Lunchtime Semaphore

from and to 372433 143758 48 N

Mercurial, no regrets

October 3rd, 2009 by Melaneum Google+

A while back, I mention one of the feature of Git I was missing in Mercurial. It was the nice way git display a summary of the changes when you update. But that’s it, no more regrets!

I discovered the world of mercurial hooks, and particularly this one:

Create a file with

from mercurial import patch, util

def diffstat(ui, repo, **kwargs):
    '''Use it like:

    [hooks]
    commit.diffstat = python:/path/to/this/file.py:diffstat
    changegroup.diffstat = python:/path/to/this/file.py:diffstat
    '''
    if kwargs.get('parent2'):
        return
    node = kwargs['node']
    first = repo[node].parents()[0].node()
    if 'url' in kwargs:
        last = repo['tip'].node()
    else:
        last = node
    diff = patch.diff(repo, first, last)
    ui.write(patch.diffstat(util.iterlines(diff)))

And as explain in the hook, add this to your ~/.hgrc

[hooks]
commit.diffstat = python:/path/to/this/file.py:diffstat
changegroup.diffstat = python:/path/to/this/file.py:diffstat

That’s it, next time you update or commit, you’ll see a nice summary of the modifications. Handy to know what’s happening at a glance.

This entry was posted on Saturday, October 3rd, 2009 at 04:44 UTC and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply