LinuxカーネルHack: git blameとその応用

svn blameは日常良く使うけど、gitでも同じことができるか調べたら、やっぱりできた。git blameで。git blameは、横幅かなり取るなぁ。

% git blame mm/oom_kill.c
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700   1) /*
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700   2)  *  linux/mm/oom_kill.c
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700   3)  *
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700   4)  *  Copyright (C)  1998,2000  Rik van Riel
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700   5)  *   Thanks go out to Claus Fischer for some serious inspiration and
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700   6)  *   for goading me into coding this file...
a63d83f4 (David Rientjes            2010-08-09 17:19:46 -0700   7)  *  Copyright (C)  2010  Google, Inc.
a63d83f4 (David Rientjes            2010-08-09 17:19:46 -0700   8)  *   Rewritten by David Rientjes
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700   9)  *
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  10)  *  The routines in this file are used to kill a process when
a49335cc (Paul Jackson              2005-09-06 15:18:09 -0700  11)  *  we're seriously out of memory. This gets called from __alloc_pages()
a49335cc (Paul Jackson              2005-09-06 15:18:09 -0700  12)  *  in mm/page_alloc.c when we really run out of memory.
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  13)  *
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  14)  *  Since we won't call these routines often (on a well-configured
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  15)  *  machine) this file will double as a 'coding guide' and a signpost
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  16)  *  for newbie kernel hackers. It features several pointers to major
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  17)  *  kernel subsystems and hints as to where to find out what things do.
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  18)  */
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  19)
8ac773b4 (Alexey Dobriyan           2006-10-19 23:28:32 -0700  20) #include <linux/oom.h>
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  21) #include <linux/mm.h>
4e950f6f (Alexey Dobriyan           2007-07-30 02:36:13 +0400  22) #include <linux/err.h>
5a0e3ad6 (Tejun Heo                 2010-03-24 17:04:11 +0900  23) #include <linux/gfp.h>
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  24) #include <linux/sched.h>
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  25) #include <linux/swap.h>
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  26) #include <linux/timex.h>
^1da177e (Linus Torvalds            2005-04-16 15:20:36 -0700  27) #include <linux/jiffies.h>
ef08e3b4 (Paul Jackson              2005-09-06 15:18:13 -0700  28) #include <linux/cpuset.h>
8bc719d3 (Martin Schwidefsky        2006-09-25 23:31:20 -0700  29) #include <linux/module.h>
8bc719d3 (Martin Schwidefsky        2006-09-25 23:31:20 -0700  30) #include <linux/notifier.h>
c7ba5c9e (Pavel Emelianov           2008-02-07 00:13:58 -0800  31) #include <linux/memcontrol.h>
6f48d0eb (David Rientjes            2010-08-09 17:18:52 -0700  32) #include <linux/mempolicy.h>
5cd9c58f (David Howells             2008-08-14 11:37:28 +0100  33) #include <linux/security.h>
[...]

応用として、mm/oom_kill.cに誰が書いたコードがどれくらい(行数)生きているのか、ワンライナーを書いて調べてみた。KOSAKIさんのコードが結構入ってる。同じく日本人のKAMEZAWA Hiroyukiさんのコードも。

% git blame mm/oom_kill.c | perl -ne 'print "$1\n" if /^.+? \((.+?) \d{4}/' | sort | uniq -c | sort -nr
    373 David Rientjes
     88 Linus Torvalds
     58 KOSAKI Motohiro
     31 Nick Piggin
     31 Luis Claudio R. Goncalves
     26 KAMEZAWA Hiroyuki
     24 Oleg Nesterov
     22 Martin Schwidefsky
     21 Mel Gorman
     15 Christoph Lameter
     14 Pavel Emelianov
      9 Paul Jackson
      5 Randy Dunlap
      3 Dave Peterson
      2 Minchan Kim
      2 Li Zefan
      2 Kurt Garloff
      2 Daisuke Nishimura
      2 Andrew Morton
      2 Alexey Dobriyan
      1 Tejun Heo
      1 Kirill Korotaev
      1 David Howells
      1 Balbir Singh