chiark / gitweb /
wip import handling etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 14 May 2017 20:49:45 +0000 (21:49 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 19 Jan 2018 18:06:45 +0000 (18:06 +0000)
git-debrebase

index d6bd8a5148c356380d4ec196d57260e7fa3e5669..3048793a8d6b6b254d292dba277cec576fe13788 100755 (executable)
@@ -332,6 +332,14 @@ sub walk {
     my $rewrite_from_here = sub {
        push @processed, { SpecialMethod => 'StartRewrite' };
     };
+    my $bomb = sub { # usage: return $bomb->();
+           print $report " Unprocessable" if $report;
+           $prprdelim->();
+           if ($nogenerate) {
+               return (undef,undef);
+           }
+           die "commit $cur: Cannot cope with this commit";
+    };
 
     my $cur = $input;
     my $basis;
@@ -340,6 +348,14 @@ sub walk {
     my $prprdelim = sub { print $report $prdelim if $report; $prdelim=""; };
 
     for (;;) {
+       if (!defined $cur) {
+           if ($report) {
+               print $report $predelim, "Origin";
+               $prdelim = "\n";
+           }
+           $basis = undef;
+           last;
+       }
        $cl = classify $cur;
        my $ty = $cl->{Type};
        my $st = $cl->{SubType};
@@ -349,7 +365,7 @@ sub walk {
        }
        $found{$ty. ( defined($st) ? "-$st" : '' )}++;
        push @processed, $cl;
-       my $p0 = $cl->{Parents}[0]{CommitId};
+       my $p0 = @[ $cl->{Parents} }==1 ? $cl->{Parents}[0]{CommitId} : undef;
        if ($ty eq 'AddPatches') {
            $cur = $p0;
            $rewrite_from_here->();
@@ -381,8 +397,7 @@ sub walk {
        } elsif ($ty eq 'BreakwaterUpstreamMerge') {
            $basis = $cur;
            last;
-       } elsif ($ty eq 'DgitImportUnpatched' &&
-                @pseudomerges == 1) {
+       } elsif ($ty eq 'DgitImportUnpatched') {
            # 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
@@ -397,6 +412,10 @@ sub walk {
            printf $report " Differs=%#x", $differs if $report;
            if ($differs & D_UPS) {
                printf $report " D_UPS" if $report;
+               # This will also trigger if a non-dgit git-based NMU
+               # deleted .gitignore (which is a thing that some of
+               # the existing git tools do if the user doesn't
+               # somehow tell them not to).  Ah well.
                push @deb_cl, {
                     %$cl,
                     SpecialMethod => 'DgitImportUpstreamUpdate',
@@ -407,21 +426,37 @@ sub walk {
                %$cl,
                SpecialMethod => 'DgitImportDebianUpdate',
                 $xmsg->("convert dgit import: upstream changes")
-           };
-           $prprdelim->();
-           $basis = walk
-               $pseudomerges[0]{Overwritten},
-               $nogenerate, $report,
-               1, $depth+1;
+            };
+           my $pm = $pseudomerges[-1];
+           if (defined $pm) {
+               # To an extent, this is heurstic.  Imports don't have
+               # a useful history of the debian/ branch.  We assume
+               # that the first pseudomerge after an import has a
+               # useful history or debian/, and ignore the histories
+               # from later pseudomerge.  Often the first pseudomerge
+               # will be the dgit import of the upload to the actual
+               # suite intended by the non-dgit NMUer, and later
+               # pseudomerges may represent in-archive copies.
+               my $ovwr = $pm->{Overwritten};
+               printf $report " PM=%s \@Ovewritten:%d", $pm, (scalar @$ovwr)
+                   if $report;
+               if (@$ovwr != 1) {
+                   return $bomb->();
+               }
+               $basis = walk
+                   $ovwr->[0]{CommitId},
+                   $nogenerate, $report,
+                   1, $depth+1;
+           } else {
+               # Everything is from this import.
+               printf $report " NoPM" if $report;
+               
+               xxx set basis to undef or something to mean make origin
+           }
            $rewrite_from_here->();
            last;
-       } else {
-           print $report " Unprocessable" if $report;
-           $prprdelim->();
-           if ($nogenerate) {
-               return (undef,undef);
-           }
-           die "commit $cur: Cannot cope with this commit";
+        } else {
+           return $bomb->();
        }
     }
     $prprdelim->();