Show More
@@ -1,50 +1,52 b'' | |||
|
1 | 1 | # Extension dedicated to test patch.diff() upgrade modes |
|
2 | 2 | |
|
3 | 3 | from __future__ import absolute_import |
|
4 | 4 | |
|
5 | 5 | from mercurial import ( |
|
6 | 6 | error, |
|
7 | 7 | patch, |
|
8 | pycompat, | |
|
8 | 9 | registrar, |
|
9 | 10 | scmutil, |
|
10 | 11 | ) |
|
11 | 12 | |
|
12 | 13 | cmdtable = {} |
|
13 | 14 | command = registrar.command(cmdtable) |
|
14 | 15 | |
|
15 | 16 | @command(b'autodiff', |
|
16 | 17 | [(b'', b'git', b'', b'git upgrade mode (yes/no/auto/warn/abort)')], |
|
17 | 18 | b'[OPTION]... [FILE]...') |
|
18 | 19 | def autodiff(ui, repo, *pats, **opts): |
|
20 | opts = pycompat.byteskwargs(opts) | |
|
19 | 21 | diffopts = patch.difffeatureopts(ui, opts) |
|
20 | 22 | git = opts.get(b'git', b'no') |
|
21 | 23 | brokenfiles = set() |
|
22 | 24 | losedatafn = None |
|
23 | 25 | if git in (b'yes', b'no'): |
|
24 | 26 | diffopts.git = git == b'yes' |
|
25 | 27 | diffopts.upgrade = False |
|
26 | 28 | elif git == b'auto': |
|
27 | 29 | diffopts.git = False |
|
28 | 30 | diffopts.upgrade = True |
|
29 | 31 | elif git == b'warn': |
|
30 | 32 | diffopts.git = False |
|
31 | 33 | diffopts.upgrade = True |
|
32 | 34 | def losedatafn(fn=None, **kwargs): |
|
33 | 35 | brokenfiles.add(fn) |
|
34 | 36 | return True |
|
35 | 37 | elif git == b'abort': |
|
36 | 38 | diffopts.git = False |
|
37 | 39 | diffopts.upgrade = True |
|
38 | 40 | def losedatafn(fn=None, **kwargs): |
|
39 | 41 | raise error.Abort(b'losing data for %s' % fn) |
|
40 | 42 | else: |
|
41 | 43 | raise error.Abort(b'--git must be yes, no or auto') |
|
42 | 44 | |
|
43 | 45 | ctx1, ctx2 = scmutil.revpair(repo, []) |
|
44 | 46 | m = scmutil.match(ctx2, pats, opts) |
|
45 | 47 | it = patch.diff(repo, ctx1.node(), ctx2.node(), match=m, opts=diffopts, |
|
46 | 48 | losedatafn=losedatafn) |
|
47 | 49 | for chunk in it: |
|
48 | 50 | ui.write(chunk) |
|
49 | 51 | for fn in sorted(brokenfiles): |
|
50 | 52 | ui.write((b'data lost for: %s\n' % fn)) |
General Comments 0
You need to be logged in to leave comments.
Login now