Category Archives: mercurial

Mercurial Templating

It’s possible to customize how the log output looks like using hg.
We can use inline templates as in:


hg log --template "{rev}"

{rev} is called a “keyword” and it gets replaced by the actual value when we do hg log. The list of keywords can be seen here.

Alternatively we can define our style in a separate file, e.g. ~/.hg/mytemplate.style:


changeset = 'changeset: {rev}:{node|short}'

We specify the style using --style=/home/unixname/.hg/mytemplate.style or setting the default style in .hgrc:


[ui]
style=/home/unixname/.hg/mytemplate.style

Other settings

Colors

We can change the font-colors of the text by using ANSI escape codes

Basically we specify \x1B[3<i>m where <i> is a number from 0 to 7 (see the wikipedia page for the color mapping). And \x1B[0m resets the color.

Files in multiple lines

We can add the following line that configures the formatting of a file entry (when using the {files} keyword)


file = ' {file}\n'

Date in my timezone

We can use

{date|localdate|rfc822date}

References

[1] http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html
[2] http://stackoverflow.com/questions/8643612/how-to-make-hg-log-verbose-show-files-on-multiple-lines
[3] http://www.selenic.com/hg/help/templates