chiark / gitweb /
git fetching: git_lrfetch_sane: Support multiple calls
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Jan 2017 03:01:39 +0000 (03:01 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Jan 2017 22:14:48 +0000 (22:14 +0000)
We want to be able to fetch from some other distro, or a bit more from
the same one.

No functional change since no callers pass trueish $supplementary.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
dgit

diff --git a/dgit b/dgit
index 4f6d111b18c25fbe67356fad08c85d900c5bc483..c66c7a63a19162c86ccf71cc59513707d23e045e 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -2515,7 +2515,14 @@ sub lrfetchref_used ($) {
 }
 
 sub git_lrfetch_sane {
 }
 
 sub git_lrfetch_sane {
-    my (@specs) = @_;
+    my ($supplementary, @specs) = @_;
+    # Make a 'refs/'.lrfetchrefs.'/*' be just like on server,
+    # at least as regards @specs.  Also leave the results in
+    # %lrfetchrefs_f, and arrange for lrfetchref_used to be
+    # able to clean these up.
+    #
+    # With $supplementary==1, @specs must not contain wildcards
+    # and we add to our previous fetches (non-atomically).
 
     # This is rather miserable:
     # When git fetch --prune is passed a fetchspec ending with a *,
 
     # This is rather miserable:
     # When git fetch --prune is passed a fetchspec ending with a *,
@@ -2541,18 +2548,19 @@ sub git_lrfetch_sane {
 
     my $url = access_giturl();
 
 
     my $url = access_giturl();
 
-    printdebug "git_lrfetch_sane specs @specs\n";
+    printdebug "git_lrfetch_sane suppl=$supplementary specs @specs\n";
 
     my $specre = join '|', map {
        my $x = $_;
        $x =~ s/\W/\\$&/g;
 
     my $specre = join '|', map {
        my $x = $_;
        $x =~ s/\W/\\$&/g;
-       $x =~ s/\\\*$/.*/;
+       my $wildcard = $x =~ s/\\\*$/.*/;
+       die if $wildcard && $supplementary;
        "(?:refs/$x)";
     } @specs;
     printdebug "git_lrfetch_sane specre=$specre\n";
     my $wanted_rref = sub {
        local ($_) = @_;
        "(?:refs/$x)";
     } @specs;
     printdebug "git_lrfetch_sane specre=$specre\n";
     my $wanted_rref = sub {
        local ($_) = @_;
-       return m/^(?:$specre)$/o;
+       return m/^(?:$specre)$/;
     };
 
     my $fetch_iteration = 0;
     };
 
     my $fetch_iteration = 0;
@@ -2595,7 +2603,9 @@ END
        my @fcmd = (@git, qw(fetch -p -n -q), $url, @fspecs);
        runcmd_ordryrun_local @fcmd if @fspecs;
 
        my @fcmd = (@git, qw(fetch -p -n -q), $url, @fspecs);
        runcmd_ordryrun_local @fcmd if @fspecs;
 
-       %lrfetchrefs_f = ();
+       if (!$supplementary) {
+           %lrfetchrefs_f = ();
+       }
        my %objgot;
 
        git_for_each_ref(lrfetchrefs, sub {
        my %objgot;
 
        git_for_each_ref(lrfetchrefs, sub {
@@ -2604,6 +2614,10 @@ END
            $objgot{$objid} = 1;
        });
 
            $objgot{$objid} = 1;
        });
 
+       if ($supplementary) {
+           last;
+       }
+
        foreach my $lrefname (sort keys %lrfetchrefs_f) {
            my $rrefname = 'refs'.substr($lrefname, length lrfetchrefs);
            if (!exists $wantr{$rrefname}) {
        foreach my $lrefname (sort keys %lrfetchrefs_f) {
            my $rrefname = 'refs'.substr($lrefname, length lrfetchrefs);
            if (!exists $wantr{$rrefname}) {
@@ -2663,7 +2677,7 @@ sub git_fetch_us () {
     push @specs, $rewritemap;
     push @specs, qw(heads/*) if deliberately_not_fast_forward;
 
     push @specs, $rewritemap;
     push @specs, qw(heads/*) if deliberately_not_fast_forward;
 
-    git_lrfetch_sane @specs;
+    git_lrfetch_sane 0, @specs;
 
     my %here;
     my @tagpats = debiantags('*',access_nomdistro);
 
     my %here;
     my @tagpats = debiantags('*',access_nomdistro);