2010年12月18日星期六

[Mercurial] Enhance hg log with nice coloring

<read [Console2 + Cygwin + bash + Mercurial + style template] to support ANSI escape code to setup the environment first>


Now, I use Console2 + cygwin + ansicon + bash for my Mercurial operation.
There are several hg command that support --style STYLE formatting, e.g. log, outgoing, incoming, tip, parents, heads, glog and serve.
The most useful common with styling is hg log.


I find a good website written by Steve Losh : Styling Mercurial’s CLI, which provide several good style template for hg log, includes "slog", "nlog" and "sglog".

Styling Mercurial’s CLI

posted by Steve Losh on
January 15, 2010


Mercurial has a great command line interface and many people use it without 
ever feeling the need for a GUI to manage their 
repositories. However, we can make it even better by taking advantage of 
Mercurial’s templating features.


In this tip I’m going to post some of the templates I use and show you how to 
use them yourself. Check out hg help templating if you want more 
details on how the templating actually works.


If you like what you see you can grab my templates by cloning their repository
from BitBucket:


hg clone http://bitbucket.org/sjl/mercurial-cli-templates/


NOTE: I’ve customized the colors of 
my Terminal, so the colors will look different for you. If you like the colors 
I’m using you can read the blog entry
I wrote about it.

Short Log

In a previous tip I described how to create an hg slog alias that can be very useful for counting changesets. With the right styling it can be useful in your day-to-day work. Here’s what the output of my hg slog command looks like:
To use this template you can edit your ~/.hgrc file to contain the following:
[alias]
slog = log --style=/full/path/to/map-cmdline.slog

Nice Log

The short log is great a quick review of the past few changesets, but for a much more detailed view of a particular changeset I’ve created an hg nlog alias, which looks like this:
To use this template you can edit your ~/.hgrc file to contain the following:
[alias]
nlog = log --style=/full/path/to/map-cmdline.nlog

Short Graphlog

The graphlog command is wonderful for reviewing the history of repositories with branches, but we can make it more compact and easier to read with another template. The result looks like this:
To use this template you can edit your ~/.hgrc file to contain the following:
[alias]
sglog = glog --style=/full/path/to/map-cmdline.sglog

===============================================================

I find a way no need to put /full/path/to/ the map-cmdline.xxx, just need to put the map-cmdline.xxx in C:\Program Files\TortoiseHg\templates, the set the alias as:
[alias]
slog  = log --style slog
nlog  = log --style nlog
sglog = log --style sglog

Then just try the following command:
hg slog -l10
hg slog -l10 -v
hg nlog -r tip
hg nlog -r tip -p

hg sglog -l8
hg sglog -l8 -v


Have fun :)

沒有留言:

發佈留言