contrib/python-hook-examples.py
changeset 7917 5a5396f49420
child 7918 62f11ef0df5b
equal deleted inserted replaced
7916:f779e1996e23 7917:5a5396f49420
       
     1 '''
       
     2 These are examples of useful hooks in Python for Mercurial.
       
     3 '''
       
     4 
       
     5 from mercurial import patch, util
       
     6 
       
     7 
       
     8 def diffstat(ui, repo, **kwargs):
       
     9     '''Use it like:
       
    10 
       
    11     [hooks]
       
    12     commit.diffstat = python:/path/to/this/file.py:diffstat
       
    13     changegroup.diffstat = python:/path/to/this/file.py:diffstat
       
    14     '''
       
    15     if kwargs.get('parent2'):
       
    16         return
       
    17     node = kwargs['node']
       
    18     first = repo[node].parents()[0].node()
       
    19     if 'url' in kwargs:
       
    20         last = repo['tip'].node()
       
    21     else:
       
    22         last = node
       
    23     diff = patch.diff(repo, first, last)
       
    24     ui.write(patch.diffstat(util.iterlines(diff)))