tests/testlib/ext-phase-report.py
author Matt Harbison <matt_harbison@yahoo.com>
Mon, 06 Jan 2025 13:29:42 -0500
changeset 52636 0e11e532c958
parent 48875 6000f5b25c9b
child 52643 5cc8deb96b48
permissions -rw-r--r--
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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33459
67a3204c83c1 phases: test phases tracking at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     1
# tiny extension to report phase changes during transaction
67a3204c83c1 phases: test phases tracking at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     2
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36044
diff changeset
     3
33459
67a3204c83c1 phases: test phases tracking at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     4
def reposetup(ui, repo):
67a3204c83c1 phases: test phases tracking at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
     5
    def reportphasemove(tr):
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 43076
diff changeset
     6
        for revs, move in sorted(tr.changes[b"phases"], key=lambda r: r[0][0]):
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 43076
diff changeset
     7
            for rev in revs:
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 43076
diff changeset
     8
                if move[0] is None:
52636
0e11e532c958 style: use `ui.xxxnoi18n()` methods instead of wrapping msg in `()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
     9
                    ui.writenoi18n(
0e11e532c958 style: use `ui.xxxnoi18n()` methods instead of wrapping msg in `()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
    10
                        b'test-debug-phase: new rev %d:  x -> %d\n'
0e11e532c958 style: use `ui.xxxnoi18n()` methods instead of wrapping msg in `()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
    11
                        % (rev, move[1])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36044
diff changeset
    12
                    )
44548
fdc802f29b2c transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents: 43076
diff changeset
    13
                else:
52636
0e11e532c958 style: use `ui.xxxnoi18n()` methods instead of wrapping msg in `()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
    14
                    ui.writenoi18n(
0e11e532c958 style: use `ui.xxxnoi18n()` methods instead of wrapping msg in `()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
    15
                        b'test-debug-phase: move rev %d: %d -> %d\n'
0e11e532c958 style: use `ui.xxxnoi18n()` methods instead of wrapping msg in `()`
Matt Harbison <matt_harbison@yahoo.com>
parents: 48875
diff changeset
    16
                        % (rev, move[0], move[1])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 36044
diff changeset
    17
                    )
33459
67a3204c83c1 phases: test phases tracking at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    18
67a3204c83c1 phases: test phases tracking at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    19
    class reportphaserepo(repo.__class__):
67a3204c83c1 phases: test phases tracking at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    20
        def transaction(self, *args, **kwargs):
67a3204c83c1 phases: test phases tracking at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    21
            tr = super(reportphaserepo, self).transaction(*args, **kwargs)
36044
3b4d14beac3d py3: port ext-phase-report.py extension
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33459
diff changeset
    22
            tr.addpostclose(b'report-phase', reportphasemove)
33459
67a3204c83c1 phases: test phases tracking at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    23
            return tr
67a3204c83c1 phases: test phases tracking at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    24
67a3204c83c1 phases: test phases tracking at the transaction level
Boris Feld <boris.feld@octobus.net>
parents:
diff changeset
    25
    repo.__class__ = reportphaserepo