Skip to content

Commit db8cae7

Browse files
sunshinecogitster
authored andcommitted
contacts: gather all blame sources prior to invoking git-blame
git-contacts invokes git-blame immediately upon encountering a patch hunk. No attempt is made to consolidate invocations for multiple hunks referencing the same file at the same revision. This can become expensive quickly. Any effort to reduce the number of times git-blame is run will need to to know in advance which line ranges to blame per file per revision. Make this information available by collecting all sources as a distinct step from invoking git-blame. A subsequent patch will utilize the information to optimize git-blame invocations. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ae9ca1 commit db8cae7

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

contrib/contacts/git-contacts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,20 @@ sub get_blame {
7474
close $f;
7575
}
7676

77+
sub blame_sources {
78+
my ($sources, $commits) = @_;
79+
for my $s (keys %$sources) {
80+
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+
}
85+
}
86+
}
87+
}
88+
7789
sub scan_patches {
78-
my ($commits, $id, $f) = @_;
90+
my ($sources, $id, $f) = @_;
7991
my $source;
8092
while (<$f>) {
8193
if (/^From ([0-9a-f]{40}) Mon Sep 17 00:00:00 2001$/) {
@@ -89,7 +101,7 @@ sub scan_patches {
89101
die "Cannot parse hunk source: $_\n";
90102
} elsif (/^@@ -(\d+)(?:,(\d+))?/ && $source) {
91103
my $len = defined($2) ? $2 : 1;
92-
get_blame($commits, $source, $1, $len, $id) if $len;
104+
push @{$sources->{$source}{$id}}, [$1, $len] if $len;
93105
}
94106
}
95107
}
@@ -162,13 +174,16 @@ for (@ARGV) {
162174
}
163175
}
164176

165-
my %commits;
177+
my %sources;
166178
for (@files) {
167-
scan_patch_file(\%commits, $_);
179+
scan_patch_file(\%sources, $_);
168180
}
169181
if (@rev_args) {
170-
scan_rev_args(\%commits, \@rev_args)
182+
scan_rev_args(\%sources, \@rev_args)
171183
}
184+
185+
my %commits;
186+
blame_sources(\%sources, \%commits);
172187
import_commits(\%commits);
173188

174189
my $contacts = {};

0 commit comments

Comments
 (0)