view contrib/python-hook-examples.py @ 14046:b24e5a708fad

web: Made elapsed time calculation dynamic (javascript). This allow safe caching of the pages by the browser and still display the right amount of elapsed time upon page refresh. If javascript is disabled, absolute time is displayed, leaving it readable. All the templates have been updated.
author Benoit Allard <benoit@aeteurope.nl>
date Thu, 28 Apr 2011 17:02:39 +0200
parents a8d13ee0ce68
children 2b585677220e
line wrap: on
line source

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