chiark / gitweb /
Split brain: Fix grammar in a message
[dgit.git] / dgit
diff --git a/dgit b/dgit
index d9b3a0186e3ce9dc27fb90169891476c097ece9d..ddcde9acc16148a4a6c1e97d290ef677110ab1e1 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -1448,7 +1448,7 @@ END
     my $cversion = getfield $clogp, 'Version';
     progress "synthesised git commit from .dsc $cversion";
     if ($lastpush_hash) {
-       runcmd @git, qw(reset --hard), $lastpush_hash;
+       runcmd @git, qw(reset -q --hard), $lastpush_hash;
        runcmd qw(sh -ec), 'dpkg-parsechangelog >>../changelogold.tmp';
        my $oldclogp = parsecontrol('../changelogold.tmp','previous changelog');
        my $oversion = getfield $oldclogp, 'Version';
@@ -1850,11 +1850,15 @@ sub get_source_format () {
 sub madformat ($) {
     my ($format) = @_;
     return 0 unless $format eq '3.0 (quilt)';
+    our $quilt_mode_warned;
     if ($quilt_mode eq 'nocheck') {
-       progress "Not doing any fixup of \`$format' due to --no-quilt-fixup";
+       progress "Not doing any fixup of \`$format' due to".
+           " ----no-quilt-fixup or --quilt=nocheck"
+           unless $quilt_mode_warned++;
        return 0;
     }
-    progress "Format \`$format', checking/updating patch stack";
+    progress "Format \`$format', need to check/update patch stack"
+       unless $quilt_mode_warned++;
     return 1;
 }
 
@@ -1991,6 +1995,8 @@ END
     my $format = getfield $dsc, 'Format';
     printdebug "format $format\n";
 
+    my $head = git_rev_parse('HEAD');
+
     if (madformat($format)) {
        # user might have not used dgit build, so maybe do this now:
        commit_quilty_patch();
@@ -2021,7 +2027,6 @@ END
            failedcmd @diffcmd;
        }
     }
-    my $head = git_rev_parse('HEAD');
     if (!$changesfile) {
        my $pat = changespat $cversion;
        my @cs = glob "$buildproductsdir/$pat";
@@ -2557,11 +2562,11 @@ sub quiltify_tree_sentinelfiles ($) {
         qw(-- debian/rules debian/control);
     $r =~ s/\n/,/g;
     return $r;
-                                }
+}
 
 sub quiltify_splitbrain_needed () {
     if (!$split_brain) {
-       progress "creating dgit view";
+       progress "dgit view: changes are required...";
        runcmd @git, qw(checkout -q -b dgit-view);
        $split_brain = 1;
     }
@@ -2595,7 +2600,7 @@ sub quiltify_splitbrain ($$$$$$) {
     if ($quilt_mode =~ m/gbp|unapplied/ &&
        ($diffbits->{O2A} & 01)) { # some patches
        quiltify_splitbrain_needed();
-       progress "creating patches-applied version using gbp pq";
+       progress "dgit view: creating patches-applied version using gbp pq";
        runcmd shell_cmd 'exec >/dev/null', @gbp, qw(pq import);
        # gbp pq import creates a fresh branch; push back to dgit-view
        runcmd @git, qw(update-ref refs/heads/dgit-view HEAD);
@@ -2604,7 +2609,7 @@ sub quiltify_splitbrain ($$$$$$) {
     if (($diffbits->{H2O} & 02) && # user has modified .gitignore
        !($diffbits->{O2A} & 02)) { # patches do not change .gitignore
        quiltify_splitbrain_needed();
-       progress "creating patch to represent .gitignore changes";
+       progress "dgit view: creating patch to represent .gitignore changes";
         ensuredir "debian/patches";
        my $gipatch = "debian/patches/auto-gitignore";
        open GIPATCH, ">>", "$gipatch" or die "$gipatch: $!";
@@ -2644,7 +2649,7 @@ END
     runcmd @git, qw(update-ref -m), $cachekey, "refs/$splitbraincache",
        $dgitview;
 
-    progress "created dgit view (commit id $dgitview)";
+    progress "dgit view: created (commit id $dgitview)";
 
     changedir '.git/dgit/unpack/work';
 }
@@ -2943,14 +2948,123 @@ sub quilt_fixup_singlepatch ($$$) {
 
     chdir "work";
     commit_quilty_patch();
+}
+
+sub quilt_make_fake_dsc ($) {
+    my ($upstreamversion) = @_;
+
+    my $fakeversion="$upstreamversion-~~DGITFAKE";
+
+    my $fakedsc=new IO::File 'fake.dsc', '>' or die $!;
+    print $fakedsc <<END or die $!;
+Format: 3.0 (quilt)
+Source: $package
+Version: $fakeversion
+Files:
+END
 
+    my $dscaddfile=sub {
+        my ($b) = @_;
+        
+       my $md = new Digest::MD5;
+
+       my $fh = new IO::File $b, '<' or die "$b $!";
+       stat $fh or die $!;
+       my $size = -s _;
+
+       $md->addfile($fh);
+       print $fakedsc " ".$md->hexdigest." $size $b\n" or die $!;
+    };
+
+    quilt_fixup_linkorigs($upstreamversion, $dscaddfile);
+
+    my @files=qw(debian/source/format debian/rules
+                 debian/control debian/changelog);
+    foreach my $maybe (qw(debian/patches debian/source/options
+                          debian/tests/control)) {
+        next unless stat_exists "../../../$maybe";
+        push @files, $maybe;
+    }
+
+    my $debtar= srcfn $fakeversion,'.debian.tar.gz';
+    runcmd qw(env GZIP=-1n tar -zcf), "./$debtar", qw(-C ../../..), @files;
+
+    $dscaddfile->($debtar);
+    close $fakedsc or die $!;
+}
+
+sub quilt_check_splitbrain_cache ($$) {
+    my ($headref, $upstreamversion) = @_;
+    # Called only if we are in (potentially) split brain mode.
+    # Called in $ud.
+    # Computes the cache key and looks in the cache.
+    # Returns ($dgit_view_commitid, $cachekey) or (undef, $cachekey)
+
+    my $splitbrain_cachekey;
     
+    progress
+ "dgit: split brain (separate dgit view) may be needed (--quilt=$quilt_mode).";
+    # we look in the reflog of dgit-intern/quilt-cache
+    # we look for an entry whose message is the key for the cache lookup
+    my @cachekey = (qw(dgit), $our_version);
+    push @cachekey, $upstreamversion;
+    push @cachekey, $quilt_mode;
+    push @cachekey, $headref;
+
+    push @cachekey, hashfile('fake.dsc');
+
+    my $srcshash = Digest::SHA->new(256);
+    my %sfs = ( %INC, '$0(dgit)' => $0 );
+    foreach my $sfk (sort keys %sfs) {
+       next unless m/^\$0\b/ || m{^Debian/Dgit\b};
+       $srcshash->add($sfk,"  ");
+       $srcshash->add(hashfile($sfs{$sfk}));
+       $srcshash->add("\n");
+    }
+    push @cachekey, $srcshash->hexdigest();
+    $splitbrain_cachekey = "@cachekey";
+
+    my @cmd = (@git, qw(reflog), '--pretty=format:%H %gs',
+              $splitbraincache);
+    printdebug "splitbrain cachekey $splitbrain_cachekey\n";
+    debugcmd "|(probably)",@cmd;
+    my $child = open GC, "-|";  defined $child or die $!;
+    if (!$child) {
+       chdir '../../..' or die $!;
+       if (!stat ".git/logs/refs/$splitbraincache") {
+           $! == ENOENT or die $!;
+           printdebug ">(no reflog)\n";
+           exit 0;
+       }
+       exec @cmd; die $!;
+    }
+    while (<GC>) {
+       chomp;
+       printdebug ">| ", $_, "\n" if $debuglevel > 1;
+       next unless m/^(\w+) (\S.*\S)$/ && $2 eq $splitbrain_cachekey;
+           
+       my $cachehit = $1;
+       quilt_fixup_mkwork($headref);
+       if ($cachehit ne $headref) {
+           progress "dgit view: found cached (commit id $cachehit)";
+           runcmd @git, qw(checkout -q -b dgit-view), $cachehit;
+           $split_brain = 1;
+           return ($cachehit, $splitbrain_cachekey);
+       }
+       progress "dgit view: found cached, no changes required";
+       return ($headref, $splitbrain_cachekey);
+    }
+    die $! if GC->error;
+    failedcmd unless close GC;
+
+    printdebug "splitbrain cache miss\n";
+    return (undef, $splitbrain_cachekey);
 }
 
 sub quilt_fixup_multipatch ($$$) {
     my ($clogp, $headref, $upstreamversion) = @_;
 
-    progress "starting quiltify (multiple patches, $quilt_mode mode)";
+    progress "examining quilt state (multiple patches, $quilt_mode mode)";
 
     # Our objective is:
     #  - honour any existing .pc in case it has any strangeness
@@ -3021,101 +3135,15 @@ sub quilt_fixup_multipatch ($$$) {
     # afterwards with dpkg-source --before-build.  That lets us save a
     # tree object corresponding to .origs.
 
-    my $fakeversion="$upstreamversion-~~DGITFAKE";
-
-    my $fakedsc=new IO::File 'fake.dsc', '>' or die $!;
-    print $fakedsc <<END or die $!;
-Format: 3.0 (quilt)
-Source: $package
-Version: $fakeversion
-Files:
-END
-
-    my $dscaddfile=sub {
-        my ($b) = @_;
-        
-       my $md = new Digest::MD5;
-
-       my $fh = new IO::File $b, '<' or die "$b $!";
-       stat $fh or die $!;
-       my $size = -s _;
-
-       $md->addfile($fh);
-       print $fakedsc " ".$md->hexdigest." $size $b\n" or die $!;
-    };
-
-    quilt_fixup_linkorigs($upstreamversion, $dscaddfile);
-
-    my @files=qw(debian/source/format debian/rules
-                 debian/control debian/changelog);
-    foreach my $maybe (qw(debian/patches debian/source/options
-                          debian/tests/control)) {
-        next unless stat_exists "../../../$maybe";
-        push @files, $maybe;
-    }
+    my $splitbrain_cachekey;
 
-    my $debtar= srcfn $fakeversion,'.debian.tar.gz';
-    runcmd qw(env GZIP=-1 tar -zcf), "./$debtar", qw(-C ../../..), @files;
+    quilt_make_fake_dsc($upstreamversion);
 
-    $dscaddfile->($debtar);
-    close $fakedsc or die $!;
-
-    my $splitbrain_cachekey;
     if (quiltmode_splitbrain()) {
-       # we look in the reflog of dgit-intern/quilt-cache
-       # we look for an entry whose message is the key for the cache lookup
-       my @cachekey = (qw(dgit), $our_version);
-       push @cachekey, $upstreamversion;
-       push @cachekey, $quilt_mode;
-       push @cachekey, $headref;
-
-       push @cachekey, hashfile('fake.dsc');
-
-       my $srcshash = Digest::SHA->new(256);
-       my %sfs = ( %INC, '$0(dgit)' => $0 );
-       foreach my $sfk (sort keys %sfs) {
-           $srcshash->add($sfk,"  ");
-           $srcshash->add(hashfile($sfs{$sfk}));
-           $srcshash->add("\n");
-       }
-       push @cachekey, $srcshash->hexdigest();
-       $splitbrain_cachekey = "@cachekey";
-
-       my @cmd = (@git, qw(reflog), '--pretty=format:%H %gs',
-                  $splitbraincache);
-       printdebug "splitbrain cachekey $splitbrain_cachekey\n";
-       debugcmd "|(probably)",@cmd;
-       my $child = open GC, "-|";  defined $child or die $!;
-       if (!$child) {
-           chdir '../../..' or die $!;
-           if (!stat ".git/logs/refs/$splitbraincache") {
-               $! == ENOENT or die $!;
-               printdebug ">(no reflog)\n";
-               exit 0;
-           }
-           exec @cmd; die $!;
-       }
-       while (<GC>) {
-           chomp;
-           printdebug ">| ", $_, "\n" if $debuglevel > 1;
-           next unless m/^(\w+) (\S.*\S)$/ && $2 eq $splitbrain_cachekey;
-           
-           my $cachehit = $1;
-           quilt_fixup_mkwork($headref);
-           if ($cachehit ne $headref) {
-               progress "quilt fixup ($quilt_mode mode) found cached tree";
-               runcmd @git, qw(checkout -q -b dgit-view), $cachehit;
-               $split_brain = 1;
-               return;
-           }
-           progress "quilt fixup ($quilt_mode mode)".
-             " found cached indication that no changes needed";
-           return;
-       }
-       die $! if GC->error;
-       failedcmd unless close GC;
-
-       printdebug "splitbrain cache miss\n";
+       my $cachehit;
+       ($cachehit, $splitbrain_cachekey) =
+           quilt_check_splitbrain_cache($headref, $upstreamversion);
+       return if $cachehit;
     }
 
     runcmd qw(sh -ec),
@@ -3204,6 +3232,7 @@ END
        return;
     }
 
+    progress "starting quiltify (multiple patches, $quilt_mode mode)";
     quiltify($clogp,$headref,$oldtiptree,\@failsuggestion);
 
     if (!open P, '>>', ".pc/applied-patches") {