chiark / gitweb /
Split brain: Move $oldtiptree calculation out of quiltify (nfc)
[dgit.git] / dgit
diff --git a/dgit b/dgit
index 299c531214cc5a50efd193bc29de9b7d7fea820f..2c72213a56bd04ace2af90aaa6514ee164de5a9e 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -2510,14 +2510,15 @@ END
     }
 }
 
-sub quiltify_trees_differ ($$) {
-    my ($x,$y) = @_;
+sub quiltify_trees_differ ($$;$) {
+    my ($x,$y,$ignoregitignore) = @_;
     # returns 1 iff the two tree objects differ other than in debian/
     local $/=undef;
     my @cmd = (@git, qw(diff-tree --name-only -z), $x, $y);
     my $diffs= cmdoutput @cmd;
     foreach my $f (split /\0/, $diffs) {
        next if $f eq 'debian';
+       next if $f eq '.gitignore' && $ignoregitignore;
        return 1;
     }
     return 0;
@@ -2532,8 +2533,15 @@ sub quiltify_tree_sentinelfiles ($) {
     return $r;
 }
 
-sub quiltify ($$$) {
-    my ($clogp,$target,$origtree) = @_;
+sub quilt_could_gbp ($$$) {
+    my ($userhead,$unapplied,$applied) = @_;
+    return
+       !quiltify_trees_differ($userhead,$unapplied,1) &&
+       quiltify_trees_differ($userhead,$applied,1);
+}
+
+sub quiltify ($$$$) {
+    my ($clogp,$target,$unapplied,$oldtiptree) = @_;
 
     # Quilt patchification algorithm
     #
@@ -2559,12 +2567,6 @@ sub quiltify ($$$) {
     # After traversing PT, we git commit the changes which
     # should be contained within debian/patches.
 
-    changedir '../fake';
-    rmtree '.pc';
-    runcmd @git, qw(add -Af .);
-    my $oldtiptree=git_write_tree();
-    changedir '../work';
-
     # The search for the path S..T is breadth-first.  We maintain a
     # todo list containing search nodes.  A search node identifies a
     # commit, and looks something like this:
@@ -2677,6 +2679,12 @@ sub quiltify ($$$) {
            foreach my $notp (@nots) {
                print STDERR "$us:  ", $reportnot->($notp), "\n";
            }
+           if (quilt_could_gbp($target,$unapplied,$oldtiptree)) {
+               print STDERR <<END;
+$us: Tree looks like a patches-unapplied git branch.
+$us: Maybe you forgot --quilt=gbp (aka --quilt=apply) ?
+END
+           }
            fail "quilt fixup naive history linearisation failed.\n".
  "Use dpkg-source --commit by hand; or, --quilt=smash for one ugly patch";
        } elsif ($quilt_mode eq 'smash') {
@@ -2883,11 +2891,24 @@ sub quilt_fixup_multipatch ($$$) {
     #     6. Back in the main tree, fast forward to the new HEAD
 
     # Another situation we may have to cope with is gbp-style
-    # patches-unapplied trees.  We want to detect these, so we know
-    # to escape into quilt_fixup_gbp.
+    # patches-unapplied trees.
+    #
+    # We would want to detect these, so we know to escape into
+    # quilt_fixup_gbp.  However, this is in general not possible.
+    # Consider a package with a one patch which the dgit user reverts
+    # (with git-revert or the moral equivalent).
+    #
+    # That is indistinguishable in contents from a patches-unapplied
+    # tree.  And looking at the history to distinguish them is not
+    # useful because the user might have made a confusing-looking git
+    # history structure (which ought to produce an error if dgit can't
+    # cope, not a silent reintroduction of an unwanted patch).
     #
-    # A gbp-style tree is one which is not a clean patches-applied
-    # tree, but _is_ a clean patches-unapplied tree.
+    # So gbp users will have to pass an option.  But we can usually
+    # detect their failure to do so: if the tree is not a clean
+    # patches-applied tree, quilt linearisation fails, but the tree
+    # _is_ a clean patches-unapplied tree, we can suggest that maybe
+    # they want --quilt=unapplied.
     #
     # To help detect this, when we are extracting the fake dsc, we
     # first extract it with --skip-patches, and then apply the patches
@@ -2932,7 +2953,8 @@ END
     $dscaddfile->($debtar);
     close $fakedsc or die $!;
 
-    runcmd qw(sh -ec), 'exec dpkg-source --no-check -x fake.dsc >/dev/null';
+    runcmd qw(sh -ec),
+        'exec dpkg-source --no-check --skip-patches -x fake.dsc >/dev/null';
 
     my $fakexdir= $package.'-'.(stripepoch $upstreamversion);
     rename $fakexdir, "fake" or die "$fakexdir $!";
@@ -2942,9 +2964,18 @@ END
     remove_stray_gits();
     mktree_in_ud_here();
 
-    changedir '..';
+    rmtree '.pc';
+
+    runcmd @git, qw(add -Af .);
+    my $unapplied=git_write_tree();
+    printdebug "fake orig tree object $unapplied\n";
 
-    my $origtree='';
+    ensuredir '.pc';
+
+    runcmd qw(sh -ec),
+        'exec dpkg-source --before-build . >/dev/null';
+
+    changedir '..';
 
     quilt_fixup_mkwork($headref);
 
@@ -2957,7 +2988,13 @@ END
         rename '../fake/.pc','.pc' or die $!;
     }
 
-    quiltify($clogp,$headref,$origtree);
+    changedir '../fake';
+    rmtree '.pc';
+    runcmd @git, qw(add -Af .);
+    my $oldtiptree=git_write_tree();
+    changedir '../work';
+
+    quiltify($clogp,$headref,$unapplied,$oldtiptree);
 
     if (!open P, '>>', ".pc/applied-patches") {
        $!==&ENOENT or die $!;