contrib/python-hook-examples.py
author Yuya Nishihara <yuya@tcha.org>
Wed, 11 Jul 2018 22:06:04 +0900
changeset 38652 bfcd5c7cbf9a
parent 28562 2b585677220e
child 39895 1a184b727aff
permissions -rw-r--r--
grep: restore pre-9ef10437bb88 behavior, enable wdir search by tweakdefaults Unfortunately, python-hglib relies on the original grep behavior and is documented as such. Even though we agreed to introduce the BC, we shouldn't break existing libraries. So this patch flips the default again and move the new default to ui.tweakdefaults. We could instead use HGPLAIN to turn this flag off, but that would be rather confusing as the old/new behaviors are quite different. Differential Revision: https://phab.mercurial-scm.org/D3919

'''
Examples of useful python hooks for Mercurial.
'''
from __future__ import absolute_import
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)))