tests/flagprocessorext.py
author Yuya Nishihara <yuya@tcha.org>
Sat, 18 Aug 2018 10:33:03 +0900
branchstable
changeset 39193 cee9043c7dba
parent 37436 9d4f09bfe3ec
child 41413 fad627d2047c
permissions -rw-r--r--
perf: fix typo in perfphasesremote()
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():
6c7a6b04b274 bundlespec: move computing the bundle contentops in parsebundlespec
Boris Feld <boris.feld@octobus.net>
parents: 36114
diff changeset
   110
        exchange._bundlespeccontentopts[k]["cg.version"] = "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
    )