chiark / gitweb /
WIP
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 29 Jan 2017 21:59:35 +0000 (21:59 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 24 Aug 2017 14:43:39 +0000 (15:43 +0100)
git-debrebase

index bb2d91a243e49cb5729e778954d5e19dbd2ceda4..310e1ad4d87bd896166295e7fb9ce2394590a119 100755 (executable)
@@ -19,7 +19,9 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 use strict;
+
 use Memoize;
+use Data::Dumper;
 
 use Debian::Dgit;
 
@@ -51,6 +53,11 @@ sub D_UPS ()     { return 0x2; }
 sub D_PAT_ADD () { return 0x4; }
 sub D_PAT_OTH () { return 0x8; }
 
+sub commit_pr_info ($) {
+    my ($r) = @_;
+    return Data::Dumper->dump([$r], [qw(commit)]);
+}
+
 sub classify ($) {
     my ($objid) = @_;
 
@@ -64,6 +71,7 @@ sub classify ($) {
        CommitId => $objid,
        Hdr => $hdr,
        Msg => $m,
+        Tree => $t,
        Parents => \@p,
     };
 
@@ -75,6 +83,17 @@ sub classify ($) {
         };
     }
 
+    my $classify = sub {
+       my ($type, @rest) = @_;
+       $r = { %r, Type => $type, @rest };
+       return $r;
+    };
+    my $unknown = sub {
+       my ($why) = @_;
+       $r = { %r, Type => Unknown };
+       return $r;
+    }
+
     if (@p == 1) {
        my $d = $r->{Parents}[0]{Differs};
        if ($d == D_DPAT_ADD) {
@@ -112,17 +131,23 @@ sub classify ($) {
            $1;
        } @p;
        return $classify->(qw(Pseudomerge),
-                          Xtype => qw(Ambiguous),
+                          SubType => qw(Ambiguous),
                           Overwritten => $bytime[0],
-                          Contributyor => $bytime[1]);
-    }
+                          Contributor => $bytime[1]);
+    }!
     foreach my $p (@p) {
-       my ($type) = git_cat_file "$p^1";
-       $p->{IsOrigin} = $type eq 'missing';
+       my ($p_h, $p_m) = get_commit $p;
+       $p->{IsOrigin} = $p_h !~ m/^parent \w+$/m;
+       $p->{IsDgitImport} = $p_m =~ m/^\[dgit import .*\]$/m;
+       $p->{IsDgitImportOrig} = $p_m =~ m/^\[dgit import orig .*\]$/m;
     }
-    if (!grep { !$_->{IsOrigin} } @p
-       && $m =~ m{^\[dgit import unpatched .*\]$}m) {
-       return $classify->(qw(DgitImport));
+    my $m2 = $m;
+    if (!grep { !($_->{IsOrigin} && $_->{isDgitImport}) } @p and
+       $m2 =~ s{^\[(dgit import unpatched .*)\]$}{[was: $1]}m) {
+
+ xxx check exactly one IsDgitImport that is tarball
+       $r->{NewMsg} = $m2;
+       return $classify->(qw(DgitImportUnpatched));
     }
 
     my ($stype, $series) = git_cat_file "$t:debian/patches/series";
@@ -144,6 +169,82 @@ sub classify ($) {
     return $unknown->("complex merge");
 }
 
+sub launder ($) {
+    my ($cur) = @_;
+    # go through commits backwards
+    # we generate two lists of commits to apply
+    my (@phases, @deb_cl, @ups_cl);
+    my %found;
+    my @psuedomerges;
+    for (;;) {
+       my $cl = classify $cur;
+       my $ty = $cl->{Type};
+       my $st = $cl->{SubType};
+       $found{$ty. ( defined($st) ? "-$st" : '' )}++;
+       my $p0 = $cl->{Parents}[0]{CommitId};
+       if ($ty eq 'AddPatches') {
+           $cur = $p0;
+           next;
+       } elsif ($ty eq 'Packaging') {
+           push @deb_cl, $cur;
+           $cur = $p0;
+           next;
+       } elsif ($ty eq 'Upstream') {
+           push @ups_cl, $cur;
+           $cur = $p0;
+           next;
+       } elsif ($ty eq 'Mixed') {
+           my $queue = sub {
+               my ($q, $wh) = @_;
+               my $ms = $cl->{Msg};
+               chomp $ms;
+               $ms .= "\n[git-debrebase split mixed commit: $wh part]\n";
+               my $cls = { $cl, Msg => $ms };
+               push @$q, $cls;
+           };
+           $queue->(\@deb_cl, "debian");
+           $queue->(\@ups_cl, "upstream");
+           next;
+       } elsif ($ty eq 'Pseudomerge') {
+           push @pseudomerges, $cl;
+           $cur = $ty->{Contributor};
+           next;
+       } elsif ($ty eq 'DgitImportUnpatched' &&
+                @pseudomerges == 1) {
+           # 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
+           # generated a pseudomerge to overwrite) as an ancestor.
+           # That will make the history of the debian/ files correct.
+           # As for the upstream version: either it's the same upstream
+           # as the previous breakwater, in which case that history is
+           # 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 $previous_breakwater = launder $pseudomerges[0]{Overwritten};
+           my $differs = get_differs $previous_breakwater, $cl->{Tree};
+           if ($differs & D_UPS) {
+               $r->{FixupUpstreamMerge} = $
+
+               push @deb_cl, {
+                    $cl,
+                    Type => NonGitNewUpstreamDgitImport,
+                    PreviousBreakwaterMerge => 
+               
+
+           push @phases, [ @deb_cl, @ups_cl ];
+           
+           if (@pseudomerges != 1) {
+}   
+
+if ($ARGV[0] eq 'launder') {
+    launder();
+}
+
+use Data::Dumper;
+print Dumper(cfg('wombat.foo.bar'));
+
+
        ((git_cat_file "$t:debian/patches/series"
        
     
@@ -167,22 +268,6 @@ sub classify ($) {
     
                    
 
-sub launder () {
-    # go through commits backwards
-    # we generate two lists of commits to apply
-    my (@deb_cl, @ups_cl);
-    my $cur = git_rev_parse('HEAD');
-    for (;;) {
-}   
-
-if ($ARGV[0] eq 'launder') {
-    launder();
-}
-
-use Data::Dumper;
-print Dumper(cfg('wombat.foo.bar'));
-
-