contrib/python-hook-examples.py
author pacien <pacien.trangirard@pacien.net>
Mon, 25 Jul 2022 22:47:15 +0200
changeset 49508 791050360486
parent 48875 6000f5b25c9b
permissions -rw-r--r--
contrib: add pull_logger extension This extension logs the pull parameters, i.e. the remote and common heads, when pulling from the local repository. The collected data should give an idea of the state of a pair of repositories and allow replaying past synchronisations between them. This is particularly useful for working on data exchange, bundling and caching-related optimisations.

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