contrib/python-hook-examples.py
author Mads Kiilerich <mads@kiilerich.com>
Mon, 07 Nov 2011 03:14:53 +0100
changeset 15439 01611e7c36ff
parent 13878 a8d13ee0ce68
child 28562 2b585677220e
permissions -rw-r--r--
dispatch: exit with 8-bit exit code The exit code returned from a program to the shell is unsigned 8-bit, but Mercurial would sometimes try to exit with negative numbers or None. sys.exit on Unix will convert that to 8-bit exit codes, but on Windows negative values showed up as 0. The exit code is now explicitly converted to unsigned 8-bit.

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