contrib/python-hook-examples.py
author Simon Heimberg <simohe@besonet.ch>
Tue, 05 Nov 2013 09:43:36 +0100
changeset 19991 ce5d711475a3
parent 13878 a8d13ee0ce68
child 28562 2b585677220e
permissions -rw-r--r--
Makefile: do update on a temporary copy of a po file This avoids having a half completed file (with a new timestamp) when msgmerge has failed.

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