Created
January 30, 2015 11:49
-
-
Save taka2/591211b279563af6010d to your computer and use it in GitHub Desktop.
職人は道具から作り始める - 必要な道具を手早く作りこんでいくワークショップ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 最近10件のコミットから、変更行数の多い順にファイル名を表示する | |
// 一番目の引数を取得 | |
arg = args[0] | |
// 引数で指定されたディレクトリでgitコマンドを実行 | |
def p = 'git log -10 --numstat --pretty=%s'.execute([], new File(arg)) | |
p.waitFor() | |
// コマンドを実行した結果を取得して、ファイル名ごとに変更行数を集計 | |
def map = new HashMap(); | |
p.text.eachLine { | |
if(it ==~ /\d+\t\d+.*/) { | |
def splitted = it.split('\t') | |
def added = Integer.valueOf(splitted[0]) | |
def deleted = Integer.valueOf(splitted[1]) | |
def changed = added + deleted | |
def filename = splitted[2] | |
if(map.containsKey(filename)) { | |
map.put(filename, map.get(filename) + changed) | |
} else { | |
map.put(filename, changed) | |
} | |
} | |
} | |
// 変更行数の降順にソートして表示 | |
map.sort { | |
it.value * -1 | |
}.each { | |
println it | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment