chiark / gitweb /
git-debrebase: parsecommit: fix confusing wrong handedness in breakwater merge classify
[dgit.git] / git-debrebase
index 1961bcc5c082d418a792ecac36a5d23b9c7f9eb8..13ff81f6d58077c7e0163c3658993c4988a4fc37 100755 (executable)
@@ -327,7 +327,7 @@ sub parsecommit ($;$) {
 
     foreach my $ph (@ph) {
        push @$p_ref, {
-            Ix => $#$p_ref,
+            Ix => scalar @$p_ref,
             CommitId => $ph,
         };
     }
@@ -456,8 +456,8 @@ sub classify ($) {
        if (@p == 2 &&
            !$haspatches &&
            !$p[$prevbrw]{IsOrigin} && # breakwater never starts with an origin
-           !($p[$prevbrw]{Differs} & ~DS_DEB) &&
-           !($p[!$prevbrw]{Differs} & ~D_UPS)) {
+           !($p[!$prevbrw]{Differs} & ~DS_DEB) && # no non-debian changess
+           !($p[$prevbrw]{Differs} & ~D_UPS)) { # no non-upstream changes
            return $classify->(qw(BreakwaterUpstreamMerge),
                               OrigParents => [ $p[!$prevbrw] ]);
        }
@@ -473,7 +473,7 @@ sub walk ($;$$);
 sub walk ($;$$) {
     my ($input,
        $nogenerate,$report) = @_;
-    # => ($tip, $breakwater_tip)
+    # => ($tip, $breakwater_tip, $last_upstream_merge_in_breakwater)
     # (or nothing, if $nogenerate)
 
     # go through commits backwards
@@ -529,6 +529,8 @@ sub walk ($;$$) {
        no warnings qw(exiting); last;
     };
 
+    my $last_upstream_update;
+
     for (;;) {
        $cl = classify $cur;
        my $ty = $cl->{Type};
@@ -546,6 +548,7 @@ sub walk ($;$$) {
            $cur = $p0;
            next;
        } elsif ($ty eq 'BreakwaterStart') {
+            $last_upstream_update = $cur;
            $build_start->('FirstPackaging', $cur);
        } elsif ($ty eq 'Upstream') {
            push @upp_cl, $cl;
@@ -570,6 +573,7 @@ sub walk ($;$$) {
            $cur = $contrib;
            next;
        } elsif ($ty eq 'BreakwaterUpstreamMerge') {
+            $last_upstream_update = $cur;
            $build_start->("PreviousBreakwater", $cur);
        } elsif ($ty eq 'DgitImportUnpatched') {
            my $pm = $pseudomerges[-1];
@@ -653,6 +657,7 @@ sub walk ($;$$) {
     my $read_tree_debian = sub {
        my ($treeish) = @_;
        read_tree_subdir 'debian', "$treeish:debian";
+        rm_subdir_cached 'debian/patches';
     };
     my $read_tree_upstream = sub {
        my ($treeish) = @_;
@@ -729,6 +734,9 @@ sub walk ($;$$) {
            my $newcommit = cmdoutput @cmd;
            confess "$ch ?" unless $rewriting or $newcommit eq $cl->{CommitId};
            $build = $newcommit;
+            if (grep { $method eq $_ } qw(DgitImportUpstreamUpdate)) {
+                $last_upstream_update = $cur;
+            }
        }
     };
 
@@ -736,7 +744,7 @@ sub walk ($;$$) {
     die sprintf "internal error %#x %s %s", $final_check, $build, $input
        if $final_check & ~D_PAT_ADD;
 
-    return ($build, $breakwater);
+    return ($build, $breakwater, $last_upstream_update);
 }
 
 sub get_head () { return git_rev_parse qw(HEAD); }
@@ -756,12 +764,13 @@ sub update_head_checkout ($$$) {
 sub cmd_launder () {
     badusage "no arguments to launder allowed" if @ARGV;
     my $old = get_head();
-    my ($tip,$breakwater) = walk $old;
+    my ($tip,$breakwater,$last_upstream_merge) = walk $old;
     update_head $old, $tip, 'launder';
     # no tree changes except debian/patches
     runcmd @git, qw(rm --quiet --ignore-unmatch -rf debian/patches);
     printf "# breakwater tip\n%s\n", $breakwater;
     printf "# working tip\n%s\n", $tip;
+    printf "# last upstream merge\n%s\n", $last_upstream_merge;
 }
 
 sub cmd_analyse () {
@@ -824,10 +833,13 @@ sub cmd_new_upstream_v0 () {
     # now we need to investigate the branch this generates the
     # laundered version but we don't switch to it yet
     my $old_head = get_head();
-    my ($old_laundered_tip,$old_bw) = walk $old_head;
+    my ($old_laundered_tip,$old_bw,$old_upstream_update) = walk $old_head;
 
     my $old_bw_cl = classify $old_bw;
-    my $old_upstream = parsecommit $old_bw_cl->{OrigParents}[0]{CommitId};
+    my $old_upstream_update_cl = classify $old_upstream_update;
+    confess unless $old_upstream_update_cl->{OrigParents};
+    my $old_upstream = parsecommit
+        $old_upstream_update_cl->{OrigParents}[0]{CommitId};
 
     my $problems = 0;
     my $problem = sub {
@@ -836,7 +848,7 @@ sub cmd_new_upstream_v0 () {
        print STDERR "preflight check failed: $msg\n";
     };
 
-    $piece->('', Old => $old_upstream);
+    $piece->('', Old => $old_upstream->{CommitId});
 
     if ($old_upstream->{Msg} =~ m{^\[git-debrebase }m) {
        if ($old_upstream->{Msg} =~