tests/flagprocessorext.py
author Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
Tue, 02 Jul 2019 12:59:58 -0400
changeset 42621 99ebde4fec99
parent 41413 fad627d2047c
child 42730 92ac6b1697a7
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:
30745
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
     1
# coding=UTF-8
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
     2
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
     3
from __future__ import absolute_import
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
     4
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
     5
import base64
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
     6
import zlib
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
     7
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
     8
from mercurial import (
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
     9
    changegroup,
31832
77f746e5383a test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents: 30745
diff changeset
    10
    exchange,
30745
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    11
    extensions,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    12
    revlog,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    13
    util,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    14
)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    15
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    16
# Test only: These flags are defined here only in the context of testing the
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    17
# behavior of the flag processor. The canonical way to add flags is to get in
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    18
# touch with the community and make them known in revlog.
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    19
REVIDX_NOOP = (1 << 3)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    20
REVIDX_BASE64 = (1 << 2)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    21
REVIDX_GZIP = (1 << 1)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    22
REVIDX_FAIL = 1
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    23
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    24
def validatehash(self, text):
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    25
    return True
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    26
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    27
def bypass(self, text):
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    28
    return False
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    29
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    30
def noopdonothing(self, text):
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    31
    return (text, True)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    32
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    33
def b64encode(self, text):
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    34
    return (base64.b64encode(text), False)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    35
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    36
def b64decode(self, text):
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    37
    return (base64.b64decode(text), True)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    38
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    39
def gzipcompress(self, text):
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    40
    return (zlib.compress(text), False)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    41
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    42
def gzipdecompress(self, text):
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    43
    return (zlib.decompress(text), True)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    44
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    45
def supportedoutgoingversions(orig, repo):
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    46
    versions = orig(repo)
36114
83246d6920f2 py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35570
diff changeset
    47
    versions.discard(b'01')
83246d6920f2 py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35570
diff changeset
    48
    versions.discard(b'02')
83246d6920f2 py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35570
diff changeset
    49
    versions.add(b'03')
30745
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    50
    return versions
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    51
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    52
def allsupportedversions(orig, ui):
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    53
    versions = orig(ui)
36114
83246d6920f2 py3: use b'' for changegroup version literals
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35570
diff changeset
    54
    versions.add(b'03')
30745
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    55
    return versions
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    56
37436
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    57
def makewrappedfile(obj):
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    58
    class wrappedfile(obj.__class__):
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    59
        def addrevision(self, text, transaction, link, p1, p2,
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    60
                        cachedelta=None, node=None,
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    61
                        flags=revlog.REVIDX_DEFAULT_FLAGS):
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    62
            if b'[NOOP]' in text:
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    63
                flags |= REVIDX_NOOP
30745
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    64
37436
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    65
            if b'[BASE64]' in text:
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    66
                flags |= REVIDX_BASE64
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    67
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    68
            if b'[GZIP]' in text:
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    69
                flags |= REVIDX_GZIP
30745
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    70
37436
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    71
            # This addrevision wrapper is meant to add a flag we will not have
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    72
            # transforms registered for, ensuring we handle this error case.
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    73
            if b'[FAIL]' in text:
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    74
                flags |= REVIDX_FAIL
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    75
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    76
            return super(wrappedfile, self).addrevision(text, transaction, link,
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    77
                                                        p1, p2,
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    78
                                                        cachedelta=cachedelta,
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    79
                                                        node=node,
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    80
                                                        flags=flags)
30745
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    81
37436
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    82
    obj.__class__ = wrappedfile
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    83
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    84
def reposetup(ui, repo):
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    85
    class wrappingflagprocessorrepo(repo.__class__):
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    86
        def file(self, f):
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    87
            orig = super(wrappingflagprocessorrepo, self).file(f)
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    88
            makewrappedfile(orig)
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    89
            return orig
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    90
9d4f09bfe3ec simplestore: correctly implement flag processors
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37165
diff changeset
    91
    repo.__class__ = wrappingflagprocessorrepo
30745
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    92
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    93
def extsetup(ui):
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    94
    # Enable changegroup3 for flags to be sent over the wire
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    95
    wrapfunction = extensions.wrapfunction
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    96
    wrapfunction(changegroup,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    97
                 'supportedoutgoingversions',
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    98
                 supportedoutgoingversions)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
    99
    wrapfunction(changegroup,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   100
                 'allsupportedversions',
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   101
                 allsupportedversions)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   102
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   103
    # Teach revlog about our test flags
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   104
    flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL]
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   105
    revlog.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   106
    revlog.REVIDX_FLAGS_ORDER.extend(flags)
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   107
31832
77f746e5383a test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents: 30745
diff changeset
   108
    # Teach exchange to use changegroup 3
37165
6c7a6b04b274 bundlespec: move computing the bundle contentops in parsebundlespec
Boris Feld <boris.feld@octobus.net>
parents: 36114
diff changeset
   109
    for k in exchange._bundlespeccontentopts.keys():
41413
fad627d2047c tests: add b'' prefixes to flagprocessorext.py
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37436
diff changeset
   110
        exchange._bundlespeccontentopts[k][b"cg.version"] = b"03"
31832
77f746e5383a test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents: 30745
diff changeset
   111
30745
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   112
    # Register flag processors for each extension
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   113
    revlog.addflagprocessor(
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   114
        REVIDX_NOOP,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   115
        (
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   116
            noopdonothing,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   117
            noopdonothing,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   118
            validatehash,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   119
        )
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   120
    )
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   121
    revlog.addflagprocessor(
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   122
        REVIDX_BASE64,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   123
        (
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   124
            b64decode,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   125
            b64encode,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   126
            bypass,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   127
        ),
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   128
    )
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   129
    revlog.addflagprocessor(
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   130
        REVIDX_GZIP,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   131
        (
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   132
            gzipdecompress,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   133
            gzipcompress,
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   134
            bypass
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   135
        )
c1b7b2285522 revlog: flag processor
Remi Chaintron <remi@fb.com>
parents:
diff changeset
   136
    )