diff options
author | Frederik Gladhorn <frederik.gladhorn@qt.io> | 2016-06-28 15:58:17 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2016-06-28 15:58:17 +0000 |
commit | f4c6a9c97cd217ef7222cb522181025eaef41337 (patch) | |
tree | 5bd03b1a73703f4d85fad309960f7e86ce129f58 /init-repository | |
parent | f78835e062d134d8d632a3a52160bb50348ed7c9 (diff) | |
parent | 39a03d3d6a55cc676871caad674514afa274090d (diff) |
Merge "Merge remote-tracking branch 'origin/5.7' into dev" into refs/staging/dev
Diffstat (limited to 'init-repository')
-rwxr-xr-x | init-repository | 124 |
1 files changed, 97 insertions, 27 deletions
diff --git a/init-repository b/init-repository index f0407f63..954237d0 100755 --- a/init-repository +++ b/init-repository @@ -71,9 +71,13 @@ Options: --module-subset=<module1>,<module2>... Only initialize the specified subset of modules given as the argument. Specified modules must already exist in .gitmodules. The - string "all" results in cloning all known modules. The default is - the set of maintained modules. Module names may be prefixed with a - dash to exclude them from a bigger set. + string "all" results in cloning all known modules. The strings + "essential", "addon", "preview", "deprecated", "obsolete", and + "ignore" refer to classes of modules; "default" maps to + "essential,addon,preview,deprecated", which corresponds with the + set of maintained modules and is also the default set. Module + names may be prefixed with a dash to exclude them from a bigger + set, e.g. "all,-ignore". --no-update Skip the `git submodule update' command. @@ -151,9 +155,13 @@ EOF } use Carp qw( confess ); +use Cwd qw( getcwd abs_path ); use English qw( -no_match_vars ); +use File::Spec::Functions qw ( rel2abs ); use Getopt::Long qw( GetOptions ); -use Cwd qw( getcwd ); + +my $script_path = abs_path($0); +$script_path =~ s,[/\\][^/\\]+$,,; my $GERRIT_SSH_BASE = 'ssh://@USER@codereview.qt-project.org@PORT@/'; @@ -234,6 +242,7 @@ sub parse_arguments # Replace any double trailing slashes from end of mirror $self->{'mirror-url'} =~ s{//+$}{/}; + $self->{'module-subset'} =~ s/\bdefault\b/preview,essential,addon,deprecated/; $self->{'module-subset'} = [ split(/,/, $self->{'module-subset'}) ]; return; @@ -272,6 +281,14 @@ sub git_submodule_init return; } +use constant { + STS_PREVIEW => 1, + STS_ESSENTIAL => 2, + STS_ADDON => 3, + STS_DEPRECATED => 4, + STS_OBSOLETE => 5 +}; + sub git_clone_all_submodules { my ($self, $my_repo_base, $co_branch, @subset) = @_; @@ -296,21 +313,57 @@ sub git_clone_all_submodules $subbases{$mod} = $base; } elsif ($2 eq "update") { push @subset, '-'.$1 if ($3 eq 'none'); - } elsif ($2 eq "initrepo") { - $subinits{$1} = ($3 eq "yes" or $3 eq "true"); + } elsif ($2 eq "status") { + if ($3 eq "preview") { + $subinits{$1} = STS_PREVIEW; + } elsif ($3 eq "essential") { + $subinits{$1} = STS_ESSENTIAL; + } elsif ($3 eq "addon") { + $subinits{$1} = STS_ADDON; + } elsif ($3 eq "deprecated") { + $subinits{$1} = STS_DEPRECATED; + } elsif ($3 eq "obsolete") { + $subinits{$1} = STS_OBSOLETE; + } elsif ($3 eq "ignore") { + delete $subinits{$1}; + } else { + die("Invalid subrepo status '$3' for '$1'.\n"); + } } } my %include = (); foreach my $mod (@subset) { + my $del = ($mod =~ s/^-//); + my $fail = 0; + my @what; if ($mod eq "all") { - map { $include{$_} = 1; } keys %subbases; - } elsif ($mod eq "default") { - map { $include{$_} = 1; } grep { $subinits{$_} } keys %subbases; - } elsif ($mod =~ s/^-//) { - delete $include{$mod}; + @what = keys %subbases; + } elsif ($mod eq "essential") { + @what = grep { ($subinits{$_} || 0) eq STS_ESSENTIAL } keys %subbases; + } elsif ($mod eq "addon") { + @what = grep { ($subinits{$_} || 0) eq STS_ADDON } keys %subbases; + } elsif ($mod eq "preview") { + @what = grep { ($subinits{$_} || 0) eq STS_PREVIEW } keys %subbases; + } elsif ($mod eq "deprecated") { + @what = grep { ($subinits{$_} || 0) eq STS_DEPRECATED } keys %subbases; + } elsif ($mod eq "obsolete") { + @what = grep { ($subinits{$_} || 0) eq STS_OBSOLETE } keys %subbases; + } elsif ($mod eq "ignore") { + @what = grep { ($subinits{$_} || 0) eq 0 } keys %subbases; + } elsif (defined($subdirs{$mod})) { + push @what, $mod; } else { - $include{$mod} = 1; + $fail = 1; + } + if ($del) { + print "Warning: excluding non-existent module '$mod'.\n" + if ($fail); + map { delete $include{$_} } @what; + } else { + die("Error: module subset names non-existent '$mod'.\n") + if ($fail); + map { $include{$_} = 1; } @what; } } @@ -483,11 +536,16 @@ sub ensure_link return if (!$self->{'force-hooks'} and -f $tgt); unlink($tgt); # In case we have a dead symlink or pre-existing hook print "Aliasing $src\n as $tgt ...\n" if (!$self->{quiet}); - return if eval { symlink($src, $tgt) }; + if ($^O ne "msys" && $^O ne "MSWin32") { + return if eval { symlink($src, $tgt) }; + } # Windows doesn't do (proper) symlinks. As the post_commit script needs # them to locate itself, we write a forwarding script instead. open SCRIPT, ">".$tgt or die "Cannot create forwarding script $tgt: $!\n"; - print SCRIPT "#!/bin/sh\nexec `dirname \$0`/$src \"\$\@\"\n"; + # Make the path palatable for MSYS. + $src =~ s,\\,/,g; + $src =~ s,^(.):/,/$1/,g; + print SCRIPT "#!/bin/sh\nexec $src \"\$\@\"\n"; close SCRIPT; } @@ -495,19 +553,31 @@ sub git_install_hooks { my ($self) = @_; - return if (!-d 'qtrepotools/git-hooks'); - - # Force C locale as git submodule returns the localized string "Entering" - local $ENV{LC_ALL} = 'C'; - chomp(my @modules = `git submodule foreach :`); - push @modules, ""; - for my $module (@modules) { - $module =~ s,^Entering \'([^\']+)\'$,$1/,; - my $rel = $module; - $rel =~ s,[^/]+,..,g; - $rel .= "../../qtrepotools/git-hooks/"; - $self->ensure_link($rel.'gerrit_commit_msg_hook', $module.'.git/hooks/commit-msg'); - $self->ensure_link($rel.'git_post_commit_hook', $module.'.git/hooks/post-commit'); + my $hooks = $script_path.'/qtrepotools/git-hooks'; + return if (!-d $hooks); + + my @configresult = qx(git config --list --local); + foreach my $line (@configresult) { + next if ($line !~ /submodule\.([^.=]+)\.url=/); + my $module = $1; + my $module_gitdir = $module.'/.git'; + if (!-d $module_gitdir) { + open GITD, $module_gitdir or die "Cannot open $module: $!\n"; + my $gd = <GITD>; + close GITD; + chomp($gd); + $gd =~ s/^gitdir: // or die "Malformed .git file $module_gitdir\n"; + $module_gitdir = rel2abs($gd, $module); + if (open COMD, $module_gitdir.'/commondir') { + my $cd = <COMD>; + chomp($cd); + $module_gitdir .= '/'.$cd; + $module_gitdir = abs_path($module_gitdir); + close COMD; + } + } + $self->ensure_link($hooks.'/gerrit_commit_msg_hook', $module_gitdir.'/hooks/commit-msg'); + $self->ensure_link($hooks.'/git_post_commit_hook', $module_gitdir.'/hooks/post-commit'); } } |