From c0e4a8e072c2b133c5aa27a9636ce97521ad3ebf Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 23 Jan 2018 15:19:33 +0000 Subject: git-debrebase: break out parsecommit Signed-off-by: Ian Jackson --- git-debrebase | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'git-debrebase') diff --git a/git-debrebase b/git-debrebase index 5808cf3..62fbc4d 100755 --- a/git-debrebase +++ b/git-debrebase @@ -285,31 +285,49 @@ sub calculate_committer_authline () { # has additional entry in classification result # OrigParents = [ subset of Parents ] # singleton list -sub classify ($) { - my ($objid) = @_; +sub parsecommit ($;$) { + my ($objid, $p_ref) = @_; + # => hash with CommitId Hdr Msg Tree Parents + # Parents entries have only Ix CommitId + # $p_ref, if provided, must be [] and is used as a base for Parents + + $p_ref //= []; + die if @$p_ref; my ($h,$m) = get_commit $objid; my ($t) = $h =~ m/^tree (\w+)$/m or die $objid; my (@ph) = $h =~ m/^parent (\w+)$/mg; - my @p; my $r = { CommitId => $objid, Hdr => $h, Msg => $m, Tree => $t, - Parents => \@p, + Parents => $p_ref, }; foreach my $ph (@ph) { - push @p, { - Ix => $#p, + push @$p_ref, { + Ix => $#$p_ref, CommitId => $ph, - Differs => (get_differs $ph, $t), }; } + return $r; +} + +sub classify ($) { + my ($objid) = @_; + + my @p; + my $r = parsecommit($objid, \@p); + my $t = $r->{Tree}; + + foreach my $p (@p) { + $p->{Differs} => (get_differs $p->{CommitId}, $t), + } + printdebug "classify $objid \$t=$t \@p", (map { sprintf " %s/%#x", $_->{CommitId}, $_->{Differs} } @p), "\n"; @@ -389,7 +407,7 @@ sub classify ($) { ($p->{IsDgitImport},) = $p_m =~ m/^\[dgit import ([0-9a-z]+) .*\]$/m; } my @orig_ps = grep { ($_->{IsDgitImport}//'X') eq 'orig' } @p; - my $m2 = $m; + my $m2 = $r->{Msg}; if (!(grep { !$_->{IsOrigin} } @p) and (@orig_ps >= @p - 1) and $m2 =~ s{^\[(dgit import unpatched .*)\]$}{[was: $1]}m) { -- cgit v1.2.3