contrib: contacts: add ability to parse from committish

For example: % git contacts R1..R2 Committishes and patch files can be mentioned in the same invocation: % git contacts R1..R2 extra/*.patch Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 21, 2013 at 06:52 UTC 8e7c4a82ec25ee92bcb81de8bb8c4a27876d6edc
1 file changed +32 -6
contrib/contacts/git-contacts
+32 -6
@@ -3,7 +3,7 @@
3 # List people who might be interested in a patch. Useful as the argument to
4 # git-send-email --cc-cmd option, and in other situations.
5 #
6 -# Usage: git contacts <file> ...
6 +# Usage: git contacts <file | rev-list option> ...
7
8 use strict;
9 use warnings;
@@ -77,8 +77,8 @@ sub get_blame {
77 }
78
79 sub scan_patches {
80 - my ($commits, $f) = @_;
81 - my ($id, $source);
80 + my ($commits, $id, $f) = @_;
81 + my $source;
82 while (<$f>) {
83 if (/^From ([0-9a-f]{40}) Mon Sep 17 00:00:00 2001$/) {
84 $id = $1;
@@ -98,18 +98,44 @@ sub scan_patches {
98 sub scan_patch_file {
99 my ($commits, $file) = @_;
100 open my $f, '<', $file or die "read failure: $file: $!\n";
101 - scan_patches($commits, $f);
101 + scan_patches($commits, undef, $f);
102 + close $f;
103 +}
104 +
105 +sub scan_rev_args {
106 + my ($commits, $args) = @_;
107 + open my $f, '-|', qw(git rev-list --reverse), @$args or die;
108 + while (<$f>) {
109 + chomp;
110 + my $id = $_;
111 + $seen{$id} = 1;
112 + open my $g, '-|', qw(git show -C --oneline), $id or die;
113 + scan_patches($commits, $id, $g);
114 + close $g;
115 + }
116 close $f;
117 }
118
119 if (!@ARGV) {
106 - die "No input patch files\n";
120 + die "No input revisions or patch files\n";
121 }
122
109 -my %commits;
123 +my (@files, @rev_args);
124 for (@ARGV) {
125 + if (-e) {
126 + push @files, $_;
127 + } else {
128 + push @rev_args, $_;
129 + }
130 +}
131 +
132 +my %commits;
133 +for (@files) {
134 scan_patch_file(\%commits, $_);
135 }
136 +if (@rev_args) {
137 + scan_rev_args(\%commits, \@rev_args)
138 +}
139 import_commits(\%commits);
140
141 my $contacts = {};