{"thread":{"id":"5841","subject":"[PATCH] add commit count options to git-shortlog","startedAt":"2006-10-06T19:39:09Z","lastAt":"2006-10-10T02:45:48Z","messageCount":3,"participants":["Nicolas Pitre","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"28325","messageId":"Pine.LNX.4.64.0610061520020.2435@xanadu.home","threadId":"5841","inReplyTo":null,"subject":"[PATCH] add commit count options to git-shortlog","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2006-10-06T19:39:09Z","receivedAt":"2006-10-06T19:39:09Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"This patch does 3 things:\n\n1) Output the number of commits along with the name for each author \n   (nice to know for long lists spending more than a screen worth of \n   commit lines).\n\n2) Provide a switch (-n) to sort authors according to their number of \n   commits instead of author alphabetic order.\n\n3) Provide a switch (-s) to supress commit lines and only keep a \n   summary of authors and the number of commits for each of them.\n\nAnd for good measure a short usage is displayed with -h.  \n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n\n---\n\nI'm far from a Perl expert.  I just hope that Perl gurus out there won't \nthrow up too badly.\n\nWith this it is possible to have nice statistics quickly, and \ndemonstrate that Junio is really our King.  ;-)\n\ndiff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt\nindex 7486ebe..1601d22 100644\n--- a/Documentation/git-shortlog.txt\n+++ b/Documentation/git-shortlog.txt\n@@ -7,16 +7,29 @@ git-shortlog - Summarize 'git log' outpu\n \n SYNOPSIS\n --------\n-git-log --pretty=short | 'git-shortlog'\n+git-log --pretty=short | 'git-shortlog' [-h] [-n] [-s]\n \n DESCRIPTION\n -----------\n Summarizes 'git log' output in a format suitable for inclusion\n-in release announcements. Each commit will be grouped by author\n+in release announcements. Each commit will be grouped by author and\n the first line of the commit message will be shown.\n \n Additionally, \"[PATCH]\" will be stripped from the commit description.\n \n+OPTIONS\n+-------\n+\n+-h::\n+\tPrint a short usage message and exit.\n+\n+-n::\n+\tSort output according to the number of commits per author instead\n+\tof author alphabetic order.\n+\n+-s:\n+\tSupress commit description and Provide a commit count summary only.\n+\n FILES\n -----\n '.mailmap'::\ndiff --git a/git-shortlog.perl b/git-shortlog.perl\nindex 0b14f83..138c4c5 100755\n--- a/git-shortlog.perl\n+++ b/git-shortlog.perl\n@@ -1,6 +1,18 @@\n #!/usr/bin/perl -w\n \n use strict;\n+use Getopt::Std;\n+use File::Basename qw(basename dirname);\n+\n+our ($opt_h, $opt_n, $opt_s);\n+getopts('hns');\n+\n+$opt_h && usage();\n+\n+sub usage {\n+\tprint STDERR \"Usage: ${\\basename $0} [-h] [-n] [-s] < <log_data>\\n\";\n+        exit(1);\n+}\n \n my (%mailmap);\n my (%email);\n@@ -38,16 +50,37 @@ sub by_name($$) {\n \n \tuc($a) cmp uc($b);\n }\n+sub by_nbentries($$) {\n+\tmy ($a, $b) = @_;\n+\tmy $a_entries = $map{$a};\n+\tmy $b_entries = $map{$b};\n+\n+\t@$b_entries - @$a_entries || by_name $a, $b;\n+}\n+\n+my $sort_method = $opt_n ? \\&by_nbentries : \\&by_name;\n+\n+sub summary_output {\n+\tmy ($obj, $num, $key);\n+\n+\tforeach $key (sort $sort_method keys %map) {\n+\t\t$obj = $map{$key};\n+\t\t$num = @$obj;\n+\t\tprintf \"%s: %u\\n\", $key, $num;\n+\t}\n+}\n \n sub shortlog_output {\n-\tmy ($obj, $key, $desc);\n+\tmy ($obj, $num, $key, $desc);\n+\n+\tforeach $key (sort $sort_method keys %map) {\n+\t\t$obj = $map{$key};\n+\t\t$num = @$obj;\n \n-\tforeach $key (sort by_name keys %map) {\n \t\t# output author\n-\t\tprintf \"%s:\\n\", $key;\n+\t\tprintf \"%s (%u):\\n\", $key, $num;\n \n \t\t# output author's 1-line summaries\n-\t\t$obj = $map{$key};\n \t\tforeach $desc (reverse @$obj) {\n \t\t\tprint \"  $desc\\n\";\n \t\t\t$n_output++;\n@@ -152,7 +185,7 @@ sub finalize {\n \n &setup_mailmap;\n &changelog_input;\n-&shortlog_output;\n+$opt_s ? &summary_output : &shortlog_output;\n &finalize;\n exit(0);\n \n"},{"id":"28347","messageId":"7vodsotqqd.fsf@assigned-by-dhcp.cox.net","threadId":"5841","inReplyTo":"Pine.LNX.4.64.0610061520020.2435@xanadu.home","subject":"Re: [PATCH] add commit count options to git-shortlog","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-10-07T09:33:30Z","receivedAt":"2006-10-07T09:33:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nicolas Pitre <nico@cam.org> writes:\n\n> This patch does 3 things:\n>...\n> Signed-off-by: Nicolas Pitre <nico@cam.org>\n>\n> ---\n>\n> I'm far from a Perl expert.  I just hope that Perl gurus out there won't \n> throw up too badly.\n>\n> With this it is possible to have nice statistics quickly, and \n> demonstrate that Junio is really our King.  ;-)\n\nI only talk passable Perl but I did not find much objectionable\nstuff there.  But I am not sure how this is useful aside from\nstroking your own ego.\n\nAlso I get the following.\n\n$ git log --pretty=short v1.4.2..abd6970 |\n  perl ./git-shortlog.perl -n -s >/dev/null\nparse error: input records != output records\n"},{"id":"28481","messageId":"Pine.LNX.4.64.0610092222030.2435@xanadu.home","threadId":"5841","inReplyTo":"7vodsotqqd.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] add commit count options to git-shortlog","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2006-10-10T02:45:48Z","receivedAt":"2006-10-10T02:45:48Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"On Sat, 7 Oct 2006, Junio C Hamano wrote:\n\n> Nicolas Pitre <nico@cam.org> writes:\n> \n> > This patch does 3 things:\n> >...\n> > Signed-off-by: Nicolas Pitre <nico@cam.org>\n> >\n> > ---\n> >\n> > I'm far from a Perl expert.  I just hope that Perl gurus out there won't \n> > throw up too badly.\n> >\n> > With this it is possible to have nice statistics quickly, and \n> > demonstrate that Junio is really our King.  ;-)\n> \n> I only talk passable Perl but I did not find much objectionable\n> stuff there.  But I am not sure how this is useful aside from\n> stroking your own ego.\n\nWhile stroking your own ego might sometimes be a good thing (hackers \nare in it for free because they have some pride back), I think it is \nmost interesting for the pure statistic values.  It is often nice to \nknow who the main contributors are and by what margin, or to have a look \nat the contribution spectrum to have a feel of participation to a given \nproject.\n\nLinus recently wanted to know the opinion of an arbitrary number of top \ndevelopers to the Linux kernel.  He used a criteria to determine who \nthose developers were which was based on amount of sign-off lines, but \nthe number of pure contribution is otherwise the metric that most \nprojects are likely to be interested in.\n\nOh, and BitKeeper had that feature.\n\n> Also I get the following.\n> \n> $ git log --pretty=short v1.4.2..abd6970 |\n>   perl ./git-shortlog.perl -n -s >/dev/null\n> parse error: input records != output records\n\nPlease find new patch below (only one line added) with that issue fixed.\n\ndiff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt\nindex 7486ebe..1601d22 100644\n--- a/Documentation/git-shortlog.txt\n+++ b/Documentation/git-shortlog.txt\n@@ -7,16 +7,29 @@ git-shortlog - Summarize 'git log' outpu\n \n SYNOPSIS\n --------\n-git-log --pretty=short | 'git-shortlog'\n+git-log --pretty=short | 'git-shortlog' [-h] [-n] [-s]\n \n DESCRIPTION\n -----------\n Summarizes 'git log' output in a format suitable for inclusion\n-in release announcements. Each commit will be grouped by author\n+in release announcements. Each commit will be grouped by author and\n the first line of the commit message will be shown.\n \n Additionally, \"[PATCH]\" will be stripped from the commit description.\n \n+OPTIONS\n+-------\n+\n+-h::\n+\tPrint a short usage message and exit.\n+\n+-n::\n+\tSort output according to the number of commits per author instead\n+\tof author alphabetic order.\n+\n+-s:\n+\tSupress commit description and Provide a commit count summary only.\n+\n FILES\n -----\n '.mailmap'::\ndiff --git a/git-shortlog.perl b/git-shortlog.perl\nindex 0b14f83..334fec7 100755\n--- a/git-shortlog.perl\n+++ b/git-shortlog.perl\n@@ -1,6 +1,18 @@\n #!/usr/bin/perl -w\n \n use strict;\n+use Getopt::Std;\n+use File::Basename qw(basename dirname);\n+\n+our ($opt_h, $opt_n, $opt_s);\n+getopts('hns');\n+\n+$opt_h && usage();\n+\n+sub usage {\n+\tprint STDERR \"Usage: ${\\basename $0} [-h] [-n] [-s] < <log_data>\\n\";\n+        exit(1);\n+}\n \n my (%mailmap);\n my (%email);\n@@ -38,16 +50,38 @@ sub by_name($$) {\n \n \tuc($a) cmp uc($b);\n }\n+sub by_nbentries($$) {\n+\tmy ($a, $b) = @_;\n+\tmy $a_entries = $map{$a};\n+\tmy $b_entries = $map{$b};\n+\n+\t@$b_entries - @$a_entries || by_name $a, $b;\n+}\n+\n+my $sort_method = $opt_n ? \\&by_nbentries : \\&by_name;\n+\n+sub summary_output {\n+\tmy ($obj, $num, $key);\n+\n+\tforeach $key (sort $sort_method keys %map) {\n+\t\t$obj = $map{$key};\n+\t\t$num = @$obj;\n+\t\tprintf \"%s: %u\\n\", $key, $num;\n+\t\t$n_output += $num;\n+\t}\n+}\n \n sub shortlog_output {\n-\tmy ($obj, $key, $desc);\n+\tmy ($obj, $num, $key, $desc);\n+\n+\tforeach $key (sort $sort_method keys %map) {\n+\t\t$obj = $map{$key};\n+\t\t$num = @$obj;\n \n-\tforeach $key (sort by_name keys %map) {\n \t\t# output author\n-\t\tprintf \"%s:\\n\", $key;\n+\t\tprintf \"%s (%u):\\n\", $key, $num;\n \n \t\t# output author's 1-line summaries\n-\t\t$obj = $map{$key};\n \t\tforeach $desc (reverse @$obj) {\n \t\t\tprint \"  $desc\\n\";\n \t\t\t$n_output++;\n@@ -152,7 +186,7 @@ sub finalize {\n \n &setup_mailmap;\n &changelog_input;\n-&shortlog_output;\n+$opt_s ? &summary_output : &shortlog_output;\n &finalize;\n exit(0);\n \n"}]}