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