tests/test-annotate.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Tue, 09 Apr 2024 22:37:15 +0200
changeset 51595 3a6fae3bef35
parent 48875 6000f5b25c9b
permissions -rw-r--r--
outgoing: add a simple fastpath when there is no common This further speed up case like `hg bundle --all` for larger repository. ### data-env-vars.name = mozilla-try-2023-03-22-zstd-sparse-revlog # benchmark.name = hg.command.bundle # bin-env-vars.hg.flavor = default # bin-env-vars.hg.py-re2-module = default # benchmark.variants.revs = all # benchmark.variants.type = none-streamv2 before: 316.749699 after: 311.165461 (-1.76%, -5.58) There is further work to be done in this area like not doing any outgoing computation in the stream case for example. however the recent changes already gives use a large win for a small amount of local work. ### benchmark.name = hg.command.bundle # bin-env-vars.hg.flavor = default # bin-env-vars.hg.py-re2-module = default # benchmark.variants.revs = all # benchmark.variants.type = none-streamv2 ## data-env-vars.name = mercurial-public-2024-03-22-zstd-sparse-revlog pre-%ln-change: 1.263859 the-%ln-change: 0.700229 (-44.60%, -0.56) prev-changeset: 0.496050 (-60.75%, -0.77) this-changeset: 0.495243 (-60.81%, -0.77) ## data-env-vars.name = tryton-public-2024-03-22-zstd-sparse-revlog pre-%ln-change: 2.975765 the-%ln-change: 1.870798 (-37.13%, -1.10) prev-changeset: 1.461583 (-50.88%, -1.51) this-changeset: 1.469185 (-50.63%, -1.51) ## data-env-vars.name = pypy-2024-03-22-zstd-sparse-revlog pre-%ln-change: 4.540080 the-%ln-change: 3.401700 (-25.07%, -1.14) prev-changeset: 2.915810 (-35.78%, -1.62) this-changeset: 2.911643 (-35.87%, -1.63) ## data-env-vars.name = heptapod-public-2024-03-25-zstd-sparse-revlog pre-%ln-change: 10.138396 the-%ln-change: 7.750458 (-23.55%, -2.39) prev-changeset: 6.665565 (-34.25%, -3.47) this-changeset: 6.672078 (-34.19%, -3.47) ## data-env-vars.name = mozilla-try-2023-03-22-zstd-sparse-revlog pre-%ln-change: 399.484481 the-%ln-change: 346.508952 (-13.26%, -52.98) prev-changeset: 316.749699 (-20.71%, -82.73) this-changeset: 311.165461 (-22.11%, -88.32)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     1
import unittest
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     2
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     3
from mercurial import (
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     4
    mdiff,
37064
434e520adb8c annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents: 36935
diff changeset
     5
    pycompat,
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     6
)
36917
7affcabf561e dagop: move annotateline and _annotatepair from context.py
Yuya Nishihara <yuya@tcha.org>
parents: 35947
diff changeset
     7
from mercurial.dagop import (
34432
2e32c6a31cc7 annotate: introduce attr for storing per-line annotate data
Siddharth Agarwal <sid0@fb.com>
parents: 34430
diff changeset
     8
    annotateline,
37064
434e520adb8c annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents: 36935
diff changeset
     9
    _annotatedfile,
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    10
    _annotatepair,
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    11
)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    12
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    13
37064
434e520adb8c annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents: 36935
diff changeset
    14
def tr(a):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    15
    return [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    16
        annotateline(fctx, lineno, skip)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    17
        for fctx, lineno, skip in zip(a.fctxs, a.linenos, a.skips)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    18
    ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    19
37064
434e520adb8c annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents: 36935
diff changeset
    20
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    21
class AnnotateTests(unittest.TestCase):
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    22
    """Unit tests for annotate code."""
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    23
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    24
    def testannotatepair(self):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    25
        self.maxDiff = None  # camelcase-required
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    26
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    27
        oldfctx = b'old'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    28
        p1fctx, p2fctx, childfctx = b'p1', b'p2', b'c'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    29
        olddata = b'a\nb\n'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    30
        p1data = b'a\nb\nc\n'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    31
        p2data = b'a\nc\nd\n'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    32
        childdata = b'a\nb2\nc\nc2\nd\n'
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    33
        diffopts = mdiff.diffopts()
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    34
36935
ec46b0ee2e3c annotate: correct parameter name of decorate() function
Yuya Nishihara <yuya@tcha.org>
parents: 36917
diff changeset
    35
        def decorate(text, fctx):
37064
434e520adb8c annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents: 36935
diff changeset
    36
            n = text.count(b'\n')
434e520adb8c annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents: 36935
diff changeset
    37
            linenos = pycompat.rangelist(1, n + 1)
434e520adb8c annotate: do not construct attr.s object per line while computing history
Yuya Nishihara <yuya@tcha.org>
parents: 36935
diff changeset
    38
            return _annotatedfile([fctx] * n, linenos, [False] * n, text)
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    39
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    40
        # Basic usage
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    41
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    42
        oldann = decorate(olddata, oldfctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    43
        p1ann = decorate(p1data, p1fctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    44
        p1ann = _annotatepair([oldann], p1fctx, p1ann, False, diffopts)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    45
        self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    46
            tr(p1ann),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    47
            [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    48
                annotateline(b'old', 1),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    49
                annotateline(b'old', 2),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    50
                annotateline(b'p1', 3),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    51
            ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    52
        )
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    53
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    54
        p2ann = decorate(p2data, p2fctx)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    55
        p2ann = _annotatepair([oldann], p2fctx, p2ann, False, diffopts)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    56
        self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    57
            tr(p2ann),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    58
            [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    59
                annotateline(b'old', 1),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    60
                annotateline(b'p2', 2),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    61
                annotateline(b'p2', 3),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    62
            ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    63
        )
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    64
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    65
        # Test with multiple parents (note the difference caused by ordering)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    66
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    67
        childann = decorate(childdata, childfctx)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    68
        childann = _annotatepair(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    69
            [p1ann, p2ann], childfctx, childann, False, diffopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    70
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    71
        self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    72
            tr(childann),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    73
            [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    74
                annotateline(b'old', 1),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    75
                annotateline(b'c', 2),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    76
                annotateline(b'p2', 2),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    77
                annotateline(b'c', 4),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    78
                annotateline(b'p2', 3),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    79
            ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    80
        )
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    81
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    82
        childann = decorate(childdata, childfctx)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    83
        childann = _annotatepair(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    84
            [p2ann, p1ann], childfctx, childann, False, diffopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    85
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    86
        self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    87
            tr(childann),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    88
            [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    89
                annotateline(b'old', 1),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    90
                annotateline(b'c', 2),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    91
                annotateline(b'p1', 3),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    92
                annotateline(b'c', 4),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    93
                annotateline(b'p2', 3),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    94
            ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
    95
        )
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    96
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    97
        # Test with skipchild (note the difference caused by ordering)
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    98
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    99
        childann = decorate(childdata, childfctx)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   100
        childann = _annotatepair(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   101
            [p1ann, p2ann], childfctx, childann, True, diffopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   102
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   103
        self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   104
            tr(childann),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   105
            [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   106
                annotateline(b'old', 1),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   107
                annotateline(b'old', 2, True),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   108
                # note that this line was carried over from earlier so it is *not*
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   109
                # marked skipped
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   110
                annotateline(b'p2', 2),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   111
                annotateline(b'p2', 2, True),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   112
                annotateline(b'p2', 3),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   113
            ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   114
        )
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
   115
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
   116
        childann = decorate(childdata, childfctx)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   117
        childann = _annotatepair(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   118
            [p2ann, p1ann], childfctx, childann, True, diffopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   119
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   120
        self.assertEqual(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   121
            tr(childann),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   122
            [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   123
                annotateline(b'old', 1),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   124
                annotateline(b'old', 2, True),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   125
                annotateline(b'p1', 3),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   126
                annotateline(b'p1', 3, True),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   127
                annotateline(b'p2', 3),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   128
            ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   129
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   130
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
   131
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
   132
if __name__ == '__main__':
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
   133
    import silenttestrunner
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 37064
diff changeset
   134
34430
80215865d154 annotate: move annotatepair unit tests to a separate file
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
   135
    silenttestrunner.main(__name__)