Mercurial > hg
annotate tests/autodiff.py @ 37274:45987e2b64f0
templatekw: do not directly call .gen
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 18 Mar 2018 00:11:36 +0900 |
parents | f654105f1517 |
children | cdccfe20eed7 |
rev | line source |
---|---|
10189
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
1 # Extension dedicated to test patch.diff() upgrade modes |
27281
3b517f2a3989
tests/autodiff.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26587
diff
changeset
|
2 |
3b517f2a3989
tests/autodiff.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26587
diff
changeset
|
3 from __future__ import absolute_import |
3b517f2a3989
tests/autodiff.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26587
diff
changeset
|
4 |
3b517f2a3989
tests/autodiff.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26587
diff
changeset
|
5 from mercurial import ( |
3b517f2a3989
tests/autodiff.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26587
diff
changeset
|
6 error, |
3b517f2a3989
tests/autodiff.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26587
diff
changeset
|
7 patch, |
32337
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27281
diff
changeset
|
8 registrar, |
27281
3b517f2a3989
tests/autodiff.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26587
diff
changeset
|
9 scmutil, |
3b517f2a3989
tests/autodiff.py: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26587
diff
changeset
|
10 ) |
10189
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
11 |
21254
51e5c793a9f4
tests: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
17956
diff
changeset
|
12 cmdtable = {} |
32337
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
27281
diff
changeset
|
13 command = registrar.command(cmdtable) |
21254
51e5c793a9f4
tests: declare commands using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents:
17956
diff
changeset
|
14 |
35581
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
15 @command(b'autodiff', |
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
16 [(b'', b'git', b'', b'git upgrade mode (yes/no/auto/warn/abort)')], |
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
17 b'[OPTION]... [FILE]...') |
10189
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
18 def autodiff(ui, repo, *pats, **opts): |
23692
f78192115229
tests/autodiff.py: explicitly only honor feature diffopts
Siddharth Agarwal <sid0@fb.com>
parents:
21254
diff
changeset
|
19 diffopts = patch.difffeatureopts(ui, opts) |
35581
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
20 git = opts.get(b'git', b'no') |
10189
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
21 brokenfiles = set() |
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
22 losedatafn = None |
35581
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
23 if git in (b'yes', b'no'): |
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
24 diffopts.git = git == b'yes' |
10189
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
25 diffopts.upgrade = False |
35581
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
26 elif git == b'auto': |
10189
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
27 diffopts.git = False |
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
28 diffopts.upgrade = True |
35581
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
29 elif git == b'warn': |
10189
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
30 diffopts.git = False |
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
31 diffopts.upgrade = True |
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
32 def losedatafn(fn=None, **kwargs): |
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
33 brokenfiles.add(fn) |
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
34 return True |
35581
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
35 elif git == b'abort': |
10189
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
36 diffopts.git = False |
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
37 diffopts.upgrade = True |
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
38 def losedatafn(fn=None, **kwargs): |
35581
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
39 raise error.Abort(b'losing data for %s' % fn) |
10189
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
40 else: |
35581
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
41 raise error.Abort(b'--git must be yes, no or auto') |
10189
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
42 |
37258
f654105f1517
tests: use context-return revpair() in autodiff
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
43 ctx1, ctx2 = scmutil.revpair(repo, []) |
f654105f1517
tests: use context-return revpair() in autodiff
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
44 m = scmutil.match(ctx2, pats, opts) |
f654105f1517
tests: use context-return revpair() in autodiff
Martin von Zweigbergk <martinvonz@google.com>
parents:
37251
diff
changeset
|
45 it = patch.diff(repo, ctx1.node(), ctx2.node(), match=m, opts=diffopts, |
10189
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
46 losedatafn=losedatafn) |
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
47 for chunk in it: |
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
48 ui.write(chunk) |
e451e599fbcf
patch: support diff data loss detection and upgrade
Patrick Mezard <pmezard@gmail.com>
parents:
diff
changeset
|
49 for fn in sorted(brokenfiles): |
35581
154754d1f137
tests: make autodiff.py work on Python 3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32337
diff
changeset
|
50 ui.write((b'data lost for: %s\n' % fn)) |