Skip to content

Commit 9ae9ca1

Browse files
sunshinecogitster
authored andcommitted
contacts: validate hunk length earlier
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ce922a commit 9ae9ca1

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

contrib/contacts/git-contacts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ sub import_commits {
6060

6161
sub get_blame {
6262
my ($commits, $source, $start, $len, $from) = @_;
63-
$len = 1 unless defined($len);
64-
return if $len == 0;
6563
open my $f, '-|',
6664
qw(git blame --porcelain -C), '-L', "$start,+$len",
6765
'--since', $since, "$from^", '--', $source or die;
@@ -90,7 +88,8 @@ sub scan_patches {
9088
} elsif (/^--- /) {
9189
die "Cannot parse hunk source: $_\n";
9290
} elsif (/^@@ -(\d+)(?:,(\d+))?/ && $source) {
93-
get_blame($commits, $source, $1, $2, $id);
91+
my $len = defined($2) ? $2 : 1;
92+
get_blame($commits, $source, $1, $len, $id) if $len;
9493
}
9594
}
9695
}

0 commit comments

Comments
 (0)