contrib/python-hook-examples.py
author Mads Kiilerich <madski@unity3d.com>
Mon, 04 Feb 2013 02:46:53 +0100
changeset 18543 c8ba98bf0e71
parent 13878 a8d13ee0ce68
child 28562 2b585677220e
permissions -rw-r--r--
merge: don't indent "local changed %s which remote deleted" prompt It was usually not shown in a context where indentation helped readability and it was inconsistent with other prompts.

'''
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)))