{"thread":{"id":"825","subject":"'shortlog' script for git","startedAt":"2005-06-04T05:49:37Z","lastAt":"2005-06-04T05:49:37Z","messageCount":1,"participants":["Jeff Garzik"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"4525","messageId":"42A140F1.5070707@pobox.com","threadId":"825","inReplyTo":null,"subject":"'shortlog' script for git","fromName":"Jeff Garzik","fromEmail":"jgarzik@pobox.com","sentAt":"2005-06-04T05:49:37Z","receivedAt":"2005-06-04T05:49:37Z","isPatch":false,"sender":{"key":"jgarzik@pobox.com","avatar":null},"body":"\nI've been wanting a shortlog script for summarizing my kernel \nsubmissions to Linus for a while.  This is now written, and the results \nare attached.  Simply use like\n\n\tgit-shortlog < changes.txt\n\t\tor\n\tgit-shortlog changes.txt\n\nThe changeset format the Perl script parses is that of\nhttp://www.kernel.org/pub/linux/kernel/people/jgarzik/git-changes-script\n\nI'll change it to parse the git-whatchanged output format sometime soon; \nLinus hates it when I use git-changes-script since he thinks its ugly :)\n\n\tJeff\n\n\n\n\n\n#!/usr/bin/perl -w\n\nuse strict;\n\nmy ($author, $desc, %map);\nmy $pstate = 1;\n\nwhile (<>) {\n\t# skip to '^commit '\n\tif ($pstate == 1) {\n\t\tnext unless /^commit /;\n\t\t$pstate++;\n\t}\n\n\t# get author\n\telsif ($pstate == 2) {\n\t\tnext unless /^author (.*) \\S+ \\S+ \\S+ \\S+ \\S+ \\S+\\s*$/;\n\t\t$author = $1;\n\t\t$pstate++;\n\t}\n\n\t# skip to blank line\n\telsif ($pstate == 3) {\n\t\tnext unless /^\\s*$/;\n\t\t$pstate++;\n\t}\n\n\t# skip to non-blank line\n\telsif ($pstate == 4) {\n\t\tnext if /^\\s*$/;\n\t\tchomp;\n\t\t$desc = $_;\n\n\t\t&shortlog_entry($author, $desc);\n\n\t\t$pstate = 1;\n\t}\n\n\telse {\n\t\tdie \"invalid parse state $pstate\";\n\t}\n}\n\n&shortlog_output;\nexit(0);\n\n\nsub shortlog_entry($$) {\n\tmy ($tmp_author, $tmp_desc) = @_;\n\tmy ($obj);\n\n\t$tmp_desc =~ s#/pub/scm/linux/kernel/git/#/.../#g;\n\t$tmp_desc =~ s/^\\[PATCH] //g;\n\t$tmp_desc =~ s/^\\s+//g;\n\n\tif (exists $map{$tmp_author}) {\n\t\t# grab ref\n\t\t$obj = $map{$tmp_author};\n\n\t\t# add desc to array\n\t\tpush(@$obj, $tmp_desc);\n\t} else {\n\t\t# create ref to new array\n\t\tmy @arr = ($tmp_desc);\n\t\t$obj = \\@arr;\n\n\t\t# store new entry in author map\n\t\t$map{$tmp_author} = $obj;\n\t}\n}\n\nsub shortlog_output {\n\tmy ($obj);\n\n\tforeach $author (sort keys %map) {\n\t\tprint \"$author:\\n\";\n\n\t\t$obj = $map{$author};\n\t\tforeach $desc (@$obj) {\n\t\t\tprint \"  $desc\\n\";\n\t\t}\n\n\t\tprint \"\\n\";\n\t}\n}\n\n"}]}