contrib/python-hook-examples.py
author timeless@mozdev.org
Thu, 03 Sep 2015 17:06:27 -0400
changeset 26170 61124bf8485f
parent 13878 a8d13ee0ce68
child 28562 2b585677220e
permissions -rw-r--r--
minirst: handle edge in hunting for parents test for "hg help -c config" in help config ``section`` ----------- section text ``def1`` definition of def1 $ hg help scope.def1 should list this paragraph, but not section text below... section text ``def2`` definition of def2 $ hg help scope.def2 should list this paragraph, but not section text below... section text $ hg help scope.section should show everything from the first section text to this last line. ``section2`` ------------

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