summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2013-09-09 14:50:36 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-09-09 14:50:36 -0700
commit3b30ba55e4c14c6939a201e87d3542e157e2b318 (patch)
treec7a7f2b4083dc789652ac4c4330af2801f3404f2 /contrib
parentMerge branch 'jc/url-match' (diff)
parentcontacts: reduce git-blame invocations (diff)
downloadtgif-3b30ba55e4c14c6939a201e87d3542e157e2b318.tar.xz
Merge branch 'es/contacts-blame-L-multi'
* es/contacts-blame-L-multi: contacts: reduce git-blame invocations contacts: gather all blame sources prior to invoking git-blame contacts: validate hunk length earlier
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/contacts/git-contacts31
1 files changed, 22 insertions, 9 deletions
diff --git a/contrib/contacts/git-contacts b/contrib/contacts/git-contacts
index d80f7d1b6e..fb6429b64b 100755
--- a/contrib/contacts/git-contacts
+++ b/contrib/contacts/git-contacts
@@ -59,11 +59,11 @@ sub import_commits {
}
sub get_blame {
- my ($commits, $source, $start, $len, $from) = @_;
- $len = 1 unless defined($len);
- return if $len == 0;
+ my ($commits, $source, $from, $ranges) = @_;
+ return unless @$ranges;
open my $f, '-|',
- qw(git blame --porcelain -C), '-L', "$start,+$len",
+ qw(git blame --porcelain -C),
+ map({"-L$_->[0],+$_->[1]"} @$ranges),
'--since', $since, "$from^", '--', $source or die;
while (<$f>) {
if (/^([0-9a-f]{40}) \d+ \d+ \d+$/) {
@@ -76,8 +76,17 @@ sub get_blame {
close $f;
}
+sub blame_sources {
+ my ($sources, $commits) = @_;
+ for my $s (keys %$sources) {
+ for my $id (keys %{$sources->{$s}}) {
+ get_blame($commits, $s, $id, $sources->{$s}{$id});
+ }
+ }
+}
+
sub scan_patches {
- my ($commits, $id, $f) = @_;
+ my ($sources, $id, $f) = @_;
my $source;
while (<$f>) {
if (/^From ([0-9a-f]{40}) Mon Sep 17 00:00:00 2001$/) {
@@ -90,7 +99,8 @@ sub scan_patches {
} elsif (/^--- /) {
die "Cannot parse hunk source: $_\n";
} elsif (/^@@ -(\d+)(?:,(\d+))?/ && $source) {
- get_blame($commits, $source, $1, $2, $id);
+ my $len = defined($2) ? $2 : 1;
+ push @{$sources->{$source}{$id}}, [$1, $len] if $len;
}
}
}
@@ -163,13 +173,16 @@ for (@ARGV) {
}
}
-my %commits;
+my %sources;
for (@files) {
- scan_patch_file(\%commits, $_);
+ scan_patch_file(\%sources, $_);
}
if (@rev_args) {
- scan_rev_args(\%commits, \@rev_args)
+ scan_rev_args(\%sources, \@rev_args)
}
+
+my %commits;
+blame_sources(\%sources, \%commits);
import_commits(\%commits);
my $contacts = {};