Debian Codegraph @

tests/autodiff.py

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