Mercurial > hg
annotate tests/test-absorb-filefixupstate.py @ 44574:5205b46bd887
fix: add a -s option to format a revision and its descendants
`hg fix -r abc123` will format that commit but not its
descendants. That seems expected given the option name (`-r`), but
it's very rarely what the user wants to do. The problem is that any
descendants of that commit will not be formatted, leaving them as
orphans that are hard to evolve. They are hard to evolve because the
new parent will have formatting changes that the orphan doesn't have.
I talked to Danny Hooper (who wrote most of the fix extension) about
the problem and we agreed that deprecating `-r` in favor of a new `-s`
argument (mimicing rebase's `-s`) would be a good way of reducing the
risk that users end up with these hard-to-evolve orphans. So that's
what this patch implements.
Differential Revision: https://phab.mercurial-scm.org/D8287
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 13 Mar 2020 12:16:00 -0700 |
parents | 2372284d9457 |
children | 89a2afe31e82 |
rev | line source |
---|---|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 from __future__ import absolute_import, print_function |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 import itertools |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
4 from mercurial import pycompat |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 from hgext import absorb |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
7 |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 class simplefctx(object): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 def __init__(self, content): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 self.content = content |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 def data(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 return self.content |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
15 |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 def insertreturns(x): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
17 # insert "\n"s after each single char |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
18 if isinstance(x, bytes): |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
19 return b''.join(ch + b'\n' for ch in pycompat.bytestr(x)) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 else: |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
21 return pycompat.maplist(insertreturns, x) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
23 |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
24 def removereturns(x): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 # the revert of "insertreturns" |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
26 if isinstance(x, bytes): |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
27 return x.replace(b'\n', b'') |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 else: |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
29 return pycompat.maplist(removereturns, x) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
30 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
31 |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
32 def assertlistequal(lhs, rhs, decorator=lambda x: x): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
33 if lhs != rhs: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
34 raise RuntimeError( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
35 'mismatch:\n actual: %r\n expected: %r' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
36 % tuple(map(decorator, [lhs, rhs])) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
37 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
38 |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 def testfilefixup(oldcontents, workingcopy, expectedcontents, fixups=None): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 """([str], str, [str], [(rev, a1, a2, b1, b2)]?) -> None |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 workingcopy is a string, of which every character denotes a single line. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 oldcontents, expectedcontents are lists of strings, every character of |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 every string denots a single line. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
48 if fixups is not None, it's the expected fixups list and will be checked. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
49 """ |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
50 expectedcontents = insertreturns(expectedcontents) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
51 oldcontents = insertreturns(oldcontents) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 workingcopy = insertreturns(workingcopy) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
53 state = absorb.filefixupstate( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
54 pycompat.maplist(simplefctx, oldcontents), 'path' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
55 ) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 state.diffwith(simplefctx(workingcopy)) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
57 if fixups is not None: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
58 assertlistequal(state.fixups, fixups) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
59 state.apply() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
60 assertlistequal(state.finalcontents, expectedcontents, removereturns) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
61 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
62 |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
63 def buildcontents(linesrevs): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
64 # linesrevs: [(linecontent : str, revs : [int])] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
65 revs = set(itertools.chain(*[revs for line, revs in linesrevs])) |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
66 return [b''] + [ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
67 b''.join([l for l, rs in linesrevs if r in rs]) for r in sorted(revs) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
68 ] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
69 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
70 |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
71 # input case 0: one single commit |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
72 case0 = [b'', b'11'] |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
73 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
74 # replace a single chunk |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
75 testfilefixup(case0, b'', [b'', b'']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
76 testfilefixup(case0, b'2', [b'', b'2']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
77 testfilefixup(case0, b'22', [b'', b'22']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
78 testfilefixup(case0, b'222', [b'', b'222']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
79 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
80 # input case 1: 3 lines, each commit adds one line |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
81 case1 = buildcontents([(b'1', [1, 2, 3]), (b'2', [2, 3]), (b'3', [3]),]) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
82 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
83 # 1:1 line mapping |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
84 testfilefixup(case1, b'123', case1) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
85 testfilefixup(case1, b'12c', [b'', b'1', b'12', b'12c']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
86 testfilefixup(case1, b'1b3', [b'', b'1', b'1b', b'1b3']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
87 testfilefixup(case1, b'1bc', [b'', b'1', b'1b', b'1bc']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
88 testfilefixup(case1, b'a23', [b'', b'a', b'a2', b'a23']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
89 testfilefixup(case1, b'a2c', [b'', b'a', b'a2', b'a2c']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
90 testfilefixup(case1, b'ab3', [b'', b'a', b'ab', b'ab3']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
91 testfilefixup(case1, b'abc', [b'', b'a', b'ab', b'abc']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
92 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
93 # non 1:1 edits |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
94 testfilefixup(case1, b'abcd', case1) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
95 testfilefixup(case1, b'ab', case1) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
96 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
97 # deletion |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
98 testfilefixup(case1, b'', [b'', b'', b'', b'']) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
99 testfilefixup(case1, b'1', [b'', b'1', b'1', b'1']) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
100 testfilefixup(case1, b'2', [b'', b'', b'2', b'2']) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
101 testfilefixup(case1, b'3', [b'', b'', b'', b'3']) |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
102 testfilefixup(case1, b'13', [b'', b'1', b'1', b'13']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
103 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
104 # replaces |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
105 testfilefixup(case1, b'1bb3', [b'', b'1', b'1bb', b'1bb3']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
106 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
107 # (confusing) replaces |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
108 testfilefixup(case1, b'1bbb', case1) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
109 testfilefixup(case1, b'bbbb', case1) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
110 testfilefixup(case1, b'bbb3', case1) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
111 testfilefixup(case1, b'1b', case1) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
112 testfilefixup(case1, b'bb', case1) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
113 testfilefixup(case1, b'b3', case1) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
114 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
115 # insertions at the beginning and the end |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
116 testfilefixup(case1, b'123c', [b'', b'1', b'12', b'123c']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
117 testfilefixup(case1, b'a123', [b'', b'a1', b'a12', b'a123']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
118 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
119 # (confusing) insertions |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
120 testfilefixup(case1, b'1a23', case1) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
121 testfilefixup(case1, b'12b3', case1) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
122 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
123 # input case 2: delete in the middle |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
124 case2 = buildcontents([(b'11', [1, 2]), (b'22', [1]), (b'33', [1, 2]),]) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
125 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
126 # deletion (optimize code should make it 2 chunks) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
127 testfilefixup( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
128 case2, b'', [b'', b'22', b''], fixups=[(4, 0, 2, 0, 0), (4, 2, 4, 0, 0)] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
129 ) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
130 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
131 # 1:1 line mapping |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
132 testfilefixup(case2, b'aaaa', [b'', b'aa22aa', b'aaaa']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
133 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
134 # non 1:1 edits |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
135 # note: unlike case0, the chunk is not "continuous" and no edit allowed |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
136 testfilefixup(case2, b'aaa', case2) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
137 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
138 # input case 3: rev 3 reverts rev 2 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
139 case3 = buildcontents([(b'1', [1, 2, 3]), (b'2', [2]), (b'3', [1, 2, 3]),]) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
140 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
141 # 1:1 line mapping |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
142 testfilefixup(case3, b'13', case3) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
143 testfilefixup(case3, b'1b', [b'', b'1b', b'12b', b'1b']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
144 testfilefixup(case3, b'a3', [b'', b'a3', b'a23', b'a3']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
145 testfilefixup(case3, b'ab', [b'', b'ab', b'a2b', b'ab']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
146 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
147 # non 1:1 edits |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
148 testfilefixup(case3, b'a', case3) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
149 testfilefixup(case3, b'abc', case3) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
150 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
151 # deletion |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
152 testfilefixup(case3, b'', [b'', b'', b'2', b'']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
153 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
154 # insertion |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
155 testfilefixup(case3, b'a13c', [b'', b'a13c', b'a123c', b'a13c']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
156 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
157 # input case 4: a slightly complex case |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
158 case4 = buildcontents( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
159 [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
160 (b'1', [1, 2, 3]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
161 (b'2', [2, 3]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
162 (b'3', [1, 2,]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
163 (b'4', [1, 3]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
164 (b'5', [3]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
165 (b'6', [2, 3]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
166 (b'7', [2]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
167 (b'8', [2, 3]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
168 (b'9', [3]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
169 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
170 ) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
171 |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
172 testfilefixup(case4, b'1245689', case4) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
173 testfilefixup(case4, b'1a2456bbb', case4) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
174 testfilefixup(case4, b'1abc5689', case4) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
175 testfilefixup(case4, b'1ab5689', [b'', b'134', b'1a3678', b'1ab5689']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
176 testfilefixup(case4, b'aa2bcd8ee', [b'', b'aa34', b'aa23d78', b'aa2bcd8ee']) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
177 testfilefixup(case4, b'aa2bcdd8ee', [b'', b'aa34', b'aa23678', b'aa24568ee']) |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
178 testfilefixup(case4, b'aaaaaa', case4) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
179 testfilefixup(case4, b'aa258b', [b'', b'aa34', b'aa2378', b'aa258b']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
180 testfilefixup(case4, b'25bb', [b'', b'34', b'23678', b'25689']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
181 testfilefixup(case4, b'27', [b'', b'34', b'23678', b'245689']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
182 testfilefixup(case4, b'28', [b'', b'34', b'2378', b'28']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
183 testfilefixup(case4, b'', [b'', b'34', b'37', b'']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
184 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
185 # input case 5: replace a small chunk which is near a deleted line |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40187
diff
changeset
|
186 case5 = buildcontents([(b'12', [1, 2]), (b'3', [1]), (b'4', [1, 2]),]) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
187 |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
188 testfilefixup(case5, b'1cd4', [b'', b'1cd34', b'1cd4']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
189 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
190 # input case 6: base "changeset" is immutable |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
191 case6 = [b'1357', b'0125678'] |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
192 |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
193 testfilefixup(case6, b'0125678', case6) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
194 testfilefixup(case6, b'0a25678', case6) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
195 testfilefixup(case6, b'0a256b8', case6) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
196 testfilefixup(case6, b'abcdefg', [b'1357', b'a1c5e7g']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
197 testfilefixup(case6, b'abcdef', case6) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
198 testfilefixup(case6, b'', [b'1357', b'157']) |
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
199 testfilefixup(case6, b'0123456789', [b'1357', b'0123456789']) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
200 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
201 # input case 7: change an empty file |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
202 case7 = [b''] |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
203 |
38988
1aab0007a7c0
tests: port test-absorb-filefixupstate to Python 3
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
204 testfilefixup(case7, b'1', case7) |