contrib/python-hook-examples.py
author Gregory Szorc <gregory.szorc@gmail.com>
Sun, 13 Dec 2015 10:45:27 -0800
changeset 27375 c4a062d090ee
parent 13878 a8d13ee0ce68
child 28562 2b585677220e
permissions -rw-r--r--
help: teach loaddoc to load from a different directory The help system currently only supports showing help topics from a single directory. We'll need to teach it to show results from different directories in order to show the internals topics. The first step is to teach loaddoc() to load documentation from a sub-directory.

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