| 1 |
''' |
| 2 |
Examples of useful python hooks for Mercurial. |
| 3 |
''' |
| 4 |
from mercurial import ( |
| 5 |
patch, |
| 6 |
util, |
| 7 |
) |
| 8 |
|
| 9 |
|
| 10 |
def diffstat(ui, repo, **kwargs): |
| 11 |
"""Example usage: |
| 12 |
|
| 13 |
[hooks] |
| 14 |
commit.diffstat = python:/path/to/this/file.py:diffstat |
| 15 |
changegroup.diffstat = python:/path/to/this/file.py:diffstat |
| 16 |
""" |
| 17 |
if kwargs.get('parent2'): |
| 18 |
return |
| 19 |
node = kwargs['node'] |
| 20 |
first = repo[node].p1().node() |
| 21 |
if 'url' in kwargs: |
| 22 |
last = repo.changelog.tip() |
| 23 |
else: |
| 24 |
last = node |
| 25 |
diff = patch.diff(repo, first, last) |
| 26 |
ui.write(patch.diffstat(util.iterlines(diff))) |