autodiff.py
65 lines
| 1.5 KiB
| text/x-python
|
PythonLexer
/ tests / autodiff.py
|
r10189 | # Extension dedicated to test patch.diff() upgrade modes | ||
|
r27281 | |||
from __future__ import absolute_import | ||||
from mercurial import ( | ||||
error, | ||||
patch, | ||||
|
r37386 | pycompat, | ||
|
r32337 | registrar, | ||
|
r27281 | scmutil, | ||
) | ||||
|
r10189 | |||
|
r21254 | cmdtable = {} | ||
|
r32337 | command = registrar.command(cmdtable) | ||
|
r21254 | |||
|
r43346 | |||
@command( | ||||
b'autodiff', | ||||
|
r35599 | [(b'', b'git', b'', b'git upgrade mode (yes/no/auto/warn/abort)')], | ||
|
r43346 | b'[OPTION]... [FILE]...', | ||
) | ||||
|
r10189 | def autodiff(ui, repo, *pats, **opts): | ||
|
r37386 | opts = pycompat.byteskwargs(opts) | ||
|
r23692 | diffopts = patch.difffeatureopts(ui, opts) | ||
|
r35599 | git = opts.get(b'git', b'no') | ||
|
r10189 | brokenfiles = set() | ||
losedatafn = None | ||||
|
r35599 | if git in (b'yes', b'no'): | ||
diffopts.git = git == b'yes' | ||||
|
r10189 | diffopts.upgrade = False | ||
|
r35599 | elif git == b'auto': | ||
|
r10189 | diffopts.git = False | ||
diffopts.upgrade = True | ||||
|
r35599 | elif git == b'warn': | ||
|
r10189 | diffopts.git = False | ||
diffopts.upgrade = True | ||||
|
r43346 | |||
|
r10189 | def losedatafn(fn=None, **kwargs): | ||
brokenfiles.add(fn) | ||||
return True | ||||
|
r43346 | |||
|
r35599 | elif git == b'abort': | ||
|
r10189 | diffopts.git = False | ||
diffopts.upgrade = True | ||||
|
r43346 | |||
|
r10189 | def losedatafn(fn=None, **kwargs): | ||
|
r35599 | raise error.Abort(b'losing data for %s' % fn) | ||
|
r43346 | |||
|
r10189 | else: | ||
|
r35599 | raise error.Abort(b'--git must be yes, no or auto') | ||
|
r10189 | |||
|
r37275 | ctx1, ctx2 = scmutil.revpair(repo, []) | ||
m = scmutil.match(ctx2, pats, opts) | ||||
|
r43346 | it = patch.diff( | ||
repo, | ||||
ctx1.node(), | ||||
ctx2.node(), | ||||
match=m, | ||||
opts=diffopts, | ||||
losedatafn=losedatafn, | ||||
) | ||||
|
r10189 | for chunk in it: | ||
ui.write(chunk) | ||||
for fn in sorted(brokenfiles): | ||||
|
r35599 | ui.write((b'data lost for: %s\n' % fn)) | ||