add commit count options to git-shortlog
This patch does 3 things: 1) Output the number of commits along with the name for each author (nice to know for long lists spending more than a screen worth of commit lines). 2) Provide a switch (-n) to sort authors according to their number of commits instead of author alphabetic order. 3) Provide a switch (-s) to supress commit lines and only keep a summary of authors and the number of commits for each of them. And for good measure a short usage is displayed with -h. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nicolas Pitre committed
Oct 6, 2006 at 15:39 UTC
4e27fb06f0fe4206606172f94a18e08d7d87c070
2 files changed
+54
-7
Documentation/git-shortlog.txt
+15
-2
@@ -7,16 +7,29 @@ git-shortlog - Summarize 'git log' output
7
8
SYNOPSIS
9
--------
10
-git-log --pretty=short | 'git-shortlog'
10
+git-log --pretty=short | 'git-shortlog' [-h] [-n] [-s]
11
12
DESCRIPTION
13
-----------
14
Summarizes 'git log' output in a format suitable for inclusion
15
-in release announcements. Each commit will be grouped by author
15
+in release announcements. Each commit will be grouped by author and
16
the first line of the commit message will be shown.
17
18
Additionally, "[PATCH]" will be stripped from the commit description.
19
20
+OPTIONS
21
+-------
22
+
23
+-h::
24
+ Print a short usage message and exit.
25
+
26
+-n::
27
+ Sort output according to the number of commits per author instead
28
+ of author alphabetic order.
29
+
30
+-s:
31
+ Supress commit description and Provide a commit count summary only.
32
+
33
FILES
34
-----
35
'.mailmap'::
git-shortlog.perl
+39
-5
@@ -1,6 +1,18 @@
1
#!/usr/bin/perl -w
2
3
use strict;
4
+use Getopt::Std;
5
+use File::Basename qw(basename dirname);
6
+
7
+our ($opt_h, $opt_n, $opt_s);
8
+getopts('hns');
9
+
10
+$opt_h && usage();
11
+
12
+sub usage {
13
+ print STDERR "Usage: ${\basename $0} [-h] [-n] [-s] < <log_data>\n";
14
+ exit(1);
15
+}
16
17
my (%mailmap);
18
my (%email);
@@ -38,16 +50,38 @@ sub by_name($$) {
50
51
uc($a) cmp uc($b);
52
}
53
+sub by_nbentries($$) {
54
+ my ($a, $b) = @_;
55
+ my $a_entries = $map{$a};
56
+ my $b_entries = $map{$b};
57
+
58
+ @$b_entries - @$a_entries || by_name $a, $b;
59
+}
60
+
61
+my $sort_method = $opt_n ? \&by_nbentries : \&by_name;
62
+
63
+sub summary_output {
64
+ my ($obj, $num, $key);
65
+
66
+ foreach $key (sort $sort_method keys %map) {
67
+ $obj = $map{$key};
68
+ $num = @$obj;
69
+ printf "%s: %u\n", $key, $num;
70
+ $n_output += $num;
71
+ }
72
+}
73
74
sub shortlog_output {
43
- my ($obj, $key, $desc);
75
+ my ($obj, $num, $key, $desc);
76
+
77
+ foreach $key (sort $sort_method keys %map) {
78
+ $obj = $map{$key};
79
+ $num = @$obj;
80
45
- foreach $key (sort by_name keys %map) {
81
# output author
47
- printf "%s:\n", $key;
82
+ printf "%s (%u):\n", $key, $num;
83
84
# output author's 1-line summaries
50
- $obj = $map{$key};
85
foreach $desc (reverse @$obj) {
86
print " $desc\n";
87
$n_output++;
@@ -152,7 +186,7 @@ sub finalize {
186
187
&setup_mailmap;
188
&changelog_input;
155
-&shortlog_output;
189
+$opt_s ? &summary_output : &shortlog_output;
190
&finalize;
191
exit(0);
192