Mercurial > hg
view tests/test-absorb-filefixupstate.py @ 43252:32187ae9eeb3
copies: simplify the handling of merges
Instead of stacking copies for both parent on the head, we move copies outside
of the heap into a dedicated dictionary. The two side of merge can we merged
sooner, making the algorithm simpler.
This simplicity reflect in the heap structure and speed up the execution for
copies involving a large amount of merges.
Here are timing for perfpathcopies of multiple revision pairs.
- filelog: timing using filelog (with the introrev condition dropped)
- base: this series base
- before: the parent of this changeset
- after: this changeset
revision: large amount; added files: large amount; rename small amount; c3b14617fbd7 9ba6ab77fd29
filelog: ! wall 3.679613 comb 3.680000 user 3.580000 sys 0.100000 (median of 3)
base: ! wall 8.884369 comb 8.880000 user 8.850000 sys 0.030000 (median of 3)
before: ! wall 8.443747 comb 8.420000 user 8.410000 sys 0.010000 (median of 3)
after: ! wall 4.697917 comb 4.690000 user 4.660000 sys 0.030000 (median of 3)
revision: large amount; added files: small amount; rename small amount; c3b14617fbd7 f650a9b140d2
filelog: ! wall 0.003357 comb 0.010000 user 0.010000 sys 0.000000 (median of 781)
base: ! wall 12.398524 comb 12.400000 user 12.330000 sys 0.070000 (median of 3)
before: ! wall 10.852593 comb 10.850000 user 10.800000 sys 0.050000 (median of 3)
after: ! wall 6.750832 comb 6.750000 user 6.640000 sys 0.110000 (median of 3)
revision: large amount; added files: large amount; rename large amount; 08ea3258278e d9fa043f30c0
filelog: ! wall 2.754687 comb 2.760000 user 2.650000 sys 0.110000 (median of 4)
base: ! wall 1.423166 comb 1.420000 user 1.400000 sys 0.020000 (median of 8)
before: ! wall 1.068041 comb 1.060000 user 1.050000 sys 0.010000 (median of 10)
after: ! wall 1.045916 comb 1.050000 user 1.040000 sys 0.010000 (median of 10)
revision: small amount; added files: large amount; rename large amount; df6f7a526b60 a83dc6a2d56f
filelog: ! wall 1.552293 comb 1.550000 user 1.510000 sys 0.040000 (median of 6
base: ! wall 0.022662 comb 0.020000 user 0.020000 sys 0.000000 (median of 128)
before: ! wall 0.021111 comb 0.020000 user 0.020000 sys 0.000000 (median of 139)
after: ! wall 0.021577 comb 0.020000 user 0.020000 sys 0.000000 (median of 138)
revision: small amount; added files: large amount; rename small amount; 4aa4e1f8e19a 169138063d63
filelog: ! wall 1.500983 comb 1.500000 user 1.420000 sys 0.080000 (median of 7)
base: ! wall 0.006956 comb 0.010000 user 0.010000 sys 0.000000 (median of 392)
before: ! wall 0.004356 comb 0.010000 user 0.010000 sys 0.000000 (median of 675)
after: ! wall 0.004329 comb 0.000000 user 0.000000 sys 0.000000 (median of 682)
revision: small amount; added files: small amount; rename small amount; 4bc173b045a6 964879152e2e
filelog: ! wall 0.011745 comb 0.020000 user 0.020000 sys 0.000000 (median of 250)
base: ! wall 0.000156 comb 0.000000 user 0.000000 sys 0.000000 (median of 17180)
before: ! wall 0.000100 comb 0.000000 user 0.000000 sys 0.000000 (median of 26912)
after: ! wall 0.000105 comb 0.000000 user 0.000000 sys 0.000000 (median of 25689)
revision: medium amount; added files: large amount; rename medium amount; c95f1ced15f2 2c68e87c3efe
filelog: ! wall 3.228230 comb 3.230000 user 3.110000 sys 0.120000 (median of 4)
base: ! wall 0.997640 comb 1.000000 user 0.980000 sys 0.020000 (median of 10)
before: ! wall 0.778291 comb 0.780000 user 0.780000 sys 0.000000 (median of 13)
after: ! wall 0.706594 comb 0.710000 user 0.710000 sys 0.000000 (median of 15)
revision: medium amount; added files: medium amount; rename small amount; d343da0c55a8 d7746d32bf9d
filelog: ! wall 1.052501 comb 1.060000 user 1.040000 sys 0.020000 (median of 10
base: ! wall 0.214519 comb 0.220000 user 0.220000 sys 0.000000 (median of 45)
before: ! wall 0.160804 comb 0.160000 user 0.160000 sys 0.000000 (median of 62)
after: ! wall 0.163736 comb 0.160000 user 0.160000 sys 0.000000 (median of 60)
Differential Revision: https://phab.mercurial-scm.org/D7069
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 02 Oct 2019 13:43:27 -0400 |
parents | 2372284d9457 |
children | 89a2afe31e82 |
line wrap: on
line source
from __future__ import absolute_import, print_function import itertools from mercurial import pycompat from hgext import absorb class simplefctx(object): def __init__(self, content): self.content = content def data(self): return self.content def insertreturns(x): # insert "\n"s after each single char if isinstance(x, bytes): return b''.join(ch + b'\n' for ch in pycompat.bytestr(x)) else: return pycompat.maplist(insertreturns, x) def removereturns(x): # the revert of "insertreturns" if isinstance(x, bytes): return x.replace(b'\n', b'') else: return pycompat.maplist(removereturns, x) def assertlistequal(lhs, rhs, decorator=lambda x: x): if lhs != rhs: raise RuntimeError( 'mismatch:\n actual: %r\n expected: %r' % tuple(map(decorator, [lhs, rhs])) ) def testfilefixup(oldcontents, workingcopy, expectedcontents, fixups=None): """([str], str, [str], [(rev, a1, a2, b1, b2)]?) -> None workingcopy is a string, of which every character denotes a single line. oldcontents, expectedcontents are lists of strings, every character of every string denots a single line. if fixups is not None, it's the expected fixups list and will be checked. """ expectedcontents = insertreturns(expectedcontents) oldcontents = insertreturns(oldcontents) workingcopy = insertreturns(workingcopy) state = absorb.filefixupstate( pycompat.maplist(simplefctx, oldcontents), 'path' ) state.diffwith(simplefctx(workingcopy)) if fixups is not None: assertlistequal(state.fixups, fixups) state.apply() assertlistequal(state.finalcontents, expectedcontents, removereturns) def buildcontents(linesrevs): # linesrevs: [(linecontent : str, revs : [int])] revs = set(itertools.chain(*[revs for line, revs in linesrevs])) return [b''] + [ b''.join([l for l, rs in linesrevs if r in rs]) for r in sorted(revs) ] # input case 0: one single commit case0 = [b'', b'11'] # replace a single chunk testfilefixup(case0, b'', [b'', b'']) testfilefixup(case0, b'2', [b'', b'2']) testfilefixup(case0, b'22', [b'', b'22']) testfilefixup(case0, b'222', [b'', b'222']) # input case 1: 3 lines, each commit adds one line case1 = buildcontents([(b'1', [1, 2, 3]), (b'2', [2, 3]), (b'3', [3]),]) # 1:1 line mapping testfilefixup(case1, b'123', case1) testfilefixup(case1, b'12c', [b'', b'1', b'12', b'12c']) testfilefixup(case1, b'1b3', [b'', b'1', b'1b', b'1b3']) testfilefixup(case1, b'1bc', [b'', b'1', b'1b', b'1bc']) testfilefixup(case1, b'a23', [b'', b'a', b'a2', b'a23']) testfilefixup(case1, b'a2c', [b'', b'a', b'a2', b'a2c']) testfilefixup(case1, b'ab3', [b'', b'a', b'ab', b'ab3']) testfilefixup(case1, b'abc', [b'', b'a', b'ab', b'abc']) # non 1:1 edits testfilefixup(case1, b'abcd', case1) testfilefixup(case1, b'ab', case1) # deletion testfilefixup(case1, b'', [b'', b'', b'', b'']) testfilefixup(case1, b'1', [b'', b'1', b'1', b'1']) testfilefixup(case1, b'2', [b'', b'', b'2', b'2']) testfilefixup(case1, b'3', [b'', b'', b'', b'3']) testfilefixup(case1, b'13', [b'', b'1', b'1', b'13']) # replaces testfilefixup(case1, b'1bb3', [b'', b'1', b'1bb', b'1bb3']) # (confusing) replaces testfilefixup(case1, b'1bbb', case1) testfilefixup(case1, b'bbbb', case1) testfilefixup(case1, b'bbb3', case1) testfilefixup(case1, b'1b', case1) testfilefixup(case1, b'bb', case1) testfilefixup(case1, b'b3', case1) # insertions at the beginning and the end testfilefixup(case1, b'123c', [b'', b'1', b'12', b'123c']) testfilefixup(case1, b'a123', [b'', b'a1', b'a12', b'a123']) # (confusing) insertions testfilefixup(case1, b'1a23', case1) testfilefixup(case1, b'12b3', case1) # input case 2: delete in the middle case2 = buildcontents([(b'11', [1, 2]), (b'22', [1]), (b'33', [1, 2]),]) # deletion (optimize code should make it 2 chunks) testfilefixup( case2, b'', [b'', b'22', b''], fixups=[(4, 0, 2, 0, 0), (4, 2, 4, 0, 0)] ) # 1:1 line mapping testfilefixup(case2, b'aaaa', [b'', b'aa22aa', b'aaaa']) # non 1:1 edits # note: unlike case0, the chunk is not "continuous" and no edit allowed testfilefixup(case2, b'aaa', case2) # input case 3: rev 3 reverts rev 2 case3 = buildcontents([(b'1', [1, 2, 3]), (b'2', [2]), (b'3', [1, 2, 3]),]) # 1:1 line mapping testfilefixup(case3, b'13', case3) testfilefixup(case3, b'1b', [b'', b'1b', b'12b', b'1b']) testfilefixup(case3, b'a3', [b'', b'a3', b'a23', b'a3']) testfilefixup(case3, b'ab', [b'', b'ab', b'a2b', b'ab']) # non 1:1 edits testfilefixup(case3, b'a', case3) testfilefixup(case3, b'abc', case3) # deletion testfilefixup(case3, b'', [b'', b'', b'2', b'']) # insertion testfilefixup(case3, b'a13c', [b'', b'a13c', b'a123c', b'a13c']) # input case 4: a slightly complex case case4 = buildcontents( [ (b'1', [1, 2, 3]), (b'2', [2, 3]), (b'3', [1, 2,]), (b'4', [1, 3]), (b'5', [3]), (b'6', [2, 3]), (b'7', [2]), (b'8', [2, 3]), (b'9', [3]), ] ) testfilefixup(case4, b'1245689', case4) testfilefixup(case4, b'1a2456bbb', case4) testfilefixup(case4, b'1abc5689', case4) testfilefixup(case4, b'1ab5689', [b'', b'134', b'1a3678', b'1ab5689']) testfilefixup(case4, b'aa2bcd8ee', [b'', b'aa34', b'aa23d78', b'aa2bcd8ee']) testfilefixup(case4, b'aa2bcdd8ee', [b'', b'aa34', b'aa23678', b'aa24568ee']) testfilefixup(case4, b'aaaaaa', case4) testfilefixup(case4, b'aa258b', [b'', b'aa34', b'aa2378', b'aa258b']) testfilefixup(case4, b'25bb', [b'', b'34', b'23678', b'25689']) testfilefixup(case4, b'27', [b'', b'34', b'23678', b'245689']) testfilefixup(case4, b'28', [b'', b'34', b'2378', b'28']) testfilefixup(case4, b'', [b'', b'34', b'37', b'']) # input case 5: replace a small chunk which is near a deleted line case5 = buildcontents([(b'12', [1, 2]), (b'3', [1]), (b'4', [1, 2]),]) testfilefixup(case5, b'1cd4', [b'', b'1cd34', b'1cd4']) # input case 6: base "changeset" is immutable case6 = [b'1357', b'0125678'] testfilefixup(case6, b'0125678', case6) testfilefixup(case6, b'0a25678', case6) testfilefixup(case6, b'0a256b8', case6) testfilefixup(case6, b'abcdefg', [b'1357', b'a1c5e7g']) testfilefixup(case6, b'abcdef', case6) testfilefixup(case6, b'', [b'1357', b'157']) testfilefixup(case6, b'0123456789', [b'1357', b'0123456789']) # input case 7: change an empty file case7 = [b''] testfilefixup(case7, b'1', case7)