contrib/python-hook-examples.py
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
Fri, 01 Feb 2013 05:40:06 +0100
branchstable
changeset 18517 0c51532ec233
parent 13878 a8d13ee0ce68
child 28562 2b585677220e
permissions -rw-r--r--
hgweb: remove baseline info from paper template The user interface introduced in d605a82cf189 is not considered ready for prime time yet. The internal code stays in place for custom template usage. The feature is ultimately wanted and will be re-enabled soon. The current issue is only related to the visual of the current interface.

'''
Examples of useful python hooks for Mercurial.
'''
from mercurial import patch, util

def diffstat(ui, repo, **kwargs):
    '''Example usage:

    [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].p1().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)))