contrib/python-hook-examples.py
author Boris Feld <boris.feld@octobus.net>
Thu, 01 Nov 2018 14:24:34 +0100
changeset 40518 b57f2734ac92
parent 39900 1a184b727aff
child 43076 2372284d9457
permissions -rw-r--r--
test: use the "correct" merge tool in `test-rebase-detach.t` The value of `HGMERGE` overrides the value passed through --config. We are about to drop this `HGMERGE` environment variable so we update the value used in config to match what is currently in use. This is another example of confusion introduced by the `HGMERGE` environment variable.

'''
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.changelog.tip()
    else:
        last = node
    diff = patch.diff(repo, first, last)
    ui.write(patch.diffstat(util.iterlines(diff)))