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 <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Sunshine committed
Aug 9, 2013 at 17:39 UTC
db8cae7e6035dd56970c88ac9e34bce1baa0f665
1 file changed
+20
-5
contrib/contacts/git-contacts
+20
-5
@@ -74,8 +74,20 @@ sub get_blame {
74
close $f;
75
}
76
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
+
89
sub scan_patches {
78
- my ($commits, $id, $f) = @_;
90
+ my ($sources, $id, $f) = @_;
91
my $source;
92
while (<$f>) {
93
if (/^From ([0-9a-f]{40}) Mon Sep 17 00:00:00 2001$/) {
@@ -89,7 +101,7 @@ sub scan_patches {
101
die "Cannot parse hunk source: $_\n";
102
} elsif (/^@@ -(\d+)(?:,(\d+))?/ && $source) {
103
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;
105
}
106
}
107
}
@@ -162,13 +174,16 @@ for (@ARGV) {
174
}
175
}
176
165
-my %commits;
177
+my %sources;
178
for (@files) {
167
- scan_patch_file(\%commits, $_);
179
+ scan_patch_file(\%sources, $_);
180
}
181
if (@rev_args) {
170
- scan_rev_args(\%commits, \@rev_args)
182
+ scan_rev_args(\%sources, \@rev_args)
183
}
184
+
185
+my %commits;
186
+blame_sources(\%sources, \%commits);
187
import_commits(\%commits);
188
189
my $contacts = {};