diff options
Diffstat (limited to 'init-repository')
-rwxr-xr-x | init-repository | 98 |
1 files changed, 75 insertions, 23 deletions
diff --git a/init-repository b/init-repository index f0407f63..b941646b 100755 --- a/init-repository +++ b/init-repository @@ -71,9 +71,12 @@ 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", "obsolete", and "ignore" refer to + classes of modules; "default" maps to "essential,addon,preview", + 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. @@ -153,7 +156,10 @@ EOF use Carp qw( confess ); use English qw( -no_match_vars ); use Getopt::Long qw( GetOptions ); -use Cwd qw( getcwd ); +use Cwd qw( getcwd abs_path ); + +my $script_path = abs_path($0); +$script_path =~ s,[/\\][^/\\]+$,,; my $GERRIT_SSH_BASE = 'ssh://@USER@codereview.qt-project.org@PORT@/'; @@ -234,6 +240,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/; $self->{'module-subset'} = [ split(/,/, $self->{'module-subset'}) ]; return; @@ -272,6 +279,13 @@ sub git_submodule_init return; } +use constant { + STS_PREVIEW => 1, + STS_ESSENTIAL => 2, + STS_ADDON => 3, + STS_OBSOLETE => 4 +}; + sub git_clone_all_submodules { my ($self, $my_repo_base, $co_branch, @subset) = @_; @@ -296,8 +310,20 @@ 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 "obsolete") { + $subinits{$1} = STS_OBSOLETE; + } elsif ($3 eq "ignore") { + delete $subinits{$1}; + } else { + die("Invalid subrepo status '$3' for '$1'.\n"); + } } } @@ -305,11 +331,21 @@ sub git_clone_all_submodules foreach my $mod (@subset) { if ($mod eq "all") { map { $include{$_} = 1; } keys %subbases; - } elsif ($mod eq "default") { - map { $include{$_} = 1; } grep { $subinits{$_} } keys %subbases; + } elsif ($mod eq "essential") { + map { $include{$_} = 1; } grep { ($subinits{$_} || 0) eq STS_ESSENTIAL } keys %subbases; + } elsif ($mod eq "addon") { + map { $include{$_} = 1; } grep { ($subinits{$_} || 0) eq STS_ADDON } keys %subbases; + } elsif ($mod eq "preview") { + map { $include{$_} = 1; } grep { ($subinits{$_} || 0) eq STS_PREVIEW } keys %subbases; + } elsif ($mod eq "obsolete") { + map { $include{$_} = 1; } grep { ($subinits{$_} || 0) eq STS_OBSOLETE } keys %subbases; } elsif ($mod =~ s/^-//) { + print "Warning: excluding non-existent module '$mod'.\n" + if (!defined($subdirs{$mod})); delete $include{$mod}; } else { + die("Error: module subset names non-existent '$mod'.\n") + if (!defined($subdirs{$mod})); $include{$mod} = 1; } } @@ -483,11 +519,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 +536,30 @@ 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.'/.git'; + if (!-d $module) { + open GITD, $module or die "Cannot open $module: $!\n"; + my $gd = <GITD>; + close GITD; + chomp($gd); + $gd =~ s/^gitdir: // or die "Malformed .git file $module\n"; + $module = $gd; # We expect it to be always absolute. + if (open COMD, $module.'/commondir') { + my $cd = <COMD>; + chomp($cd); + $module .= '/'.$cd; + $module = abs_path($module); + close COMD; + } + } + $self->ensure_link($hooks.'/gerrit_commit_msg_hook', $module.'/hooks/commit-msg'); + $self->ensure_link($hooks.'/git_post_commit_hook', $module.'/hooks/post-commit'); } } |