* [PATCH 0/2] Fix handling of merges in git-annotate
@ 2006-07-04 1:30 Ryan Anderson
2006-07-04 1:30 ` [PATCH 1/2] annotate: Support annotation of files on other revisions Ryan Anderson
2006-07-04 1:34 ` [PATCH 0/2] Fix handling of merges in git-annotate Ryan Anderson
0 siblings, 2 replies; 6+ messages in thread
From: Ryan Anderson @ 2006-07-04 1:30 UTC (permalink / raw)
To: junkio; +Cc: git
This 2-patch series is a major overhaul to the way git-annotate calculates the blame for each line.
Instead of parsing each diff in reverse, this uses the output from "git
diff-tree --combined", so that merges can be handled sanely.
Ryan Anderson:
annotate: Support annotation of files on other revisions.
annotate: Correct most merge following to annotate correctly.
git-annotate.perl | 197 ++++++++++++++++++++++++++++++++++++---------------
t/t8001-annotate.sh | 6 ++
2 files changed, 145 insertions(+), 58 deletions(-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] annotate: Support annotation of files on other revisions.
2006-07-04 1:30 [PATCH 0/2] Fix handling of merges in git-annotate Ryan Anderson
@ 2006-07-04 1:30 ` Ryan Anderson
2006-07-04 1:30 ` [PATCH 2/2] annotate: Correct most merge following to annotate correctly Ryan Anderson
2006-07-04 8:04 ` [PATCH] t8001-annotate: fix a bash-ism in this test Eric Wong
2006-07-04 1:34 ` [PATCH 0/2] Fix handling of merges in git-annotate Ryan Anderson
1 sibling, 2 replies; 6+ messages in thread
From: Ryan Anderson @ 2006-07-04 1:30 UTC (permalink / raw)
To: junkio; +Cc: git, Ryan Anderson
This is a bug fix, and cleans up one or two other things spotted during the
course of tracking down the main bug here.
Also, the test-suite is updated to reflect this case.
Signed-off-by: Ryan Anderson <ryan@michonline.com>
(cherry picked from 2f7554b4db3ab2c2d3866b160245c91c9236fc9a commit)
---
t/t8001-annotate.sh | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/t/t8001-annotate.sh b/t/t8001-annotate.sh
index 2496397..70e2ad2 100755
--- a/t/t8001-annotate.sh
+++ b/t/t8001-annotate.sh
@@ -6,4 +6,10 @@ test_description='git-annotate'
PROG='git annotate'
. ../annotate-tests.sh
+test_expect_success \
+ 'Annotating an old revision works' \
+ '[ $(git annotate file master | awk "{print \$3}" | grep -c "^A$") == 2 ] && \
+ [ $(git annotate file master | awk "{print \$3}" | grep -c "^B$") == 2 ]'
+
+
test_done
--
1.4.1.g8fced
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] annotate: Correct most merge following to annotate correctly.
2006-07-04 1:30 ` [PATCH 1/2] annotate: Support annotation of files on other revisions Ryan Anderson
@ 2006-07-04 1:30 ` Ryan Anderson
2006-07-04 8:04 ` [PATCH] t8001-annotate: fix a bash-ism in this test Eric Wong
1 sibling, 0 replies; 6+ messages in thread
From: Ryan Anderson @ 2006-07-04 1:30 UTC (permalink / raw)
To: junkio; +Cc: git, Ryan Anderson
There is still a bug involving octopus merges, somewhere, but this gets normal
merges correct, so it's still an improvement over the existing version.
Signed-off-by: Ryan Anderson <ryan@michonline.com>
---
git-annotate.perl | 197 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 139 insertions(+), 58 deletions(-)
diff --git a/git-annotate.perl b/git-annotate.perl
index a6a7a48..9a7b022 100755
--- a/git-annotate.perl
+++ b/git-annotate.perl
@@ -102,10 +102,10 @@ while (my $bound = pop @stack) {
push @revqueue, $head;
init_claim( defined $starting_rev ? $head : 'dirty');
unless (defined $starting_rev) {
- my $diff = open_pipe("git","diff","-R", "HEAD", "--",$filename)
+ my $diff = open_pipe("git","diff","HEAD", "--",$filename)
or die "Failed to call git diff to check for dirty state: $!";
- _git_diff_parse($diff, $head, "dirty", (
+ _git_diff_parse($diff, [$head], "dirty", (
'author' => gitvar_name("GIT_AUTHOR_IDENT"),
'author_date' => sprintf("%s +0000",time()),
)
@@ -154,14 +154,13 @@ sub handle_rev {
my %revinfo = git_commit_info($rev);
- foreach my $p (@{$revs{$rev}{'parents'}}) {
-
- git_diff_parse($p, $rev, %revinfo);
- push @revqueue, $p;
- }
+ if (exists $revs{$rev}{parents} &&
+ scalar @{$revs{$rev}{parents}} != 0) {
+ git_diff_parse($revs{$rev}{'parents'}, $rev, %revinfo);
+ push @revqueue, @{$revs{$rev}{'parents'}};
- if (scalar @{$revs{$rev}{parents}} == 0) {
+ } else {
# We must be at the initial rev here, so claim everything that is left.
for (my $i = 0; $i < @{$revs{$rev}{lines}}; $i++) {
if (ref ${$revs{$rev}{lines}}[$i] eq '' || ${$revs{$rev}{lines}}[$i][1] eq '') {
@@ -252,89 +251,171 @@ sub git_find_parent {
# Get a diff between the current revision and a parent.
# Record the commit information that results.
sub git_diff_parse {
- my ($parent, $rev, %revinfo) = @_;
+ my ($parents, $rev, %revinfo) = @_;
+
+ my @filenames = ( $revs{$rev}{'filename'} );
+ foreach my $parent (@$parents) {
+ push @filenames, $revs{$parent}{'filename'};
+ }
- my $diff = open_pipe("git-diff-tree","-M","-p",$rev,$parent,"--",
- $revs{$rev}{'filename'}, $revs{$parent}{'filename'})
+ my $diff = open_pipe("git-diff-tree","-M","-p","-c",$rev,"--",
+ @filenames )
or die "Failed to call git-diff for annotation: $!";
- _git_diff_parse($diff, $parent, $rev, %revinfo);
+ _git_diff_parse($diff, $parents, $rev, %revinfo);
close($diff);
}
sub _git_diff_parse {
- my ($diff, $parent, $rev, %revinfo) = @_;
+ my ($diff, $parents, $rev, %revinfo) = @_;
+
+ my $ri = 0;
- my ($ri, $pi) = (0,0);
my $slines = $revs{$rev}{'lines'};
- my @plines;
+ my (%plines, %pi);
my $gotheader = 0;
my ($remstart);
- my ($hunk_start, $hunk_index);
+ my $parent_count = @$parents;
+
+ my $diff_header_regexp = "^@";
+ $diff_header_regexp .= "@" x @$parents;
+ $diff_header_regexp .= ' -\d+,\d+' x @$parents;
+ $diff_header_regexp .= ' \+(\d+),\d+';
+
+ my %claim_regexps;
+ my $allparentplus = '^' . '\\+' x @$parents . '(.*)$';
+
+ {
+ my $i = 0;
+ foreach my $parent (@$parents) {
+
+ $pi{$parent} = 0;
+ my $r = '^' . '.' x @$parents . '(.*)$';
+ my $p = $r;
+ substr($p,$i+1, 1) = '\\+';
+
+ my $m = $r;
+ substr($m,$i+1, 1) = '-';
+
+ $claim_regexps{$parent}{plus} = $p;
+ $claim_regexps{$parent}{minus} = $m;
+
+ $plines{$parent} = [];
+
+ $i++;
+ }
+ }
+
+ DIFF:
while(<$diff>) {
chomp;
- if (m/^@@ -(\d+),(\d+) \+(\d+),(\d+)/) {
- $remstart = $1;
- # Adjust for 0-based arrays
- $remstart--;
- # Reinit hunk tracking.
- $hunk_start = $remstart;
- $hunk_index = 0;
+ if (m/$diff_header_regexp/) {
+ $remstart = $1 - 1;
+ # (0-based arrays)
+
$gotheader = 1;
- for (my $i = $ri; $i < $remstart; $i++) {
- $plines[$pi++] = $slines->[$i];
- $ri++;
+ printf("Copying from %d to %d\n", $ri, $remstart);
+ foreach my $parent (@$parents) {
+ for (my $i = $ri; $i < $remstart; $i++) {
+ $plines{$parent}[$pi{$parent}++] = $slines->[$i];
+ }
}
- next;
- } elsif (!$gotheader) {
- next;
- }
+ $ri = $remstart;
- if (m/^\+(.*)$/) {
- my $line = $1;
- $plines[$pi++] = [ $line, '', '', '', 0 ];
- next;
+ next DIFF;
- } elsif (m/^-(.*)$/) {
- my $line = $1;
- if (get_line($slines, $ri) eq $line) {
- # Found a match, claim
- claim_line($ri, $rev, $slines, %revinfo);
- } else {
- die sprintf("Sync error: %d/%d\n|%s\n|%s\n%s => %s\n",
- $ri, $hunk_start + $hunk_index,
- $line,
- get_line($slines, $ri),
- $rev, $parent);
- }
- $ri++;
+ } elsif (!$gotheader) {
+ # Skip over the leadin.
+ next DIFF;
+ }
- } elsif (m/^\\/) {
+ if (m/^\\/) {
;
# Skip \No newline at end of file.
# But this can be internationalized, so only look
# for an initial \
} else {
- if (substr($_,1) ne get_line($slines,$ri) ) {
- die sprintf("Line %d (%d) does not match:\n|%s\n|%s\n%s => %s\n",
- $hunk_start + $hunk_index, $ri,
- substr($_,1),
- get_line($slines,$ri),
- $rev, $parent);
+ my %claims = ();
+ my $negclaim = 0;
+ my $allclaimed = 0;
+ my $line;
+
+ if (m/$allparentplus/) {
+ claim_line($ri, $rev, $slines, %revinfo);
+ $allclaimed = 1;
+
+ }
+
+ PARENT:
+ foreach my $parent (keys %claim_regexps) {
+ my $m = $claim_regexps{$parent}{minus};
+ my $p = $claim_regexps{$parent}{plus};
+
+ if (m/$m/) {
+ $line = $1;
+ $plines{$parent}[$pi{$parent}++] = [ $line, '', '', '', 0 ];
+ $negclaim++;
+
+ } elsif (m/$p/) {
+ $line = $1;
+ if (get_line($slines, $ri) eq $line) {
+ # Found a match, claim
+ $claims{$parent}++;
+
+ } else {
+ die sprintf("Sync error: %d\n|%s\n|%s\n%s => %s\n",
+ $ri, $line,
+ get_line($slines, $ri),
+ $rev, $parent);
+ }
+ }
+ }
+
+ if (%claims) {
+ foreach my $parent (@$parents) {
+ next if $claims{$parent} || $allclaimed;
+ $plines{$parent}[$pi{$parent}++] = $slines->[$ri];
+ #[ $line, '', '', '', 0 ];
+ }
+ $ri++;
+
+ } elsif ($negclaim) {
+ next DIFF;
+
+ } else {
+ if (substr($_,scalar @$parents) ne get_line($slines,$ri) ) {
+ foreach my $parent (@$parents) {
+ printf("parent %s is on line %d\n", $parent, $pi{$parent});
+ }
+
+ die sprintf("Line %d, does not match:\n|%s|\n|%s|\n%s\n",
+ $ri,
+ substr($_,scalar @$parents),
+ get_line($slines,$ri), $rev);
+ }
+ foreach my $parent (@$parents) {
+ $plines{$parent}[$pi{$parent}++] = $slines->[$ri];
+ }
+ $ri++;
}
- $plines[$pi++] = $slines->[$ri++];
}
- $hunk_index++;
}
+
for (my $i = $ri; $i < @{$slines} ; $i++) {
- push @plines, $slines->[$ri++];
+ foreach my $parent (@$parents) {
+ push @{$plines{$parent}}, $slines->[$ri];
+ }
+ $ri++;
+ }
+
+ foreach my $parent (@$parents) {
+ $revs{$parent}{lines} = $plines{$parent};
}
- $revs{$parent}{lines} = \@plines;
return;
}
--
1.4.1.g8fced
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] Fix handling of merges in git-annotate
2006-07-04 1:30 [PATCH 0/2] Fix handling of merges in git-annotate Ryan Anderson
2006-07-04 1:30 ` [PATCH 1/2] annotate: Support annotation of files on other revisions Ryan Anderson
@ 2006-07-04 1:34 ` Ryan Anderson
1 sibling, 0 replies; 6+ messages in thread
From: Ryan Anderson @ 2006-07-04 1:34 UTC (permalink / raw)
To: Ryan Anderson; +Cc: junkio, git
[-- Attachment #1: Type: text/plain, Size: 411 bytes --]
Ryan Anderson wrote:
> This 2-patch series is a major overhaul to the way git-annotate calculates the blame for each line.
>
> Instead of parsing each diff in reverse, this uses the output from "git
> diff-tree --combined", so that merges can be handled sanely.
>
I forgot:
Please pull from http://h4x0r5.com/~ryan/git/ryan.git annotate-upstream
--
Ryan Anderson
sometimes Pug Majere
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] t8001-annotate: fix a bash-ism in this test
2006-07-04 1:30 ` [PATCH 1/2] annotate: Support annotation of files on other revisions Ryan Anderson
2006-07-04 1:30 ` [PATCH 2/2] annotate: Correct most merge following to annotate correctly Ryan Anderson
@ 2006-07-04 8:04 ` Eric Wong
2006-07-04 8:46 ` Junio C Hamano
1 sibling, 1 reply; 6+ messages in thread
From: Eric Wong @ 2006-07-04 8:04 UTC (permalink / raw)
To: Ryan Anderson; +Cc: junkio, git
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
t/t8001-annotate.sh | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/t/t8001-annotate.sh b/t/t8001-annotate.sh
index 70e2ad2..3a6490e 100755
--- a/t/t8001-annotate.sh
+++ b/t/t8001-annotate.sh
@@ -8,8 +8,8 @@ PROG='git annotate'
test_expect_success \
'Annotating an old revision works' \
- '[ $(git annotate file master | awk "{print \$3}" | grep -c "^A$") == 2 ] && \
- [ $(git annotate file master | awk "{print \$3}" | grep -c "^B$") == 2 ]'
+ '[ $(git annotate file master | awk "{print \$3}" | grep -c "^A$") -eq 2 ] && \
+ [ $(git annotate file master | awk "{print \$3}" | grep -c "^B$") -eq 2 ]'
test_done
--
1.4.1.g4148
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] t8001-annotate: fix a bash-ism in this test
2006-07-04 8:04 ` [PATCH] t8001-annotate: fix a bash-ism in this test Eric Wong
@ 2006-07-04 8:46 ` Junio C Hamano
0 siblings, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2006-07-04 8:46 UTC (permalink / raw)
To: Eric Wong; +Cc: git
Thanks -- good catch.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-07-04 8:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-04 1:30 [PATCH 0/2] Fix handling of merges in git-annotate Ryan Anderson
2006-07-04 1:30 ` [PATCH 1/2] annotate: Support annotation of files on other revisions Ryan Anderson
2006-07-04 1:30 ` [PATCH 2/2] annotate: Correct most merge following to annotate correctly Ryan Anderson
2006-07-04 8:04 ` [PATCH] t8001-annotate: fix a bash-ism in this test Eric Wong
2006-07-04 8:46 ` Junio C Hamano
2006-07-04 1:34 ` [PATCH 0/2] Fix handling of merges in git-annotate Ryan Anderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).