[PATCH] annotate: Support annotation of files on other revisions.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>

---

 git-annotate.perl   |    7 +++++--
 t/t8001-annotate.sh |    6 ++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

On Mon, Mar 06, 2006 at 01:29:32PM +1300, Martin Langhoff wrote:
> On 3/6/06, Ryan Anderson <ryan@xxxxxxxxxxxxxx> wrote:
> > Along these lines, if anyone can pin down the complicated cases that
> > annotate and blame get differently, adding them as a test would be
> > *exceedingly* appreciated, even if it makes annotate (or blame) fail for
> > a bit, it gives us something to work against.
> 
> It would be great if they both worked properly with paths that existed
> in the past. Right now, I can't git-annotate or git-blame a file I
> know was there in a past revision. I think I had taught Johannes'
> annotate to deal with this, or at least intended to. As things stand,
> git-annotate/git-blame need a checkout, which is really silly.

annotate was *trying* to handle that cleanly, but failed due to a silly
bug.  This is the same bug that Junio pointed out:
	cd t
	./t8001-annotate.sh
	cd trash
	../../git-annotate file master

This is fixed by the patch at the end of this email.

> Tools like gitweb and cvsserver should be able to do:
> 
>   GIT_DIR=/somebarerepo/git.git git-(annotate|blame) -h headname Makefile
> 
> and not worry about creating a temporary index *and* checking out
> Makefile so that things work. That's what cvsserver does now, anyway.
> Ugly :-(

For annotate, the syntax I was using was:
	git annotate Makefile headname

I'm not married to it, so please, send a patch to change it if you want
(Please fix up the test case I'm sending in this patch, as well.)

cdd80fd28d300dd2400bf75ff64ae2bf1a8b92aa
diff --git a/git-annotate.perl b/git-annotate.perl
index d93ee19..5953ac6 100755
--- a/git-annotate.perl
+++ b/git-annotate.perl
@@ -10,6 +10,7 @@ use warnings;
 use strict;
 use Getopt::Long;
 use POSIX qw(strftime gmtime);
+use Data::Dumper;
 
 sub usage() {
 	print STDERR 'Usage: ${\basename $0} [-s] [-S revs-file] file [ revision ]
@@ -99,7 +100,7 @@ while (my $bound = pop @stack) {
 	}
 }
 push @revqueue, $head;
-init_claim( defined $starting_rev ? $starting_rev : 'dirty');
+init_claim( defined $starting_rev ? $head : 'dirty');
 unless (defined $starting_rev) {
 	my $diff = open_pipe("git","diff","-R", "HEAD", "--",$filename)
 		or die "Failed to call git diff to check for dirty state: $!";
@@ -345,6 +346,7 @@ sub git_cat_file {
 	return () unless defined $rev && defined $filename;
 
 	my $blob = git_ls_tree($rev, $filename);
+	die "Failed to find a blob for $filename in rev $rev\n" if !defined $blob;
 
 	my $catfile = open_pipe("git","cat-file", "blob", $blob)
 		or die "Failed to git-cat-file blob $blob (rev $rev, file $filename): " . $!;
@@ -367,12 +369,13 @@ sub git_ls_tree {
 
 	my ($mode, $type, $blob, $tfilename);
 	while(<$lstree>) {
+		chomp;
 		($mode, $type, $blob, $tfilename) = split(/\s+/, $_, 4);
 		last if ($tfilename eq $filename);
 	}
 	close($lstree);
 
-	return $blob if $filename eq $filename;
+	return $blob if ($tfilename eq $filename);
 	die "git-ls-tree failed to find blob for $filename";
 
 }
diff --git a/t/t8001-annotate.sh b/t/t8001-annotate.sh
index 172908a..761d0bc 100755
--- a/t/t8001-annotate.sh
+++ b/t/t8001-annotate.sh
@@ -87,4 +87,10 @@ test_expect_success \
     'One line blamed on B2' \
     '[ $(git annotate file | awk "{print \$3}" | grep -c "^B2$") == 1 ]'
 
+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.2.4.g9201-dirty



-- 

Ryan Anderson
  sometimes Pug Majere
-
: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]