chiark / gitweb /
git-debrebase: found
[dgit.git] / git-debrebase
index ba990e7471637f2e79febf8fe74bd877aa706b27..8c1dba80b881d257ca161305aa63c33e990272da 100755 (executable)
@@ -115,10 +115,10 @@ sub get_commit ($) {
     return ($`,$');
 }
 
-sub D_DEB ()     { return 0x1; }
-sub D_UPS ()     { return 0x2; }
-sub D_PAT_ADD () { return 0x4; }
-sub D_PAT_OTH () { return 0x8; }
+sub D_DEB ()     { return 0x1; } # debian/ (not including debian/patches/)
+sub D_UPS ()     { return 0x2; } # upstream files
+sub D_PAT_ADD () { return 0x4; } # debian/patches/ extra patches at end
+sub D_PAT_OTH () { return 0x8; } # debian/patches other changes
 
 our $rd = ".git/git-debrebase";
 our $ud = "$rd/work";
@@ -130,12 +130,48 @@ sub commit_pr_info ($) {
 
 sub calculate_committer_authline () {
     my $c = cmdoutput @git, qw(commit-tree --no-gpg-sign -m),
-       'XXX DUMMY COMMIT (git-debrebase)', "$basis:";
+       'DUMMY COMMIT (git-debrebase)', "$basis:";
     my ($h,$m) = get_commit $c;
     $h =~ m/^committer .*$/m or confess "($h) ?";
     return $&;
 }
 
+# classify returns an info hash like this
+#   CommitId => $objid
+#   Hdr => # commit headers, including 1 final newline
+#   Msg => # commit message (so one newline is dropped)
+#   Tree => $treeobjid
+#   Type => (see below)
+#   Parents = [ {
+#       Ix => $index # ie 0, 1, 2, ...
+#       CommitId
+#       Differs => return value from get_differs
+#       IsOrigin
+#       IsDggitImport => 'orig' 'tarball' 'unpatched' 'package' (as from dgit)
+#     } ...]
+#   NewMsg => # commit message, but with any [dgit import ...] edited
+#             # to say "[was: ...]"
+#
+# Types:
+#   Packaging
+#   Upstream
+#   AddPatches
+#   Mixed
+#   Unknown
+#
+#   Pseudomerge
+#     has additional entres in classification result
+#       Overwritten = [ subset of Parents ]
+#       Contributor = $the_remaining_Parent
+#
+#   DgitImportUnpatched
+#     has additional entry in classification result
+#       OrigParents = [ subset of Parents ]
+#
+#   BreakwaterUpstreamMerge
+#     has additional entry in classification result
+#       OrigParents = [ subset of Parents ]
+
 sub classify ($) {
     my ($objid) = @_;
 
@@ -243,20 +279,30 @@ sub classify ($) {
        !($p[0]{Differs} & ~D_DEB) &&
        !($p[1]{Differs} & ~D_UPS)) {
        return $classify->(qw(BreakwaterUpstreamMerge),
-                          Upstream => $p[1]);
+                          OrigParents => [ $p[1] ]);
     }
+    # xxx multi-.orig upstreams
 
     return $unknown->("complex merge");
 }
 
-sub launder ($$$) {
-    my ($input, $pseudos_must_overwrite_this, $wantdebonly) = @_;
+sub walk ($$$;$$$) {
+    my ($input, $pseudos_must_overwrite_this, $wantdebonly,
+       $report, $depth, $report_anomaly, $nogenerate) = @_;
     # go through commits backwards
     # we generate two lists of commits to apply
+    # => ($tip, $breakwater_tip)
     my (@deb_cl, @ups_cl, @processed);
     my %found;
     my @pseudomerges;
 
+    $report //= sub { };
+    $report_anomaly //= sub {
+       my ($cl, $msg) = @_;
+       die "commit $cl: $msg\n";
+    };
+    $depth //= 0;
+
     my $cl;
     my $xmsg = sub {
        my ($appendinfo) = @_;
@@ -275,13 +321,17 @@ sub launder ($$$) {
        $cl = classify $cur;
        my $ty = $cl->{Type};
        my $st = $cl->{SubType};
+       $report->($cl);
        $found{$ty. ( defined($st) ? "-$st" : '' )}++;
        my $p0 = $cl->{Parents}[0]{CommitId};
+       $cl->{Abbrev} = lc substr $ty,0,1;
        if ($ty eq 'AddPatches') {
+           $cl->{Abbrev} = 'P';
            $cur = $p0;
            $rewrite_from_here->();
            next;
        } elsif ($ty eq 'Packaging') {
+           $cl->{Abbrev} = 'd';
            push @deb_cl, $cl;
            push @processed, $cl;
            $cur = $p0;
@@ -302,8 +352,16 @@ sub launder ($$$) {
            $rewrite_from_here->();
            next;
        } elsif ($ty eq 'Pseudomerge') {
-           if (defined $pseudos_must_overwrite_this) {
-               confess 'xxx actually check this';
+           $cl->{Abbrev} = 'M';
+           if (defined $pseudos_must_overwrite_this &&
+               !grep {
+                   is_fast_fwd $pseudos_must_overwrite_this, $_->{CommitId}
+               },
+               @{ $cl->{Overwritten} }) {
+               $report_anomaly->($cl,
+                                 "Pseudomerge should overwrite".
+                                 " $pseudos_must_overwrite_this".
+                                 " but does not do so");
            }
            push @pseudomerges, $cl;
            $rewrite_from_here->();
@@ -314,6 +372,7 @@ sub launder ($$$) {
            last;
        } elsif ($ty eq 'DgitImportUnpatched' &&
                 @pseudomerges == 1) {
+           $cl->{Abbrev} = 'I';
            # This import has a tree which is just like a breakwater
            # tree, but it has the wrong history.  Its ought to have
            # the previous breakwater (which dgit ought to have
@@ -324,6 +383,7 @@ sub launder ($$$) {
            # precisely right.  Otherwise, it was a non-gitish upload
            # of a new upstream version.  We can tell these apart
            # by looking at the tree of the supposed upstream.
+           my $differs = get_differs $previous_breakwater, $cl->{Tree};
            if ($differs & D_UPS) {
                push @deb_cl, {
                     %r,
@@ -336,18 +396,21 @@ sub launder ($$$) {
                SpecialMethod => 'DgitImportDebianUpdate',
                 $xmsg->("convert dgit import: upstream changes")
            };
-           my $differs = get_differs $previous_breakwater, $cl->{Tree};
-           $basis = launder $pseudomerges[0]{Overwritten}, undef, 1;
+           $basis = launder $pseudomerges[0]{Overwritten}, undef, 1,
+               $report, $depth+1, $nogenerate;
            $rewrite_from_here->();
            last;
        } else {
-           die "Reached difficult commit $cur: ".Dumper($cl);
+           $report_anomaly->($cl, "Cannot cope with this commit");
        }
     }
     # Now we build it back up again
 
+    if ($nogenerate) {
+       return (undef, $basis);
+    }
+
     workarea_fresh();
-    in_workarea sub { xxx attributes xxx };
 
     my $rewriting = 1;
 
@@ -442,10 +505,15 @@ sub update_head ($$) {
     runcmd @git, qw(update-ref -m), "git-debrebase $mrest", $new, $old;
 }
 
+sub cmd_analyse () {
+    
+
 sub cmd_launder () {
     my $old = get_head();
     my ($tip,$breakwater) = launder $old, 0, undef, 0;
-    update_head $old, $tip, 'launder'; # no tree changes! xxx debian/patches
+    update_head $old, $tip, 'launder';
+    # no tree changes except debian/patches
+    runcmd @git, qw(rm --quiet -rf debian/patches);
     printf "# breakwater tip:\n%s\n", $breakwater;
 }