view contrib/python-hook-examples.py @ 38003:1335bbfb066f

packaging: move most of contrib/docker to contrib/packaging/docker contrib/ is kind of a dumping ground for all kinds of random things. Many of the files in contrib/ are related to packaging. But sorting out how everything is related is a lot of effort since it is all mixed together. This commit starts the process of refactoring everything related to packaging so it all lives under one roof. Most content from contrib/docker is simply moved to contrib/packaging/docker and all references are updated. Differential Revision: https://phab.mercurial-scm.org/D3541
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 12 May 2018 13:17:01 -0700
parents 2b585677220e
children 1a184b727aff
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['tip'].node()
    else:
        last = node
    diff = patch.diff(repo, first, last)
    ui.write(patch.diffstat(util.iterlines(diff)))