Mercurial > public > mercurial-scm > hg-stable
view tests/autodiff.py @ 52661:0e11e532c958
style: use `ui.xxxnoi18n()` methods instead of wrapping msg in `()`
These aliases were introduced back in 5209fc94b982, because `black` was going to
strip away the extra parentheses, but they're needed to subvert `test-check-code.t`.
That obviously changed at some point, but `pyupgrade`[1] also strips these out.
While that tool is very useful in adapting code to modern standards, it lacks
the ability to turn off most conversions, so constantly reverting these is a
pain.
Even without that, the code is more understandable with an explicit declaration.
It also would have been an easy typo to miss the leading `_` in the i18n method
`_()` that the checker is looking for, and fail to detect the problem.
The `contrib/perf.py` code just uses a local alias to the original methods
because (IIUC), this tries to be compatible with old versions of hg. But
practically, these noi18n aliases were added before useful py3 support, and at
some point, it won't be feasible to do py2 benchmarking anymore, and maybe this
module can be cleaned up some.
[1] https://github.com/asottile/pyupgrade
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 06 Jan 2025 13:29:42 -0500 |
parents | 6000f5b25c9b |
children |
line wrap: on
line source
# Extension dedicated to test patch.diff() upgrade modes from mercurial import ( error, logcmdutil, patch, pycompat, registrar, scmutil, ) cmdtable = {} command = registrar.command(cmdtable) @command( b'autodiff', [(b'', b'git', b'', b'git upgrade mode (yes/no/auto/warn/abort)')], b'[OPTION]... [FILE]...', ) def autodiff(ui, repo, *pats, **opts): opts = pycompat.byteskwargs(opts) diffopts = patch.difffeatureopts(ui, opts) git = opts.get(b'git', b'no') brokenfiles = set() losedatafn = None if git in (b'yes', b'no'): diffopts.git = git == b'yes' diffopts.upgrade = False elif git == b'auto': diffopts.git = False diffopts.upgrade = True elif git == b'warn': diffopts.git = False diffopts.upgrade = True def losedatafn(fn=None, **kwargs): brokenfiles.add(fn) return True elif git == b'abort': diffopts.git = False diffopts.upgrade = True def losedatafn(fn=None, **kwargs): raise error.Abort(b'losing data for %s' % fn) else: raise error.Abort(b'--git must be yes, no or auto') ctx1, ctx2 = logcmdutil.revpair(repo, []) m = scmutil.match(ctx2, pats, opts) it = patch.diff( repo, ctx1.node(), ctx2.node(), match=m, opts=diffopts, losedatafn=losedatafn, ) for chunk in it: ui.write(chunk) for fn in sorted(brokenfiles): ui.writenoi18n(b'data lost for: %s\n' % fn)