sapling/contrib/python-hook-examples.py

23 lines
586 B
Python
Raw Normal View History

2009-03-26 17:49:47 +03:00
'''
2009-03-30 03:21:39 +04:00
Examples of useful python hooks for Mercurial.
2009-03-26 17:49:47 +03:00
'''
from mercurial import patch, util
def diffstat(ui, repo, **kwargs):
2009-03-30 03:21:39 +04:00
'''Example usage:
2009-03-26 17:49:47 +03:00
[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].parents()[0].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)))