Chapter 11
Customising the output of Mercurial

Mercurial 報表するみをしていますこのみはテンプレづいておりテンプレ使することでコマンド Mercurial みのウェブインタフェかけ全体カスタマイズもできま

11.1 Using precanned output styles

Mercurial には使できるつかがされています。「とはかによってかれてMercurial かにインストされたされたテンプレのことです

Mercurial されたMercurial てみましょう

1  $ hg log -r1
2  changeset:   1:1f5a344665d8
3  tag:         mytag
4  user:        Bryan O’Sullivan <bos@serpentine.com>
5  date:        Mon Jul 20 21:48:34 2009 +0000
6  summary:     added line to end of <<hello>> file.
7  

このではありますがチェンジセットというくのですcompact くことでこのします

1  $ hg log --style compact
2  3[tip]   2677318af26d   2009-07-20 21:48 +0000   bos
3    Added tag v0.1 for changeset 8899b18d5d72
4  
5  2[v0.1]   8899b18d5d72   2009-07-20 21:48 +0000   bos
6    Added tag mytag for changeset 1f5a344665d8
7  
8  1[mytag]   1f5a344665d8   2009-07-20 21:48 +0000   bos
9    added line to end of <<hello>> file.
10  
11  0   cd0d035975cb   2009-07-20 21:48 +0000   bos
12    added hello
13  

changelog からはMercurial テンプレトエンジン垣間ることができますこのGNU プロジェクト changelog ガイドライン[RS]沿ったいます

1  $ hg log --style changelog
2  2009-07-20  Bryan O’Sullivan  <bos@serpentine.com>
3  
4   * .hgtags:
5   Added tag v0.1 for changeset 8899b18d5d72
6   [2677318af26d] [tip]
7  
8   * .hgtags:
9   Added tag mytag for changeset 1f5a344665d8
10   [8899b18d5d72] [v0.1]
11  
12   * goodbye, hello:
13   added line to end of <<hello>> file.
14  
15   in addition, added a file with the helpful name (at least i hope
16   that some might consider it so) of goodbye.
17   [1f5a344665d8] [mytag]
18  
19   * hello:
20   added hello
21   [cd0d035975cb]
22  

Mercurial default というであることをってもくほどのことはいでしょう

11.1.1 Setting a default style

みのhgrc  ファイルすることでMercurial コマンド使するえるができま

1  [ui]
2  style = compact

したファイルへのパスする方法ファイルMercurial せる コピする方法には Mercurial インストされたディレクトリtemplates ディレクトリのどちらででも ファイル使うことができます

11.2 Commands that support styles and templates

logての Mercurial コマンドしてテンプレできますえばhg incominghg loghg outgoingおよび hg tipがそうです1

がこのマニュアルしているではテンプレしているコマンドそれくありません しかしみのコマンドカスタマイズコマンドでしたのでMercurial コミュニティからはコマンドにおけるテンプレへの要望のところあまりありませ

11.3 The basics of templating

Mercurial テンプレとはうならテキストですしてされない部分があるじて たなテキストでの実施されます

するMercurial をもうてみましょう

1  $ hg log -r1
2  changeset:   1:1f5a344665d8
3  tag:         mytag
4  user:        Bryan O’Sullivan <bos@serpentine.com>
5  date:        Mon Jul 20 21:48:34 2009 +0000
6  summary:     added line to end of <<hello>> file.
7  

それではえるためのテンプレしてコマンドしてみましょう

1  $ hg log -r1 --template ’i saw a changesetn’
2  i saw a changeset

テンプレとしてチェンジセットされるテキストするだけの hg logコマンドする--template オプションチェンジセット使するテンプレとして れたテキスト使することを Mercurial 指示します

テンプレ\nしているしてくださいこれはエスケプシケンスばれるも のでテンプレすることを Mercurial 指示しますこのした Mercurial しますエスケプシケンスする11.5  してくださ

されたするテンプレあまり有用とはえませんのでもうなものにしてみましょ

1  $ hg log --template ’i saw a changeset: {desc}∖n’
2  i saw a changeset: Added tag v0.1 for changeset 8899b18d5d72
3  i saw a changeset: Added tag mytag for changeset 1f5a344665d8
4  i saw a changeset: added line to end of <<hello>> file.
5  
6  in addition, added a file with the helpful name (at least i hope that some might consider it so) of goodbye.
7  i saw a changeset: added hello

テンプレ{desc}チェンジセットログメッセされてされます{}まれたテキストされたにはどんなテキストまれていたでもおよびテキスト部分 Mercurial によりみられますそのものをしたい11.5  べる方法エスケしなければなりま せん

11.4 Common template keywords

以下使することですぐにでもテンプレくことができます

author
チェンジセットチェンジセットされません
branches
チェンジセットコミットされたブランチブランチdefault です
date
チェンジセットコミットされたこのがありませんのでするフィルタ がありますフィルタする11.6  してくださいとしてされます Unix UTC タイムスタンプ1970 1 1 からのコミットUTC らのタイムゾンオフセットです
desc
チェンジセットログメッセ
files
リストチェンジセットないしされたてのファイル
file_adds
リストチェンジセットされたファイル
file_dels
リストチェンジセットされたファイル
node
チェンジセットハッシュ4016進数したもの
parents
リストチェンジセット
rev
整数リポジトリロカルチェンジセットリビジョン
tags
リストチェンジセットけられたタグ

つかしてみることでこれらの使したされるることができます 11.1してくださ


1  $ hg log -r1 --template ’author: {author}∖n’
2  author: Bryan O’Sullivan <bos@serpentine.com>
3  $ hg log -r1 --template ’desc:n{desc}∖n’
4  desc:
5  added line to end of <<hello>> file.
6  
7  in addition, added a file with the helpful name (at least i hope that some might consider it so) of goodbye.
8  $ hg log -r1 --template ’files: {files}∖n’
9  files: goodbye hello
10  $ hg log -r1 --template ’file_adds: {file_adds}∖n’
11  file_adds: goodbye
12  $ hg log -r1 --template ’file_dels: {file_dels}∖n’
13  file_dels:
14  $ hg log -r1 --template ’node: {node}∖n’
15  node: 1f5a344665d8e800e1d88631d873fada9816c8f5
16  $ hg log -r1 --template ’parents: {parents}∖n’
17  parents:
18  $ hg log -r1 --template ’rev: {rev}∖n’
19  rev: 1
20  $ hg log -r1 --template ’tags: {tags}∖n’
21  tags: mytag

Figure 11.1: Template keywords in use

したようにdate のある生成しませんのでいするがありますそのためには filter 使がありますが 11.6  してください

1  $ hg log -r1 --template ’date: {date}∖n’
2  date: 1248126514.00
3  $ hg log -r1 --template ’date: {date|isodate}∖n’
4  date: 2009-07-20 21:48 +0000

11.5 Escape sequences

Mercurial テンプレトエンジン使われているエスケプシケンスしますバックスラッ シュ\したにはそれにそれらつの以下すようなしま

∖∖
バックスラッシュ\)/ ASCII 134
n
ASCII 12.
r
ASCII 15.
t
タブASCII 11.
v
タブASCII 13.
∖{
{)/ ASCII 173.
∖}
})/ ASCII 175.

のように\{ないし {そのものをテンプレ使したいこれらはエスケされなければなりませ

11.6 Filtering keywords to change their results

テンプレにおけるのうちのつかはちに使えるほど便なものではありませんMercurial するためにフィルタすることをめてきますにおいてフィルタである isodate めるようにするために使しています

Mercurial サポする使されるフィルタリスト以下しますテキストできるフィルタ あればでのみなものもありますフィルタいて利用それに となっています

addbreaks
テキストXHTML <br/>タグしますえばfoo\nbarfoo<br/>\nbarとなります
age
date 現在するします10 minutesのような生成しま
basename
テキストですがfiles やその相対してするのが有用ですテキスト パスとしてそのスネしますえば foo/bar/bazbazとなります
date
date Unix date コマンド同等フォマットしますがタイムゾ みますMon Sep 04 15:13:13 2006 -0700のような生成します
domain
テキストですがauthor してするのが有用ですルアドレス し き つ け ド メ イ ン 部 分 の み を し ま すえ ばBryan O’Sullivan <bos@serpentine.com>serpentine.comとなります
email
テ キ ス ト で す がauthor してするのが有用ですルアドレスしきつけしますえばBryan O’Sullivan <bos@serpentine.com>bos@serpentine.comとなります
escape
テキストXML/XHTML である &<および >XML えます
fill68
テキストテキスト68 まるようにしますtabindent フィルタ実施80 フォントめたいtabindent フィルタテキストするのがいでしょう
fill76
テキスト76 まるようにします
firstline
テキストテキストまないします
hgdate
date のあるとしてします1157407993 25200のような 生成します
isodate
date ISO 8601 としてします2006-09-04 15:13:13 -0700のような生成します
obfuscate
テキストですがauthor してするのが有用ですテキスト する XML ケンス生成しますルアドレス収集スパムボットspambot するつとして利用です
person
ですがauthor してするのが有用ですルアドレスより 部分しますえば Bryan O’Sullivan <bos@serpentine.com>Bryan O’Sullivanとなり ます
rfc822date
date ルヘッダしますMon, 04 Sep 2006 15:13:13 -0700のような生成しま
short
チェンジセットハッシュですチェンジセットハッシュ12 16 生成 ます
shortdate
date します2006-09-04のような生成します
strip
テキストならびにします
tabindent
テキストてのタブまるようにします
urlescape
テキストURL とされるエスケしますえばfoo bar foo%20bar になります
user
ですがauthor してするのが有用ですルアドレスから部分しますえば Bryan O’Sullivan <bos@serpentine.com>bosとなります

1  $ hg log -r1 --template ’{author}∖n’
2  Bryan O’Sullivan <bos@serpentine.com>
3  $ hg log -r1 --template ’{author|domain}∖n’
4  serpentine.com
5  $ hg log -r1 --template ’{author|email}∖n’
6  bos@serpentine.com
7  $ hg log -r1 --template ’{author|obfuscate}∖n’ | cut -c-76
8  Bryan O'Sulli
9  $ hg log -r1 --template ’{author|person}∖n’
10  Bryan O’Sullivan
11  $ hg log -r1 --template ’{author|user}∖n’
12  bos
13  $ hg log -r1 --template ’looks almost right, but actually garbage: {date}∖n’
14  looks almost right, but actually garbage: 1248126514.00
15  $ hg log -r1 --template ’{date|age}∖n’
16  3 seconds
17  $ hg log -r1 --template ’{date|date}∖n’
18  Mon Jul 20 21:48:34 2009 +0000
19  $ hg log -r1 --template ’{date|hgdate}∖n’
20  1248126514 0
21  $ hg log -r1 --template ’{date|isodate}∖n’
22  2009-07-20 21:48 +0000
23  $ hg log -r1 --template ’{date|rfc822date}∖n’
24  Mon, 20 Jul 2009 21:48:34 +0000
25  $ hg log -r1 --template ’{date|shortdate}∖n’
26  2009-07-20
27  $ hg log -r1 --template ’{desc}∖n’ | cut -c-76
28  added line to end of <<hello>> file.
29  
30  in addition, added a file with the helpful name (at least i hope that some m
31  $ hg log -r1 --template ’{desc|addbreaks}∖n’ | cut -c-76
32  added line to end of <<hello>> file.<br/>
33  <br/>
34  in addition, added a file with the helpful name (at least i hope that some m
35  $ hg log -r1 --template ’{desc|escape}∖n’ | cut -c-76
36  added line to end of <<hello>> file.
37  
38  in addition, added a file with the helpful name (at least i hope that some m
39  $ hg log -r1 --template ’{desc|fill68}∖n’
40  added line to end of <<hello>> file.
41  
42  in addition, added a file with the helpful name (at least i hope
43  that some might consider it so) of goodbye.
44  $ hg log -r1 --template ’{desc|fill76}∖n’
45  added line to end of <<hello>> file.
46  
47  in addition, added a file with the helpful name (at least i hope that some
48  might consider it so) of goodbye.
49  $ hg log -r1 --template ’{desc|firstline}∖n’
50  added line to end of <<hello>> file.
51  $ hg log -r1 --template ’{desc|strip}∖n’ | cut -c-76
52  added line to end of <<hello>> file.
53  
54  in addition, added a file with the helpful name (at least i hope that some m
55  $ hg log -r1 --template ’{desc|tabindent}∖n’ | expand | cut -c-76
56  added line to end of <<hello>> file.
57  
58          in addition, added a file with the helpful name (at least i hope tha
59  $ hg log -r1 --template ’{node}∖n’
60  1f5a344665d8e800e1d88631d873fada9816c8f5
61  $ hg log -r1 --template ’{node|short}∖n’
62  1f5a344665d8

Figure 11.2: Template filters in action

: してフィルタみたMercurial して Python しますえばdesc isodate フィルタするのはよろしくありません

11.6.1 Combining filters

でのるためにフィルタわせることができます以下ではログメッセ 68 まるようにしたさらにタブとしてわれる Unix では げがフィルタにより実施されます

1  $ hg log -r1 --template ’description:nt{desc|strip|fill68|tabindent}∖n’
2  description:
3   added line to end of <<hello>> file.
4  
5   in addition, added a file with the helpful name (at least i hope
6   that some might consider it so) of goodbye.

テンプレにおける \tタブ利用げをうためのものであることにしてくださ tabindent てのげするためにこのタブです

におけるフィルタ順序であるしてくださいフィルタされ フィルタフィルタされるというですえばfill68|tabindent というtabindent|fill68 とはったとなります

11.7 From templates to styles

コマンドでのテンプレするしますしかしテンプレりがちですか テンプレけできれば便になりますsytleファイルけられファイルされたテンプレ のことです

それコマンドでの--template オプション使ではせなかった Mercurial テンプレトエンジン ファイルいることですことができます

11.7.1 The simplest of style files

以下ファイルだけのものです

1  $ echo ’changeset = "rev: {rev}∖n"’ > rev
2  $ hg log -l1 --style ./rev
3  rev: 3

このチェンジセットするにはテキストテンプレとして使せよMercurial 指示しま

11.7.2 Style file syntax

ファイル文法です

11.8 Style files by example

ファイルするためにつかのしますファイルしてむよりもからめて つかのみすることでファイルそうといます

11.8.1 Identifying mistakes in style files

ファイルがあったMercurial はそっけないエラメッセしますがするところがわかってしまえ そのメッセ有用です

1  $ cat broken.style
2  changeset =

broken.style changeset しようとしているもののそのされていないしてくださいこのようなファイルされた Mercurial メッセします

1  $ hg log -r1 --style broken.style
2  ** unknown exception encountered, details follow
3  ** report bug details to http://mercurial.selenic.com/bts/
4  ** or mercurial@selenic.com
5  ** Mercurial Distributed SCM (version 1.3)
6  ** Extensions loaded:
7  Traceback (most recent call last):
8    File "/home/vmuser/bin/hg", line 27, in <module>
9      mercurial.dispatch.run()
10    File "/home/vmuser/lib/python/mercurial/dispatch.py", line 16, in run
11      sys.exit(dispatch(sys.argv[1:]))
12    File "/home/vmuser/lib/python/mercurial/dispatch.py", line 27, in dispatch
13      return _runcatch(u, args)
14    File "/home/vmuser/lib/python/mercurial/dispatch.py", line 43, in _runcatch
15      return _dispatch(ui, args)
16    File "/home/vmuser/lib/python/mercurial/dispatch.py", line 449, in _dispatch
17      return runcommand(lui, repo, cmd, fullargs, ui, options, d)
18    File "/home/vmuser/lib/python/mercurial/dispatch.py", line 317, in runcommand
19      ret = _runcommand(ui, options, cmd, d)
20    File "/home/vmuser/lib/python/mercurial/dispatch.py", line 501, in _runcommand
21      return checkargs()
22    File "/home/vmuser/lib/python/mercurial/dispatch.py", line 454, in checkargs
23      return cmdfunc()
24    File "/home/vmuser/lib/python/mercurial/dispatch.py", line 448, in <lambda>
25      d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
26    File "/home/vmuser/lib/python/mercurial/util.py", line 370, in check
27      return func(*args, **kwargs)
28    File "/home/vmuser/lib/python/mercurial/commands.py", line 2030, in log
29      displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
30    File "/home/vmuser/lib/python/mercurial/cmdutil.py", line 978, in show_changeset
31      t = changeset_templater(ui, repo, patch, opts, mapfile, buffered)
32    File "/home/vmuser/lib/python/mercurial/cmdutil.py", line 742, in __init__
33      ’filecopy’: ’{name} ({source})’})
34    File "/home/vmuser/lib/python/mercurial/templater.py", line 160, in __init__
35      if val[0] in "’"":
36  IndexError: string index out of range

このメッセ威圧えますがくのはそれほどしくありません

11.8.2 Uniquely identifying a repository

として Mercurial リポジトリ一意 2 したい リポジトリリビジョン使するのがいでしょう

1  $ hg log -r0 --template ’{node}
2  84c0f05ef0a48b978212fbe41c27597bd50397a0

この一意であることがされていませんがそれでもくのにおいて有用です

リポジトリ利用以下します

11.8.3 Mimicking Subversion’s output

えば Subversion のようなデフォルトをまねてみましょう

1  $ svn log -r9653
2  ------------------------------------------------------------------------
3  r9653 | sean.hefty | 2006-09-27 14:39:55 -0700 (Wed, 27 Sep 2006) | 5 lines
4  
5  On reporting a route error, also include the status for the error,
6  rather than indicating a status of 0 when an error has occurred.
7  
8  Signed-off-by: Sean Hefty <sean.hefty@intel.com>
9  
10  ------------------------------------------------------------------------

Subversion はかなりですのでファイルテキストSubversion により生成される部分 されるテンプレ3 えるのはでしょう

1  $ cat svn.template
2  r{rev} | {author|user} | {date|isodate} ({date|rfc822date})
3  
4  {desc|strip|fill76}
5  
6  ------------------------------------------------------------------------

このテンプレによるSubversion により生成されるからする 4 かあります

Subversion 力例テンプレのようなフィルタへのえをせいぜいがですファイルにこのテンプレすればいのです

1  $ cat svn.style
2  header = ’------------------------------------------------------------------------nn’
3  changeset = svn.template

テンプレトファイルテキストファイル接設するには
nえればいのですがファイルくしてしまいますテンプレファイルするか ンプレトファイルしたものをファイルからするかをめるにはとするのがいでしょうファイ きさやさがまるテンプレトテキストするのではなくファイルしてしまいましょ