X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=blobdiff_plain;f=dgit;h=23cae18f2acdbc58528293c191cf5baf210239d7;hp=d3b2ec7ee5cfde2e9c36d05efa6fba4d340a8ef8;hb=51f61cf75f6614603782edde86261c9d1bd8c769;hpb=140e8c84b7e36eacbf9802c8a04f40eb32ef59ce diff --git a/dgit b/dgit index d3b2ec7e..23cae18f 100755 --- a/dgit +++ b/dgit @@ -1549,6 +1549,9 @@ $later_warning_msg END @output = $lastpush_mergeinput; } else { + # Same version. Use what's in the server git branch, + # discarding our own import. (This could happen if the + # server automatically imports all packages into git.) @output = $lastpush_mergeinput; } } @@ -1604,9 +1607,135 @@ sub ensure_we_have_orig () { sub git_fetch_us () { my @specs = - map { "+refs/$_/*:".lrfetchrefs."/$_/*" } + map { "$_/*" } qw(tags heads), $branchprefix; - runcmd_ordryrun_local @git, qw(fetch -p -n -q), access_giturl(), @specs; + + # This is rather miserable: + # When git-fetch --prune is passed a fetchspec ending with a *, + # it does a plausible thing. If there is no * then: + # - it matches subpaths too, even if the supplied refspec + # starts refs, and behaves completely madly if the source + # has refs/refs/something. (See, for example, Debian #NNNN.) + # - if there is no matching remote ref, it bombs out the whole + # fetch. + # We want to fetch a fixed ref, and we don't know in advance + # if it exists, so this is not suitable. + # + # Our workaround is to use git-ls-remote. git-ls-remote has its + # own qairks. Notably, it has the absurd multi-tail-matching + # behaviour: git-ls-remote R refs/foo can report refs/foo AND + # refs/refs/foo etc. + # + # Also, we want an idempotent snapshot, but we have to make two + # calls to the remote: one to git-ls-remote and to git-fetch. The + # solution is use git-ls-remote to obtain a target state, and + # git-fetch to try to generate it. If we don't manage to generate + # the target state, we try again. + + my $specre = join '|', map { + my $x = $_; + $x =~ s/\W/\\$&/g; + $x =~ s/\\\*$/.*/; + "(?:refs/$x)"; + } @specs; + printdebug "git_fetch_us specre=$specre\n"; + my $wanted_rref = sub { + local ($_) = @_; + return m/^(?:$specre)$/o; + }; + + my %lrfetchrefs_f; + + my $fetch_iteration = 0; + FETCH_ITERATION: + for (;;) { + if (++$fetch_iteration > 10) { + fail "too many iterations trying to get sane fetch!"; + } + + my @look = map { "refs/$_" } @specs; + my @lcmd = (@git, qw(ls-remote -q --refs), access_giturl(), @look); + debugcmd "|",@lcmd; + + my %wantr; + open GITLS, "-|", @lcmd or die $!; + while () { + printdebug "=> ", $_; + m/^(\w+)\s+(\S+)\n/ or die "ls-remote $_ ?"; + my ($objid,$rrefname) = ($1,$2); + if (!$wanted_rref->($rrefname)) { + print STDERR <($rrefname)) { + printdebug <'; + my $want = $wantr{$rrefname}; + next if $got eq $want; + if (!defined $objgot{$want}) { + print STDERR <