contrib/python-hook-examples.py
author Patrick Mezard <patrick@mezard.eu>
Fri, 27 Apr 2012 10:17:55 +0200
branchstable
changeset 16526 f2cc0ffb09de
parent 13878 a8d13ee0ce68
child 28562 2b585677220e
permissions -rw-r--r--
test-subrepo-svn: fix non-determinism The test was randomly failing with: --- /tests/test-subrepo-svn.t +++ /test-subrepo-svn.t.err @@ -273,10 +273,10 @@ 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ cd t/s $ svn status - ? * a (glob) - X * externals (glob) - ? * f1 (glob) - ? * f2 (glob) + ? f1 + ? f2 + ? a + X externals Performing status on external item at 'externals'* (glob)

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