contrib/python-hook-examples.py
author Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
Mon, 02 May 2011 19:21:30 +0200
changeset 14164 cb98fed52495
parent 13878 a8d13ee0ce68
child 28562 2b585677220e
permissions -rw-r--r--
discovery: add new set-based discovery Adds a new discovery method based on repeatedly sampling the still undecided subset of the local node graph to determine the set of nodes common to both the client and the server. For small differences between client and server, it uses about the same or slightly fewer roundtrips than the old tree-based discovery. For larger differences, it typically reduces the number of roundtrips drastically (from 150 to 4, for instance). The old discovery code now lives in treediscovery.py, the new code is in setdiscovery.py. Still missing is a hook for extensions to contribute nodes to the initial sample. For instance, Augie's remotebranches could contribute the last known state of the server's heads. Credits for the actual sampler and computing common heads instead of bases go to Benoit Boissinot.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7917
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
     1
'''
7918
62f11ef0df5b Change wording in example hook
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7917
diff changeset
     2
Examples of useful python hooks for Mercurial.
7917
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
     3
'''
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
     4
from mercurial import patch, util
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
     5
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
     6
def diffstat(ui, repo, **kwargs):
7918
62f11ef0df5b Change wording in example hook
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7917
diff changeset
     7
    '''Example usage:
7917
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
     8
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
     9
    [hooks]
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    10
    commit.diffstat = python:/path/to/this/file.py:diffstat
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    11
    changegroup.diffstat = python:/path/to/this/file.py:diffstat
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    12
    '''
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    13
    if kwargs.get('parent2'):
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    14
        return
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    15
    node = kwargs['node']
13878
a8d13ee0ce68 misc: replace .parents()[0] with p1()
Matt Mackall <mpm@selenic.com>
parents: 7918
diff changeset
    16
    first = repo[node].p1().node()
7917
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    17
    if 'url' in kwargs:
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    18
        last = repo['tip'].node()
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    19
    else:
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    20
        last = node
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    21
    diff = patch.diff(repo, first, last)
5a5396f49420 diffstat hook example
Alexander Solovyov <piranha@piranha.org.ua>
parents:
diff changeset
    22
    ui.write(patch.diffstat(util.iterlines(diff)))