Hg-Prompt extension for Mercurial

You can add some Mercurial information to your shell prompt, but it can be quite a pain to do this using the commands in Mercurial. Steve Losh created the Hg-Prompt extension purely for the purpose of using it in shell prompts.

To install this extension, first clone the repository somewhere:

$ hg clone https://bitbucket.org/sjl/hg-prompt/

And add the path to the prompt.py in your hgrc file:

[extensions]
prompt = /path/to/hg-prompt/prompt.py

The extension comes with keywords which are listed here. For example, to get the count of incoming changes:

$ hg prompt "{No of incoming changes: {incoming|count}}"

The great thing about this is that if there is no incoming changes, none of the text is printed.

You can easily adapt Hg-Prompt into your shell. For example, in the fish shell, you can print out the incoming changes like this in its fish_prompt.fish:

echo (hg prompt "{No of in changes: {incoming|count}}")

Tried with: Mercurial 2.8.2 and Ubuntu 14.04

How to view specific revisions in Mercurial log

I typically check the Mercurial history of a repository using the log or the graphical log -G method. I sometimes find it convenient to view only the tags or heads in the same log format. This is as if the log was filtered out to show only the tags or heads log entries.

This can be done by passing the resulting list of revisions from the tag or head functions to the log option:

$ hg log -r "tag()"
$ hg log -G -r "tag()"
$ hg log -r "head()"
$ hg log -G -r "head()"

Tried with: Mercurial 2.8.2 and Ubuntu 14.04

How to use Activity extension of Mercurial

Display of activities on a Mercurial repository

Display of activities on a Mercurial repository

The Punchcard extension of Mercurial can be used to obtain a calendar chart of your contributions to a repository, as shown in this post. If you need to view or generate traditional line graphs of your activities on a Mercurial repository, then the Activity extension might be appropriate for you.

Clone the repository of the Activity extension:

$ hg clone http://sources.freehackers.org/Hgactivity/

Add these lines to your hgrc:

[extensions]
activity=/path/to/Hgactivity/activity

That is it! To view line graphs of activities on your repository in an interactive GUI:

$ hg activity --mode=gui

You can view your activity, activities of all contributors, activities across different files and directories by choosing the various options in the GUI.

To generate an image file named activity.png of this line graph:

$ hg activity --mode=file

If you find yourself using one of these activity options a lot, you could create an alias for it by adding these lines to your hgrc:

[alias]
gact = activity --mode=gui

After this, you can use the alias instead of the more verbose form:

$ hg gact

Tried with: Mercurial 2.8.2 and Ubuntu 12.04

How to use Punchcard extension of Mercurial

Punchcard of a Mercurial repository

Punchcard of a Mercurial repository

One of the coolest feature of Github is the calendar chart that is shows for your contributions. Though Bitbucket does not yet have such a feature, you can display a similar chart for a Mercurial repository using the Punchcard extension.

  1. To begin, first clone the Punchcard repository in a suitable directory:
$ hg clone https://bitbucket.org/birkenfeld/hgpunchcard
  1. Modify your hgrc and add this line:
[extensions]
hgpunchcard = /path/to/hgpunchcard.py
  1. To generate the punchcard for a repository, try this command from inside any of its directories:
$ hg punchcard

This saves a file named punchcard.png that a chart of your commits to this repository, as shown above.

Tried with: Mercurial 2.8.2 and Ubuntu 12.04

How to use ExtDiff extension of Mercurial

Mercurial is very convenient to use at the commandline. However, there are certain operations that are better with the GUI. For example, I prefer to use a GUI to go through the diff of uncommitted changes. The ExtDiff extension can be used to launch a GUI Diff tool to view the diff of a single file or across the entire repository.

  • To enable the ExtDiff extension, add this line to your hgrc:
[extensions]
hgext.extdiff =
  • To view the diff of a particular file using a GUI diff program, for example meld:
$ hg extdiff -p meld src/bar/foo.cpp
  • To view the diff of all uncommitted files using a GUI diff program, for example meld:
$ hg extdiff -p meld

Make sure that the GUI diff program you use has the ability to show the diff of multiple files in a directory hierarchy.

  • If you want to always launch a particular GUI diff program, then it is better to add a custom command for it. For example, to launch meld using a new command named vdiff, add this line to your hgrc:
[extdiff]
cmd.vdiff = meld

After this, you can view the diff using the vdiff command:

$ hg vdiff src/bar/foo.cpp
$ hg vdiff

Tried with: Mercurial 2.8.2 and Ubuntu 12.04

How to use Churn extension of Mercurial

The Churn extension is useful to have on repositories shared by many authors. It shows a simple histogram of committed changes, along with author name.

  • To enable the Churn extension, add this line to your hgrc:
[extensions]
churn =
  • Using churn is straightforward:
$ hg churn
joe@mac.com 800 ********************************
foo@foo.com 420 *****************

Tried with: Mercurial 2.8.2 and Ubuntu 12.04

How to use Shelve extension of Mercurial

The Shelve extension of Mercurial is useful to temporarily store away your uncommitted changes and then restore them back. For example, if you are working on some changes, and before you commit it, someone comes in and asks you to test something on an earlier version. You can shelve away your changes, finish the testing and unshelve the changes and continue.

  • The Shelve extension needs Mercurial 2.8 or later. If you have an older version of Mercurial, install the latest version.

  • If your Mercurial installation does not include the Shelve extension, it can be installed from PyPI using PIP:

$ sudo pip install hgshelve
  • Enable the extension by adding this line to your hgrc:
[extensions]
shelve =
  • To shelve your uncommitted changes:
$ hg shelve

It will be stored using the name default. You can provide other names if you wish.

  • To unshelve these changes later:
$ hg unshelve

Tried with: Mercurial 2.8.2 and Ubuntu 12.04