contrib/python-hook-examples.py
author Boris Feld <boris.feld@octobus.net>
Wed, 26 Sep 2018 22:05:28 +0200
changeset 39920 7198cdbbbde1
parent 39900 1a184b727aff
child 43076 2372284d9457
permissions -rw-r--r--
rebase: don't try to prune obsolete changeset already in the destination With similar motivations to the previous changesets, we stop marking changeset from pruning when it is not the command intention. In this case, we still need to distinguish between the strip and the obsolete case.

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