Skip to content

Commit

Permalink
contacts: validate hunk length earlier
Browse files Browse the repository at this point in the history
Rather than calling get_blame() with a zero-length hunk only to have it
rejected immediately, perform hunk-length validation earlier in order to
avoid calling get_blame() unnecessarily.

This is a preparatory step to simplify later patches which reduce the
number of git-blame invocations by collecting together all lines to
blame within a single file at a particular revision. By validating the
blame range early, the subsequent patch can more easily avoid adding
empty ranges at collection time.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Eric Sunshine authored and Junio C Hamano committed Aug 13, 2013
1 parent 5ce922a commit 9ae9ca1
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions contrib/contacts/git-contacts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ sub import_commits {

sub get_blame {
my ($commits, $source, $start, $len, $from) = @_;
$len = 1 unless defined($len);
return if $len == 0;
open my $f, '-|',
qw(git blame --porcelain -C), '-L', "$start,+$len",
'--since', $since, "$from^", '--', $source or die;
Expand Down Expand Up @@ -90,7 +88,8 @@ sub scan_patches {
} elsif (/^--- /) {
die "Cannot parse hunk source: $_\n";
} elsif (/^@@ -(\d+)(?:,(\d+))?/ && $source) {
get_blame($commits, $source, $1, $2, $id);
my $len = defined($2) ? $2 : 1;
get_blame($commits, $source, $1, $len, $id) if $len;
}
}
}
Expand Down

0 comments on commit 9ae9ca1

Please sign in to comment.