git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] Add Author and Documentation sections to git-for-each-ref.txt

From
Jeff King <peff@peff.net>
Date
Mar 17, 2011, 19:34 UTC
Message-ID
<20110317193450.GD20508@sigill.intra.peff.net>
In-Reply-To
<1300371608.16335.1.camel@wpalmer.simply-domain>
On Thu, Mar 17, 2011 at 02:20:08PM +0000, Will Palmer wrote:
Show 11 quoted lines
> On Wed, 2011-03-09 at 14:14 +0200, Alexei Sholik wrote:
> > .................. Just ran this command
> > 
> > git blame -p "$1" | awk '$1 ~ /author$/ { print substr($0,
> > length("author  "), length($0)) }' | sort | uniq -c | sort -nr
> > 
> > on the for-each-ref.c and saw that Junio had the first place by a
> > relatively large margin.
> > 
> 
> Wrap that up in a script and submit /that/ as a patch ;)

That just counts the number of commits that have any surviving line in a given file. So it's slightly better than "shortlog -ns" in that it removes commits whose contents have been totally rewritten (and it properly handles content-following). But if you are going to use blame, the more interesting measure is probably a count of lines attributed to each author. Something like:

  git blame -p "$1" | perl -ne '
    if (/^([0-9a-f]{40})/) {
      $sha1 = $1;
      $count{$sha1}++;
    }
    elsif (/^author (.*)/) {
      $author{$sha1} = $1;
    }
    END {
      foreach my $sha1 (keys(%count)) {
        $r{$author{$sha1}} += $count{$sha1};
      }
      foreach my $a (sort { $r{$b} <=> $r{$a} } keys(%r)) {
        print "$r{$a} $a\n";
      }
    }
  '
-Peff
Previous: Will PalmerNext: Alexei Sholik
Message 8 of 24 in “A couple of tweaks in git-for-each-ref.txt”
  1. 0/2 A couple of tweaks in git-for-each-ref.txtAlexei Sholik, Mar 8, 2011
  2. 1/2 Documentation: remove redundant colons in git-for-each-ref.txtAlexei Sholik, Mar 8, 2011
  3. Michael J GruberMar 9, 2011
  4. 2/2 Add Author and Documentation sections to git-for-each-ref.txtAlexei Sholik, Mar 8, 2011
  5. Michael J GruberMar 9, 2011
  6. Alexei SholikMar 9, 2011
  7. Will PalmerMar 17, 2011
  8. Jeff KingMar 17, 2011
  9. Alexei SholikMar 17, 2011
  10. Jeff KingMar 17, 2011
  11. Alexei SholikMar 17, 2011
  12. Junio C HamanoMar 9, 2011
  13. Jeff KingMar 10, 2011
  14. Junio C HamanoMar 10, 2011
  15. Jeff KingMar 11, 2011
  16. Junio C HamanoMar 11, 2011
  17. Alexei SholikMar 12, 2011
  18. Jeff KingMar 13, 2011
  19. Junio C HamanoMar 13, 2011
  20. Jeff KingMar 13, 2011
  21. Junio C HamanoMar 13, 2011
  22. Michael J GruberMar 13, 2011
  23. Jeff KingMar 17, 2011
  24. Junio C HamanoMar 9, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.