Mercurial > hg
annotate contrib/tmplrewrite.py @ 14087:f3d585c9b042
graphmod: restore generator nature of dagwalker
9966c95b8c4f introduced the ability to walk the DAG
given arbitrary revisions, but changed the behaviour of
it to return a list of all nodes (and create a changectx
for each one) rather than doing it lazily.
This has a pretty significant impact on performance for large
repositories (tested on CPython repo, with output disabled):
$ time hg glog
real 0m2.642s
user 0m2.560s
sys 0m0.080s
Before 9966c95b8c4f:
$ time hg glog
real 0m0.143s
user 0m0.112s
sys 0m0.032s
And after this fix:
$ time hg glog
real 0m0.213s
user 0m0.184s
sys 0m0.028s
author | Idan Kamara <idankk86@gmail.com> |
---|---|
date | Sat, 30 Apr 2011 15:10:58 +0300 |
parents | 94ef2c8ce683 |
children |
rev | line source |
---|---|
8432
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
1 #!/usr/bin/python |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
2 import sys, os, re |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
3 |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
4 IGNORE = ['.css', '.py'] |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
5 oldre = re.compile('#([\w\|%]+)#') |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
6 |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
7 def rewrite(fn): |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
8 f = open(fn) |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
9 new = open(fn + '.new', 'wb') |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
10 for ln in f: |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
11 new.write(oldre.sub('{\\1}', ln)) |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
12 new.close() |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
13 f.close() |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
14 os.rename(new.name, f.name) |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
15 |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
16 if __name__ == '__main__': |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
17 if len(sys.argv) < 2: |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
18 print 'usage: python tmplrewrite.py [file [file [file]]]' |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
19 for fn in sys.argv[1:]: |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
20 if os.path.splitext(fn) in IGNORE: |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
21 continue |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
22 print 'rewriting %s...' % fn |
94ef2c8ce683
contrib: add tmplrewrite.py script to help rewrite old templater syntax
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff
changeset
|
23 rewrite(fn) |