chiark / gitweb /
git-debrebase: git-debrebase fixes
[dgit.git] / git-debrebase
index d9bc9432cd423bc7ffcce120780aa750539cc7fb..428f9e6cfb15898cf096ba5a8caf31db0f8391a5 100755 (executable)
 use strict;
 
 use Memoize;
+use Carp;
 use Data::Dumper;
 
 use Debian::Dgit qw(:DEFAULT $wa);
@@ -136,6 +137,7 @@ sub D_PAT_OTH () { return 0x8; } # debian/patches other changes
 
 our $rd = ".git/git-debrebase";
 our $ud = "$rd/work";
+our @git = qw(git);
 
 sub commit_pr_info ($) {
     my ($r) = @_;
@@ -144,7 +146,7 @@ sub commit_pr_info ($) {
 
 sub calculate_committer_authline () {
     my $c = cmdoutput @git, qw(commit-tree --no-gpg-sign -m),
-       'DUMMY COMMIT (git-debrebase)', "$basis:";
+       'DUMMY COMMIT (git-debrebase)', "HEAD:";
     my ($h,$m) = get_commit $c;
     $h =~ m/^committer .*$/m or confess "($h) ?";
     return $&;
@@ -191,13 +193,13 @@ sub classify ($) {
 
     my ($h,$m) = get_commit $objid;
 
-    my ($t) = $h =~ m/^tree (\w+)$/m or die $cur;
+    my ($t) = $h =~ m/^tree (\w+)$/m or die $objid;
     my (@ph) = $h =~ m/^parent (\w+)$/m;
     my @p;
 
     my $r = {
        CommitId => $objid,
-       Hdr => $hdr,
+       Hdr => $h,
        Msg => $m,
         Tree => $t,
        Parents => \@p,
@@ -213,26 +215,26 @@ sub classify ($) {
 
     my $classify = sub {
        my ($type, @rest) = @_;
-       $r = { %r, Type => $type, @rest };
+       $r = { %$r, Type => $type, @rest };
        return $r;
     };
     my $unknown = sub {
        my ($why) = @_;
-       $r = { %r, Type => Unknown };
+       $r = { %$r, Type => qw(Unknown) };
        return $r;
-    }
+    };
 
     if (@p == 1) {
        my $d = $r->{Parents}[0]{Differs};
-       if ($d == D_DPAT_ADD) {
+       if ($d == D_PAT_ADD) {
            return $classify->(qw(AddPatches));
-       } elsif ($d & (D_DPAT_ADD|D_DPAT_OTH)) {
+       } elsif ($d & (D_PAT_ADD|D_PAT_OTH)) {
            return $unknown->("edits debian/patches");
        } elsif ($d == D_DEB) {
            return $classify->(qw(Packaging));
        } elsif ($d == D_UPS) {
            return $classify->(qw(Upstream));
-       } elsif ($d == D_DEB|D_UPS) {
+       } elsif ($d == (D_DEB|D_UPS)) {
            return $classify->(qw(Mixed));
        } elsif ($d == 0) {
            return $unknown->("no changes");
@@ -262,16 +264,16 @@ sub classify ($) {
                           SubType => qw(Ambiguous),
                           Overwritten => $bytime[0],
                           Contributor => $bytime[1]);
-    }!
+    }
     foreach my $p (@p) {
        my ($p_h, $p_m) = get_commit $p;
        $p->{IsOrigin} = $p_h !~ m/^parent \w+$/m;
        ($p->{IsDgitImport},) = $p_m =~ m/^\[dgit import ([0-9a-z]+) .*\]$/m;
     }
-    my @orig_ps = grep { ($_->{IsDgitImport}//'X') eq 'orig' };
+    my @orig_ps = grep { ($_->{IsDgitImport}//'X') eq 'orig' } @p;
     my $m2 = $m;
     if (!(grep { !$_->{IsOrigin} } @p) and
-       (@origs >= @p - 1) and
+       (@orig_ps >= @p - 1) and
        $m2 =~ s{^\[(dgit import unpatched .*)\]$}{[was: $1]}m) {
        $r->{NewMsg} = $m2;
        return $classify->(qw(DgitImportUnpatched),
@@ -300,7 +302,8 @@ sub classify ($) {
     return $unknown->("complex merge");
 }
 
-sub walk ($;$$$$) {
+sub walk ($;$$$$);
+sub walk {
     my ($input,
        $nogenerate,$report,
        $wantdebonly,$depth) = @_;
@@ -326,9 +329,10 @@ sub walk ($;$$$$) {
     };
 
     my $cur = $input;
+    my $basis;
 
     my $prdelim = "";
-    my $prprdelim = sub { print $report $prdelim if $report; $prdelim=""; }
+    my $prprdelim = sub { print $report $prdelim if $report; $prdelim=""; };
 
     for (;;) {
        $cl = classify $cur;
@@ -389,13 +393,13 @@ sub walk ($;$$$$) {
            if ($differs & D_UPS) {
                printf $report " D_UPS" if $report;
                push @deb_cl, {
-                    %r,
+                    %$cl,
                     SpecialMethod => 'DgitImportUpstreamUpdate',
                     $xmsg->("convert dgit import: debian changes")
                 };
            }
            push @deb_cl, {
-               %r,
+               %$cl,
                SpecialMethod => 'DgitImportDebianUpdate',
                 $xmsg->("convert dgit import: upstream changes")
            };
@@ -455,9 +459,9 @@ sub walk ($;$$$$) {
                $current_method = $cl;
                next;
            }
-           $method = $cl->{SpecialMethod} // $current_method;
+           my $method = $cl->{SpecialMethod} // $current_method;
            my @parents = ($build);
-           my $cltree = $cl->{CommitId}
+           my $cltree = $cl->{CommitId};
            if ($method eq 'Debian') {
                $read_tree_debian->($cltree);
            } elsif ($method eq 'Upstream') {
@@ -471,7 +475,7 @@ sub walk ($;$$$$) {
                next;
            } elsif ($method eq 'DgitImportDebianUpdate') {
                $read_tree_debian->($cltree);
-               $rm_tree_cached(qw(debian/patches));
+               $rm_tree_cached->(qw(debian/patches));
            } elsif ($method eq 'DgitImportUpstreamUpdate') {
                $read_tree_upstream->($cltree);
                push @parents, map { $_->{CommitId} } @{ $cl->{OrigParents} };