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 <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Sunshine committed
Aug 9, 2013 at 17:39 UTC
9ae9ca1f95ccd3b4c1d62d856eb8b48fdff7c2d5
1 file changed
+2
-3
contrib/contacts/git-contacts
+2
-3
@@ -60,8 +60,6 @@ sub import_commits {
60
61
sub get_blame {
62
my ($commits, $source, $start, $len, $from) = @_;
63
- $len = 1 unless defined($len);
64
- return if $len == 0;
63
open my $f, '-|',
64
qw(git blame --porcelain -C), '-L', "$start,+$len",
65
'--since', $since, "$from^", '--', $source or die;
@@ -90,7 +88,8 @@ sub scan_patches {
88
} elsif (/^--- /) {
89
die "Cannot parse hunk source: $_\n";
90
} 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;
93
}
94
}
95
}