tests/test-revlog-ancestry.py
author Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
Tue, 02 Jul 2019 12:59:58 -0400
changeset 42621 99ebde4fec99
parent 40366 b14fdf1fb615
child 43076 2372284d9457
permissions -rw-r--r--
commit: improve the files field of changelog for merges Currently, the files list of merge commits repeats all the deletions (either actual deletions, or files that got renamed) that happened between base and p2 of the merge. If p2 is the main branch, the list can easily be much bigger than the change being merged. This results in various problems worth improving: - changelog is bigger than necessary - `hg log directory` lists many unrelated merge commits, and `hg log -v -r commit` frequently fills multiple screens worth of files - it possibly slows down adjustlinkrev, by forcing it to read more manifests, and that function can certainly be a bottleneck - the server side of pulls can waste a lot of time simply opening the filelogs for pointless files (the constant factors for opening even a tiny filelog is apparently pretty bad) So stop listing such files as described in the code. Impacted merge commits and their descendants get a different hash than they would have without this. This doesn't seem problematic, except for convert. The previous commit helped with that in the hg->hg case (but if you do svn->hg twice from scratch, hashes can still change). The rest of the description is numbers. I don't have much to report, because recreating the files list of existing repositories is not easy: - debugupgradeformat and bundle/unbundle don't recreate the list - export/import tends to choke quickly applying patches or on description that contain diffs, - merge commits from the convert extension don't have the right files list for reasons orthogonal to the current commit - replaying the merge with hg update/hg merge/hg revert --all/hg commit can end up failing in hg revert - I wasn't sure that using debugsetparents + debugrebuilddirstate would really build the right thing I measured commit time before and after this change, in a case with no files filtered out, several files filtered out (no difference) and 5k files filtered out (+1% time). Recreating the 100 more recent merges in a private repo, the concatenated uncompressed files lists goes from 1.12MB to 0.52MB. Excluding 3 merges that are not representative, then the size goes from 570k to 15k. I converted part of mozilla-central, and observed file list shrinking quite a bit too, starting at the very first merge, 733641d9feaf, going from 550 files to 10 files (although they have relatively few merges, so they probably wouldn't care). Differential Revision: https://phab.mercurial-scm.org/D6613
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
     1
from __future__ import absolute_import, print_function
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
     2
import os
28763
abe605bbf0de py3: use absolute_import in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 27344
diff changeset
     3
from mercurial import (
abe605bbf0de py3: use absolute_import in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 27344
diff changeset
     4
    hg,
abe605bbf0de py3: use absolute_import in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 27344
diff changeset
     5
    merge,
28842
d466facc5a6e tests: alias ui as uimod in test-revlog-ancestry/test-ui-verbosity
Yuya Nishihara <yuya@tcha.org>
parents: 28764
diff changeset
     6
    ui as uimod,
28763
abe605bbf0de py3: use absolute_import in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 27344
diff changeset
     7
)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
     8
30564
d83ca854fa21 ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 28842
diff changeset
     9
u = uimod.ui.load()
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    10
36512
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    11
repo = hg.repository(u, b'test1', create=1)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    12
os.chdir('test1')
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    13
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    14
def commit(text, time):
36512
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    15
    repo.commit(text=text, date=b"%d 0" % time)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    16
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    17
def addcommit(name, time):
36513
5a029f049854 py3: make sure we open the file in bytes mode
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36512
diff changeset
    18
    f = open(name, 'wb')
36512
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    19
    f.write(b'%s\n' % name)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    20
    f.close()
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9031
diff changeset
    21
    repo[None].add([name])
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    22
    commit(name, time)
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    23
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    24
def update(rev):
40366
b14fdf1fb615 update: clarify update() call sites by specifying argument names
Martin von Zweigbergk <martinvonz@google.com>
parents: 36513
diff changeset
    25
    merge.update(repo, rev, branchmerge=False, force=True)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    26
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    27
def merge_(rev):
40366
b14fdf1fb615 update: clarify update() call sites by specifying argument names
Martin von Zweigbergk <martinvonz@google.com>
parents: 36513
diff changeset
    28
    merge.update(repo, rev, branchmerge=True, force=False)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    29
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    30
if __name__ == '__main__':
36512
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    31
    addcommit(b"A", 0)
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    32
    addcommit(b"B", 1)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    33
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    34
    update(0)
36512
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    35
    addcommit(b"C", 2)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    36
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    37
    merge_(1)
36512
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    38
    commit(b"D", 3)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    39
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    40
    update(2)
36512
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    41
    addcommit(b"E", 4)
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    42
    addcommit(b"F", 5)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    43
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    44
    update(3)
36512
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    45
    addcommit(b"G", 6)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    46
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    47
    merge_(5)
36512
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    48
    commit(b"H", 7)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    49
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    50
    update(5)
36512
14d2371216ba py3: add b'' prefixes in tests/test-revlog-ancestry.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30564
diff changeset
    51
    addcommit(b"I", 8)
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    52
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    53
    # Ancestors
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    54
    print('Ancestors of 5')
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 11303
diff changeset
    55
    for r in repo.changelog.ancestors([5]):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    56
        print(r, end=' ')
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    57
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    58
    print('\nAncestors of 6 and 5')
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 11303
diff changeset
    59
    for r in repo.changelog.ancestors([6, 5]):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    60
        print(r, end=' ')
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    61
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    62
    print('\nAncestors of 5 and 4')
16866
91f3ac205816 revlog: ancestors(*revs) becomes ancestors(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 11303
diff changeset
    63
    for r in repo.changelog.ancestors([5, 4]):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    64
        print(r, end=' ')
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    65
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    66
    print('\nAncestors of 7, stop at 6')
16868
eb88ed4269c5 revlog: add optional stoprev arg to revlog.ancestors()
Joshua Redstone <joshua.redstone@fb.com>
parents: 16867
diff changeset
    67
    for r in repo.changelog.ancestors([7], 6):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    68
        print(r, end=' ')
16868
eb88ed4269c5 revlog: add optional stoprev arg to revlog.ancestors()
Joshua Redstone <joshua.redstone@fb.com>
parents: 16867
diff changeset
    69
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    70
    print('\nAncestors of 7, including revs')
18081
f88c60e740a1 revlog.ancestors: add support for including revs
Siddharth Agarwal <sid0@fb.com>
parents: 16868
diff changeset
    71
    for r in repo.changelog.ancestors([7], inclusive=True):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    72
        print(r, end=' ')
18081
f88c60e740a1 revlog.ancestors: add support for including revs
Siddharth Agarwal <sid0@fb.com>
parents: 16868
diff changeset
    73
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    74
    print('\nAncestors of 7, 5 and 3, including revs')
18081
f88c60e740a1 revlog.ancestors: add support for including revs
Siddharth Agarwal <sid0@fb.com>
parents: 16868
diff changeset
    75
    for r in repo.changelog.ancestors([7, 5, 3], inclusive=True):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    76
        print(r, end=' ')
18081
f88c60e740a1 revlog.ancestors: add support for including revs
Siddharth Agarwal <sid0@fb.com>
parents: 16868
diff changeset
    77
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    78
    # Descendants
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    79
    print('\n\nDescendants of 5')
16867
1093ad1e8903 revlog: descendants(*revs) becomes descendants(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16866
diff changeset
    80
    for r in repo.changelog.descendants([5]):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    81
        print(r, end=' ')
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    82
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    83
    print('\nDescendants of 5 and 3')
16867
1093ad1e8903 revlog: descendants(*revs) becomes descendants(revs) (API)
Bryan O'Sullivan <bryano@fb.com>
parents: 16866
diff changeset
    84
    for r in repo.changelog.descendants([5, 3]):
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    85
        print(r, end=' ')
6872
c7cc40fd74f6 Add ancestors and descendants to revlog
Stefano Tortarolo <stefano.tortarolo@gmail.com>
parents:
diff changeset
    86
28764
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    87
    print('\nDescendants of 5 and 4')
e677b8daeb3f py3: use print_function in test-revlog-ancestry.py
Robert Stanca <robert.stanca7@gmail.com>
parents: 28763
diff changeset
    88
    print(*repo.changelog.descendants([5, 4]), sep=' ')