chiark / gitweb /
Split brain: Introduce $diffbits (nfc)
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 99cb7fe29196830abc0f483bb703f169adf806d6..08d07bec9190b600fac461f8ccb3bde037a593f2 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -61,7 +61,7 @@ our $cleanmode;
 our $changes_since_version;
 our $rmchanges;
 our $quilt_mode;
-our $quilt_modes_re = 'linear|smash|auto|nofix|nocheck|gbp|apply';
+our $quilt_modes_re = 'linear|smash|auto|nofix|nocheck|gbp|unapplied';
 our $we_are_responder;
 our $initiator_tempdir;
 
@@ -2513,8 +2513,9 @@ END
 sub quiltify_trees_differ ($$;$) {
     my ($x,$y,$finegrained) = @_;
     # returns true iff the two tree objects differ other than in debian/
-    # returns bitmas 01 - differ in upstream files except .gitignore
-    #                02 - differ in .gitignore
+    # with $finegrained,
+    # returns bitmask 01 - differ in upstream files except .gitignore
+    #                 02 - differ in .gitignore
     local $/=undef;
     my @cmd = (@git, qw(diff-tree --name-only -z));
     push @cmd, qw(-r) if $finegrained;
@@ -2538,9 +2539,10 @@ sub quiltify_tree_sentinelfiles ($) {
     return $r;
 }
 
-sub quiltify_splitbrain () {
+sub quiltify_splitbrain ($) {
+    my ($diffbits) = @_;
     # memoisation via git-reflog
-    my $may_apply = $quilt_mode =~ m/gbp|apply/;
+    my $may_apply = $quilt_mode =~ m/gbp|unapplied/;
     die "xxx not yet implemented";
 #    if ($may_apply &&
 #      quiltify_trees_differ($userhead,)) {}
@@ -3000,14 +3002,19 @@ END
     # We calculate some guesswork now about what kind of tree this might
     # be.  This is mostly for error reporting.
 
-    my $user2unapplied    = quiltify_trees_differ($headref,   $unapplied, 1);
-    my $user2applied      = quiltify_trees_differ($headref,   $oldtiptree,1);
-    my $applied2unapplied = quiltify_trees_differ($oldtiptree,$unapplied, 1);
+    my $diffbits = {
+        # H = user's HEAD
+        # O = orig, without patches applied
+        # A = "applied", ie orig with H's debian/patches applied
+        H2O => quiltify_trees_differ($headref,  $unapplied, 1),
+        H2A => quiltify_trees_differ($headref,  $oldtiptree,1),
+        O2A => quiltify_trees_differ($unapplied,$oldtiptree,1),
+    };
 
     my @dl;
     foreach my $b (qw(01 02)) {
-        foreach my $v ($user2unapplied, $applied2unapplied, $user2applied) {
-            push @dl, ($v & $b) ? '##' : '==';
+        foreach my $v (qw(H2O O2A H2A)) {
+            push @dl, ($diffbits->{$v} & $b) ? '##' : '==';
         }
     }
     printdebug "differences \@dl @dl.\n";
@@ -3019,16 +3026,16 @@ END
                                  $dl[2],                     $dl[5];
 
     my @failsuggestion;
-    if (!($user2unapplied & $applied2unapplied)) {
+    if (!($diffbits->{H2O} & $diffbits->{O2A})) {
         push @failsuggestion, "This might be a patches-unapplied branch.";
-    }  elsif (!($user2applied & $applied2unapplied)) {
+    }  elsif (!($diffbits->{H2A} & $diffbits->{O2A})) {
         push @failsuggestion, "This might be a patches-applied branch.";
     }
-    push @failsuggestion,
"Maybe you need to specify one of  --quilt=apply --quilt=gbp --quilt=dpm  ?";
+    push @failsuggestion, "Maybe you need to specify one of".
       " --quilt=gbp --quilt=dpm --quilt=unapplied ?";
 
     if ($quilt_mode =~ m/gbp|dpm|apply/) {
-       quiltify_splitbrain();
+       quiltify_splitbrain($diffbits);
        return;
     }