chiark / gitweb /
Test suite: move t-commit and break out t-policy (nfc)
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 4f0329a49932b21caf94395785b6eb4bf167e551..c315c7f1606846ae74dde955052254b3ba5b8f76 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -111,6 +111,8 @@ sub lref () { return "refs/heads/".lbranch(); }
 sub lrref () { return "refs/remotes/$remotename/".server_branch($csuite); }
 sub rrref () { return server_ref($csuite); }
 
+sub lrfetchrefs () { return "refs/dgit-fetch/$isuite"; }
+
 sub stripepoch ($) {
     my ($vsn) = @_;
     $vsn =~ s/^\d+\://;
@@ -162,6 +164,11 @@ sub deliberately ($) {
     return !!grep { $_ eq "--deliberately-$enquiry" } @deliberatelies;
 }
 
+sub deliberately_not_fast_forward () {
+    deliberately('not-fast-forward') ||
+       deliberately('TEST-not-fast-forward-dgit-only');
+}
+
 #---------- remote protocol support, common ----------
 
 # remote push initiator/responder protocol:
@@ -667,23 +674,6 @@ sub parsechangelog {
     return $c;
 }
 
-sub git_get_ref ($) {
-    my ($refname) = @_;
-    my $got = cmdoutput_errok @git, qw(show-ref --), $refname;
-    if (!defined $got) {
-       $?==256 or fail "git show-ref failed (status $?)";
-       printdebug "ref $refname= [show-ref exited 1]\n";
-       return '';
-    }
-    if ($got =~ m/^(\w+) \Q$refname\E$/m) {
-       printdebug "ref $refname=$1\n";
-       return $1;
-    } else {
-       printdebug "ref $refname= [no match]\n";
-       return '';
-    }
-}
-
 sub must_getcwd () {
     my $d = getcwd();
     defined $d or fail "getcwd failed: $!";
@@ -1271,24 +1261,13 @@ sub ensure_we_have_orig () {
     }
 }
 
-sub rev_parse ($) {
-    return cmdoutput @git, qw(rev-parse), "$_[0]~0";
-}
-
-sub is_fast_fwd ($$) {
-    my ($ancestor,$child) = @_;
-    my @cmd = (@git, qw(merge-base), $ancestor, $child);
-    my $mb = cmdoutput_errok @cmd;
-    if (defined $mb) {
-       return rev_parse($mb) eq rev_parse($ancestor);
-    } else {
-       $?==256 or failedcmd @cmd;
-       return 0;
-    }
-}
-
 sub git_fetch_us () {
     runcmd_ordryrun_local @git, qw(fetch),access_giturl(),fetchspec();
+    if (deliberately_not_fast_forward) {
+       runcmd_ordryrun_local @git, qw(fetch -p), access_giturl(),
+           map { "+refs/$_/*:".lrfetchrefs."/$_/*" }
+           qw(tags heads);
+    }
 }
 
 sub fetch_from_archive () {
@@ -1658,7 +1637,7 @@ sub dopush ($) {
 #    runcmd @git, qw(fetch -p ), "$alioth_git/$package.git",
 #        map { lref($_).":".rref($_) }
 #        (uploadbranch());
-    my $head = rev_parse('HEAD');
+    my $head = git_rev_parse('HEAD');
     if (!$changesfile) {
        my $multi = "$buildproductsdir/".
            "${package}_".(stripepoch $cversion)."_multi.changes";
@@ -1681,11 +1660,12 @@ sub dopush ($) {
     responder_send_command("param head $head");
     responder_send_command("param csuite $csuite");
 
-    if ($forceflag && defined $lastpush_hash) {
-       git_for_each_tag_referring($lastpush_hash, sub {
-           my ($objid,$fullrefname,$tagname) = @_;
-           responder_send_command("supersedes $fullrefname=$objid");
-           $supersedes{$fullrefname} = $objid;
+    if ($forceflag) {
+       git_for_each_ref(lrfetchrefs, sub {
+           my ($objid,$objtype,$lrfetchrefname,$reftail) = @_;
+           my $rrefname= substr($lrfetchrefname, length(lrfetchrefs) + 1);
+           responder_send_command("supersedes $rrefname=$objid");
+           $supersedes{$rrefname} = $objid;
        });
     }
 
@@ -1849,8 +1829,7 @@ sub cmd_push {
     if (fetch_from_archive()) {
        if (is_fast_fwd(lrref(), 'HEAD')) {
            # ok
-       } elsif (deliberately('not-fast-forward') ||
-                deliberately('TEST-not-fast-forward-dgit-only')) {
+       } elsif (deliberately_not_fast_forward) {
            $forceflag = '+';
        } else {
            fail "dgit push: HEAD is not a descendant".
@@ -2403,7 +2382,7 @@ sub build_maybe_quilt_fixup () {
     #     6. Back in the main tree, fast forward to the new HEAD
 
     my $clogp = parsechangelog();
-    my $headref = rev_parse('HEAD');
+    my $headref = git_rev_parse('HEAD');
 
     prep_ud();
     changedir $ud;