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