Mercurial built-in template style description

1k views Asked by At

I am trying to tune the output of hg log by defining my own style. In fact, just adding information to the default style would be perfect. Is there a place where I can get the description of the default styles (default, compact, ...) to write my own?

4

There are 4 answers

0
Vinz On BEST ANSWER

After some research, I finally found the location of the default styles for hg log, located on my ubuntu 14.04 at

/usr/share/mercurial/templates/

You can find there the following files:

map-cmdline.bisect
map-cmdline.changelog
map-cmdline.compact
map-cmdline.default
map-cmdline.phases
map-cmdline.xml        

They do not contain any color scheme, but they are allowed me to build my 'patched' version of default.

1
Christophe Muller On

If you know how to use the various keywords that Mercurial templating feature understands (see hg help templating for a very complete usage doc), then you can either:

  • specify your choices by giving a template on the command line, e.g.,

    $ hg tip --template "{rev} at {date|isodate}"\n
    882 at 2014-12-17 08:50 +0100

  • or edit an ascii file with the same format and use it with the style option, e.g.,

    $ cat ~/mystyle.txt
    changeset = "{rev} at {date|isodate}\n"
    $ hg tip --style ~/mystyle.txt
    882 at 2014-12-17 08:50 +0100

0
muxator On

It's strange, but the default templates are hardcoded in mercurial code.

The file map-cmdline.default is never read at runtime, but can be used to exactly replicate mercurial output (and thus to extend it).

Example of how to extend hg log output to include the git commit hash of a git repository cloned via hg-git.

Look for the location of map-cmdline.default:

$ hg debuginstall --config ui.editor=cat | grep "default template"
checking default template (/usr/lib/python2.7/dist-packages/mercurial/templates/map-cmdline.default)

Edit /etc/mercurial/hgrc, pasting a slightly modified version of map-cmdline.default:

...first part of your hgrc...

[templates]
# support "git-commit" line in hg log
changeset_git = '{cset}{cset_git}{branches}{bookmarks}{tags}{parents}{user}{ldate}{ltroubles}{lobsfate}{summary}\n'
cset_git      = '{if(gitnode, "git-commit:  {label("status.unknown", gitnode|short)}\n")}'

...the rest of 'templates' section of map-cmdline.default...

[templatealias]
...the whole 'templatealias' section of map-cmdline.default...

Example output:

~/git$ hg log --graph
@    changeset:   54881:d420062ce3d6
|\   git-commit:  6326d2e53311    <-- new line, only appears in git clones
| |  tag:         default/pu
| |  tag:         tip
| |  parent:      54879:31a4c8ccc461
| |  parent:      54880:691b9814f119
| |  user:        Junio C Hamano <[email protected]>
| |  date:        Sun Mar 25 10:52:08 2018 -0700
| |  summary:     Merge branch 'jh/partial-clone' into pu
0
M Hutson On

From other comments elsewhere you can find out where the styles location is by:

hg debuginstall --config ui.editor=cat

Or using a bug if you choose a directory under the template it complains and tells you where they are (probably should for non matching styles), well it does for 1.9.2:

hg in --style paper

If you want to colour the output you could use the color extension now. add to .hgrc:

[extensions]
color=