Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/debugcommands.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 | cac851655570 |
children | 73ab542565e0 |
comparison
equal
deleted
inserted
replaced
52660:cdfaba964f21 | 52661:0e11e532c958 |
---|---|
262 nodeids = [] | 262 nodeids = [] |
263 id = 0 | 263 id = 0 |
264 progress.update(id) | 264 progress.update(id) |
265 for type, data in dagparser.parsedag(text): | 265 for type, data in dagparser.parsedag(text): |
266 if type == b'n': | 266 if type == b'n': |
267 ui.note((b'node %s\n' % pycompat.bytestr(data))) | 267 ui.notenoi18n(b'node %s\n' % pycompat.bytestr(data)) |
268 id, ps = data | 268 id, ps = data |
269 | 269 |
270 files = [] | 270 files = [] |
271 filecontent = {} | 271 filecontent = {} |
272 | 272 |
343 nodeid = repo.commitctx(cx) | 343 nodeid = repo.commitctx(cx) |
344 nodeids.append(nodeid) | 344 nodeids.append(nodeid) |
345 at = id | 345 at = id |
346 elif type == b'l': | 346 elif type == b'l': |
347 id, name = data | 347 id, name = data |
348 ui.note((b'tag %s\n' % name)) | 348 ui.notenoi18n(b'tag %s\n' % name) |
349 tags.append(b"%s %s\n" % (hex(repo.changelog.node(id)), name)) | 349 tags.append(b"%s %s\n" % (hex(repo.changelog.node(id)), name)) |
350 elif type == b'a': | 350 elif type == b'a': |
351 ui.note((b'branch %s\n' % data)) | 351 ui.notenoi18n(b'branch %s\n' % data) |
352 atbranch = data | 352 atbranch = data |
353 progress.update(id) | 353 progress.update(id) |
354 | 354 |
355 if tags: | 355 if tags: |
356 repo.vfs.write(b"localtags", b"".join(tags)) | 356 repo.vfs.write(b"localtags", b"".join(tags)) |
440 | 440 |
441 def _debugbundle2(ui, gen, all=None, **opts): | 441 def _debugbundle2(ui, gen, all=None, **opts): |
442 """lists the contents of a bundle2""" | 442 """lists the contents of a bundle2""" |
443 if not isinstance(gen, bundle2.unbundle20): | 443 if not isinstance(gen, bundle2.unbundle20): |
444 raise error.Abort(_(b'not a bundle2 file')) | 444 raise error.Abort(_(b'not a bundle2 file')) |
445 ui.write((b'Stream params: %s\n' % _quasirepr(gen.params))) | 445 ui.writenoi18n(b'Stream params: %s\n' % _quasirepr(gen.params)) |
446 parttypes = opts.get('part_type', []) | 446 parttypes = opts.get('part_type', []) |
447 for part in gen.iterparts(): | 447 for part in gen.iterparts(): |
448 if parttypes and part.type not in parttypes: | 448 if parttypes and part.type not in parttypes: |
449 continue | 449 continue |
450 msg = b'%s -- %s (mandatory: %r)\n' | 450 msg = b'%s -- %s (mandatory: %r)\n' |
451 ui.write((msg % (part.type, _quasirepr(part.params), part.mandatory))) | 451 ui.writenoi18n( |
452 msg % (part.type, _quasirepr(part.params), part.mandatory) | |
453 ) | |
452 if part.type == b'changegroup': | 454 if part.type == b'changegroup': |
453 version = part.params.get(b'version', b'01') | 455 version = part.params.get(b'version', b'01') |
454 cg = changegroup.getunbundler(version, part, b'UN') | 456 cg = changegroup.getunbundler(version, part, b'UN') |
455 if not ui.quiet: | 457 if not ui.quiet: |
456 _debugchangegroup(ui, cg, all=all, indent=4, **opts) | 458 _debugchangegroup(ui, cg, all=all, indent=4, **opts) |