annotate contrib/python-hook-examples.py @ 25344:ceaf04bb14ff

revset: add fast path for _list() of integer revisions This can greatly speed up chained 'or' of integer revisions. 1) reduce nesting of chained 'or' operations 2) optimize to a list 3) fast path for integer revisions (this patch) revset #0: 0 + 1 + 2 + ... + 1000 1) wall 0.483341 comb 0.480000 user 0.480000 sys 0.000000 (best of 20) 2) wall 0.025393 comb 0.020000 user 0.020000 sys 0.000000 (best of 107) 3) wall 0.008371 comb 0.000000 user 0.000000 sys 0.000000 (best of 317) revset #1: sort(0 + 1 + 2 + ... + 1000) 1) wall 0.035240 comb 0.040000 user 0.040000 sys 0.000000 (best of 100) 2) wall 0.026432 comb 0.030000 user 0.030000 sys 0.000000 (best of 102) 3) wall 0.008418 comb 0.000000 user 0.000000 sys 0.000000 (best of 322) revset #2: first(0 + 1 + 2 + ... + 1000) 1) wall 0.028949 comb 0.030000 user 0.030000 sys 0.000000 (best of 100) 2) wall 0.025503 comb 0.030000 user 0.030000 sys 0.000000 (best of 106) 3) wall 0.008423 comb 0.010000 user 0.010000 sys 0.000000 (best of 319) But I admit that it is still slower than the spanset. revset #3: 0:1000 3) wall 0.000132 comb 0.000000 user 0.000000 sys 0.000000 (best of 19010)
author Yuya Nishihara <yuya@tcha.org>
date Sun, 17 May 2015 15:16:13 +0900
parents a8d13ee0ce68
children 2b585677220e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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)))