view contrib/python-hook-examples.py @ 20631:5d4606bec54c

cmdserver: mask return code of runcommand in the same way as dispatch.run "hg help" does not state that the code for abort is 255, but it's confusing to have different code between hg command and command server. Tests of python-hglib 1.2 passed with this change.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 03 Mar 2014 15:50:51 +0900
parents a8d13ee0ce68
children 2b585677220e
line wrap: on
line source

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