Mercurial > public > mercurial-scm > hg
diff hgext/remotefilelog/debugcommands.py @ 52636: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 | 94fa2543d710 |
children |
line wrap: on
line diff
--- a/hgext/remotefilelog/debugcommands.py Tue Jan 07 14:57:51 2025 -0500 +++ b/hgext/remotefilelog/debugcommands.py Mon Jan 06 13:29:42 2025 -0500 @@ -128,19 +128,15 @@ basehdr = b' base' if format == 0: - ui.write( - ( - b" rev offset length " + basehdr + b" linkrev" - b" nodeid p1 p2\n" - ) + ui.writenoi18n( + b" rev offset length " + basehdr + b" linkrev" + b" nodeid p1 p2\n" ) elif format == 1: - ui.write( - ( - b" rev flag offset length" - b" size " + basehdr + b" link p1 p2" - b" nodeid\n" - ) + ui.writenoi18n( + b" rev flag offset length" + b" size " + basehdr + b" link p1 p2" + b" nodeid\n" ) for i in r: @@ -307,7 +303,7 @@ for filename, node, deltabase, deltalen in dpack.iterentries(): bases[node] = deltabase if node in nodes: - ui.write((b"Bad entry: %s appears twice\n" % short(node))) + ui.writenoi18n(b"Bad entry: %s appears twice\n" % short(node)) failures += 1 nodes.add(node) if filename != lastfilename: @@ -350,7 +346,7 @@ failures += _sanitycheck(ui, set(nodes), bases) if failures > 1: - ui.warn((b"%d failures\n" % failures)) + ui.warnnoi18n(b"%d failures\n" % failures) return 1 @@ -370,21 +366,17 @@ while deltabase != sha1nodeconstants.nullid: if deltabase not in nodes: - ui.warn( - ( - b"Bad entry: %s has an unknown deltabase (%s)\n" - % (short(node), short(deltabase)) - ) + ui.warnnoi18n( + b"Bad entry: %s has an unknown deltabase (%s)\n" + % (short(node), short(deltabase)) ) failures += 1 break if deltabase in seen: - ui.warn( - ( - b"Bad entry: %s has a cycle (at %s)\n" - % (short(node), short(deltabase)) - ) + ui.warnnoi18n( + b"Bad entry: %s has a cycle (at %s)\n" + % (short(node), short(deltabase)) ) failures += 1 break