Skip to content

Commit 4c70cfb

Browse files
sunshinecogitster
authored andcommitted
contacts: reduce git-blame invocations
git-contacts invokes git-blame once for each patch hunk it encounters. No attempt is made to consolidate invocations for multiple hunks referencing the same file at the same revision. This can become expensive quickly. Reduce the number of git-blame invocations by taking advantage of the ability to specify multiple -L ranges for a single invocation. Without this patch, on a randomly chosen range of commits: % time git-contacts 25fba78^..23c339c >/dev/null real 0m6.142s user 0m5.429s sys 0m0.356s With this patch: % time git-contacts 25fba78^..23c339c >/dev/null real 0m2.285s user 0m2.093s sys 0m0.165s Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent db8cae7 commit 4c70cfb

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

contrib/contacts/git-contacts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ sub import_commits {
5959
}
6060

6161
sub get_blame {
62-
my ($commits, $source, $start, $len, $from) = @_;
62+
my ($commits, $source, $from, $ranges) = @_;
63+
return unless @$ranges;
6364
open my $f, '-|',
64-
qw(git blame --porcelain -C), '-L', "$start,+$len",
65+
qw(git blame --porcelain -C),
66+
map({"-L$_->[0],+$_->[1]"} @$ranges),
6567
'--since', $since, "$from^", '--', $source or die;
6668
while (<$f>) {
6769
if (/^([0-9a-f]{40}) \d+ \d+ \d+$/) {
@@ -78,10 +80,7 @@ sub blame_sources {
7880
my ($sources, $commits) = @_;
7981
for my $s (keys %$sources) {
8082
for my $id (keys %{$sources->{$s}}) {
81-
for my $range (@{$sources->{$s}{$id}}) {
82-
get_blame($commits, $s,
83-
$range->[0], $range->[1], $id);
84-
}
83+
get_blame($commits, $s, $id, $sources->{$s}{$id});
8584
}
8685
}
8786
}

0 commit comments

Comments
 (0)