Mercurial, no regrets

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.

Leave a Reply

Your email address will not be published. Required fields are marked *