Graphlog で頭をスッキリしよう

posted by Steve Losh on October 3, 2009

hg log は、 Mercurial を始めたばかりの時にまず覚えるコマンドのひとつです。 このコマンドはリポジトリに対する全コミットの記録を見せてくれます。 コマンドの出力はこんな風です:

$ hg log
チェンジセット:   2:7b393734ccf7
タグ:             tip
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:42:13 2009 -0400
要約:             Do some more work.

チェンジセット:   1:26ac605206b4
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:42:08 2009 -0400
要約:             Do some work.

チェンジセット:   0:ef4afb3d9699
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:42:00 2009 -0400
要約:             Initial commit.

$

悪くないね! 変更が枝分かれせず(ブランチを切らず)一直線に並んでいればこれで OK です。 しかし、一度枝分かれしてしまうと、読むに耐えなくなってしまいます。 先ほどの続きで 2、3 コミットした後の出力を見てみましょう:

$ hg log
チェンジセット:   8:b58f37a6f0af
タグ:             tip
親:               3:fee36cf81486
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:48:55 2009 -0400
要約:             Oh god the server is on fire fix it now.

チェンジセット:   7:8f54b4d0d885
親:               5:ce29b9e5288f
親:               6:1dff6084cda4
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:48:20 2009 -0400
要約:             Go back to the old wording.

チェンジセット:   6:1dff6084cda4
親:               4:3c52ba0b77af
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:47:23 2009 -0400
要約:             Actually, the wording was fine.

チェンジセット:   5:ce29b9e5288f
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:46:21 2009 -0400
要約:             Add some content.

チェンジセット:   4:3c52ba0b77af
親:               2:7b393734ccf7
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:46:04 2009 -0400
要約:             Change some wording around.

チェンジセット:   3:fee36cf81486
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:45:50 2009 -0400
要約:             Fix a horrific bug.

チェンジセット:   2:7b393734ccf7
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:42:13 2009 -0400
要約:             Do some more work.

チェンジセット:   1:26ac605206b4
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:42:08 2009 -0400
要約:             Do some work.

チェンジセット:   0:ef4afb3d9699
ユーザ:           Steve Losh <steve@stevelosh.com>
日付:             Fri Oct 02 23:42:00 2009 -0400
要約:             Initial commit.

$

さて、今度は何が起きているのかパッと見で理解するのは簡単でありません。 少なくとも 1 回マージしている(チェンジセット 7 に親が 2 つあるから)ということは、 どこかにブランチがあるはずです。ブランチがどれか一目で見つけられますか? 見つけようとするけどイラッと来て終わりですよね。

ログを分かりやすくするには、次のように ~/.hgrc ファイルを編集して graphlog エクステンション を有効にします:

[extensions]
graphlog =

さぁ、 hg glogASCII アートなグラフログを表示できるようになりました:

$ hg glog
@  チェンジセット:   8:b58f37a6f0af
|  タグ:             tip
|  親:               3:fee36cf81486
|  ユーザ:           Steve Losh <steve@stevelosh.com>
|  日付:             Fri Oct 02 23:48:55 2009 -0400
|  要約:             Oh god the server is on fire fix it now.
|
| o    チェンジセット:   7:8f54b4d0d885
| |\   親:               5:ce29b9e5288f
| | |  親:               6:1dff6084cda4
| | |  ユーザ:           Steve Losh <steve@stevelosh.com>
| | |  日付:             Fri Oct 02 23:48:20 2009 -0400
| | |  要約:             Go back to the old wording.
| | |
| | o  チェンジセット:   6:1dff6084cda4
| | |  親:               4:3c52ba0b77af
| | |  ユーザ:           Steve Losh <steve@stevelosh.com>
| | |  日付:             Fri Oct 02 23:47:23 2009 -0400
| | |  要約:             Actually, the wording was fine.
| | |
| o |  チェンジセット:   5:ce29b9e5288f
| |/   ユーザ:           Steve Losh <steve@stevelosh.com>
| |    日付:             Fri Oct 02 23:46:21 2009 -0400
| |    要約:             Add some content.
| |
| o  チェンジセット:   4:3c52ba0b77af
| |  親:               2:7b393734ccf7
| |  ユーザ:           Steve Losh <steve@stevelosh.com>
| |  日付:             Fri Oct 02 23:46:04 2009 -0400
| |  要約:             Change some wording around.
| |
o |  チェンジセット:   3:fee36cf81486
|/   ユーザ:           Steve Losh <steve@stevelosh.com>
|    日付:             Fri Oct 02 23:45:50 2009 -0400
|    要約:             Fix a horrific bug.
|
o  チェンジセット:   2:7b393734ccf7
|  ユーザ:           Steve Losh <steve@stevelosh.com>
|  日付:             Fri Oct 02 23:42:13 2009 -0400
|  要約:             Do some more work.
|
o  チェンジセット:   1:26ac605206b4
|  ユーザ:           Steve Losh <steve@stevelosh.com>
|  日付:             Fri Oct 02 23:42:08 2009 -0400
|  要約:             Do some work.
|
o  チェンジセット:   0:ef4afb3d9699
   ユーザ:           Steve Losh <steve@stevelosh.com>
   日付:             Fri Oct 02 23:42:00 2009 -0400
   要約:             Initial commit.

$

これでブランチの分岐点は一目瞭然です。

個人的には、 hg glog の出力はもう少しコンパクトな方がいいと思っています。 たいていの場合、各コミットの詳細はほとんど必要ないですから。 私は ~/.hgrc ファイルを編集して、次のようにしています:

[defaults]
glog = --template 'チェンジセット:   {rev}:{node|short} {tags}\n要約:             {desc|firstline|fill68|tabindent|tabindent}\n\n'

このテンプレートをデフォルトに指定したことで、 hg glog の出力はこんな風になりました:

$ hg glog
@  チェンジセット:   8:b58f37a6f0af tip 
|  要約:             Oh god the server is on fire fix it now.
|
| o    チェンジセット:   7:8f54b4d0d885  
| |\   要約:             Go back to the old wording.
| | |
| | o  チェンジセット:   6:1dff6084cda4  
| | |  要約:             Actually, the wording was fine.
| | |
| o |  チェンジセット:   5:ce29b9e5288f  
| |/   要約:             Add some content.
| |
| o  チェンジセット:   4:3c52ba0b77af  
| |  要約:             Change some wording around.
| |
o |  チェンジセット:   3:fee36cf81486  
|/   要約:             Fix a horrific bug.
|
o  チェンジセット:   2:7b393734ccf7  
|  要約:             Do some more work.
|
o  チェンジセット:   1:26ac605206b4  
|  要約:             Do some work.
|
o  チェンジセット:   0:ef4afb3d9699  
   要約:             Initial commit.

$

私としてはこの方がずっと見やすく、かつ必要十分な情報を提示しています。 特定のチェンジセットについて詳しく知りたければ、 hg log -r REV または hg show REV を使えば良いのです。

hg log は使えます。ただし、ブランチができるとぐちゃぐちゃに。 Graphlog があなたの見方です。