17
17
# <http://www.gnu.org/licenses/>.
18
18
#
19
19
#
20
- # gitblame [--p4] [--prefix path] [domain] pathname
20
+ # gitblame [--p4] [--prefix path] [--abbrev regexp] [ domain] pathname
21
21
#
22
22
# This script runs "git blame" for the specified file and formats the result
23
23
# to match the diffcov(1) age/ownership annotation specification.
33
33
# If passed a domain name (or domain regexp):
34
34
# strip that domain from the author's address, and treat all users outside
35
35
# the matching domain as "External".
36
+ # The --abbrev argument enables you to specify one or more regexp patterns
37
+ # which are used to compute the user name abbreviation that are applied.
36
38
37
39
package gitblame ;
38
40
use strict;
@@ -47,7 +49,7 @@ our @EXPORT_OK = qw(new);
47
49
48
50
use constant {
49
51
P4 => 0,
50
- DOMAIN => 1,
52
+ ABBREV => 1,
51
53
PREFIX => 2,
52
54
};
53
55
@@ -59,21 +61,27 @@ sub new
59
61
my $mapP4 ;
60
62
my $prefix ;
61
63
my @args = @_ ;
62
-
64
+ my @abbrev ;
63
65
if (!GetOptionsFromArray(\@_ ,
64
66
(" p4" => \$mapP4 ,
65
- " prefix:s" => \$prefix )
67
+ " prefix:s" => \$prefix ,
68
+ ' abbrev:s' => \@abbrev )
66
69
)) {
67
70
my $exe = basename($script ? $script : $0 );
68
- print (STDERR " usage: $exe [--p4] [domain] pathname\n " );
71
+ print (STDERR
72
+ " usage: $exe [--p4] [--abbrev regexp]* [domain] pathname\n " );
69
73
exit (1) if ($script eq $0 );
70
74
return undef ;
71
75
}
72
-
73
76
my $internal_domain = shift ;
77
+ if ($internal_domain ) {
78
+ push (@abbrev , ' s/^([^@]+)\@' . $internal_domain . ' $/$1/' );
79
+ push (@abbrev , ' s/^([^@]+)\@.+$/External/' );
80
+ # else leave domain in place
81
+ }
74
82
my @prefix ;
75
83
push (@prefix , $prefix ) if $prefix ;
76
- my $self = [$mapP4 , $internal_domain , \@prefix ];
84
+ my $self = [$mapP4 , \ @abbrev , \@prefix ];
77
85
return bless $self , $class ;
78
86
}
79
87
@@ -109,6 +117,7 @@ sub annotate
109
117
open (HANDLE, " -|" ,
110
118
" cd $dir ; git blame -e $basename 2> /dev/null" )
111
119
) {
120
+ my %abbrev ; # user name abbreviations
112
121
while (my $line = <HANDLE>) {
113
122
chomp $line ;
114
123
# Also remove CR from line-end
@@ -152,14 +161,18 @@ sub annotate
152
161
$owner =~ s / at / \@ / ;
153
162
my $fullname = $owner ;
154
163
155
- if ($self -> [DOMAIN]) {
156
- # # strip domain part for internal users...
157
- $owner =~ s /\@ $self->[DOMAIN]// ;
158
- # replace everybody else with "External"
159
- $owner =~ s / .*\@ .*/ External/ ;
164
+ if (exists ($abbrev {$fullname })) {
165
+ $owner = $abbrev {$fullname };
166
+ } else {
167
+ # compute only once...
168
+ foreach my $re (@{$self -> [ABBREV]}) {
169
+ # # strip domain part for internal users...
170
+ eval ' $owner =~ ' . $re . ' ;' ;
171
+ die (" invalid domain pattern '$re ': $@ " )
172
+ if $@ ;
173
+ }
174
+ $abbrev {$fullname } = $owner ;
160
175
}
161
- # else leave domain in place
162
-
163
176
# Convert Git date/time to diffcov canonical format
164
177
# replace space between date and time with 'T'
165
178
$when =~ s /\s / T/ ;
0 commit comments