X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-annotate.perl;h=a6a7a482cdcf34e3a1d545c7d5deab599a7c0d2f;hb=9c0f4823614cf80b0d110a648d95de84be5b7bd3;hp=91da6d5b7f8b35592597dbedf2fd7f7c6fc5609e;hpb=87475f4dfce96b040fffbaefda9a4daa789786b2;p=git.git diff --git a/git-annotate.perl b/git-annotate.perl index 91da6d5b7..a6a7a482c 100755 --- a/git-annotate.perl +++ b/git-annotate.perl @@ -10,29 +10,33 @@ use warnings; use strict; use Getopt::Long; use POSIX qw(strftime gmtime); +use File::Basename qw(basename dirname); sub usage() { - print STDERR 'Usage: ${\basename $0} [-s] [-S revs-file] file [ revision ] + print STDERR "Usage: ${\basename $0} [-s] [-S revs-file] file [ revision ] -l, --long Show long rev (Defaults off) + -t, --time + Show raw timestamp (Defaults off) -r, --rename Follow renames (Defaults on). -S, --rev-file revs-file - use revs from revs-file instead of calling git-rev-list + Use revs from revs-file instead of calling git-rev-list -h, --help This message. -'; +"; exit(1); } -our ($help, $longrev, $rename, $starting_rev, $rev_file) = (0, 0, 1); +our ($help, $longrev, $rename, $rawtime, $starting_rev, $rev_file) = (0, 0, 1); my $rc = GetOptions( "long|l" => \$longrev, + "time|t" => \$rawtime, "help|h" => \$help, "rename|r" => \$rename, - "rev-file|S" => \$rev_file); -if (!$rc or $help) { + "rev-file|S=s" => \$rev_file); +if (!$rc or $help or !@ARGV) { usage(); } @@ -96,17 +100,17 @@ 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) { - open(DIFF,"-|","git","diff","-R", "HEAD", "--",$filename) + my $diff = open_pipe("git","diff","-R", "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()), ) ); - close(DIFF); + close($diff); } handle_rev(); @@ -125,7 +129,7 @@ foreach my $l (@filelines) { } printf("%s\t(%10s\t%10s\t%d)%s\n", $rev, $committer, - format_date($date), $i++, $output); + format_date($date), ++$i, $output); } sub init_claim { @@ -172,20 +176,22 @@ sub handle_rev { sub git_rev_list { my ($rev, $file) = @_; + my $revlist; if ($rev_file) { - open(P, '<' . $rev_file); + open($revlist, '<' . $rev_file) + or die "Failed to open $rev_file : $!"; } else { - open(P,"-|","git-rev-list","--parents","--remove-empty",$rev,"--",$file) + $revlist = open_pipe("git-rev-list","--parents","--remove-empty",$rev,"--",$file) or die "Failed to exec git-rev-list: $!"; } my @revs; - while(my $line =
) { + while(my $line = <$revlist>) { chomp $line; my ($rev, @parents) = split /\s+/, $line; push @revs, [ $rev, @parents ]; } - close(P); + close($revlist); printf("0 revs found for rev %s (%s)\n", $rev, $file) if (@revs == 0); return @revs; @@ -194,22 +200,25 @@ sub git_rev_list { sub find_parent_renames { my ($rev, $file) = @_; - open(P,"-|","git-diff-tree", "-M50", "-r","--name-status", "-z","$rev") + my $patch = open_pipe("git-diff-tree", "-M50", "-r","--name-status", "-z","$rev") or die "Failed to exec git-diff: $!"; local $/ = "\0"; my %bound; - my $junk =
; - while (my $change =
) { + my $junk = <$patch>; + while (my $change = <$patch>) { chomp $change; - my $filename =
; + my $filename = <$patch>; + if (!defined $filename) { + next; + } chomp $filename; if ($change =~ m/^[AMD]$/ ) { next; } elsif ($change =~ m/^R/ ) { my $oldfilename = $filename; - $filename =
;
+ $filename = <$patch>;
chomp $filename;
if ( $file eq $filename ) {
my $parent = git_find_parent($rev, $oldfilename);
@@ -218,7 +227,7 @@ sub find_parent_renames {
}
}
}
- close(P);
+ close($patch);
return \%bound;
}
@@ -227,14 +236,14 @@ sub find_parent_renames {
sub git_find_parent {
my ($rev, $filename) = @_;
- open(REVPARENT,"-|","git-rev-list","--remove-empty", "--parents","--max-count=1","$rev","--",$filename)
+ my $revparent = open_pipe("git-rev-list","--remove-empty", "--parents","--max-count=1","$rev","--",$filename)
or die "Failed to open git-rev-list to find a single parent: $!";
- my $parentline =