view contrib/python-hook-examples.py @ 45563:142f0dcf90d0

log: remove stale comment about order of user revset _makerevset() no longer depends on the computed revs since ea3320015d54 "log: remove dead code to follow descendants if ascending revisions specified."
author Yuya Nishihara <yuya@tcha.org>
date Sat, 12 Sep 2020 16:11:10 +0900
parents 2372284d9457
children 89a2afe31e82
line wrap: on
line source

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