Mercurial > hg
annotate tests/flagprocessorext.py @ 39770:7aa440222323
localrepo: enable ellipsis flag on revlogs when repo is narrow
If the narrow requirement is present, revlogs created for that
repository will have the ellipsis flag enabled.
This is the same behavior that the narrow extension exhibits. Except
the ellipsis flag won't be enabled on repos/revlogs that don't have
the narrow requirement.
Differential Revision: https://phab.mercurial-scm.org/D4648
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 13 Sep 2018 15:57:18 -0700 |
parents | 9d4f09bfe3ec |
children | fad627d2047c |
rev | line source |
---|---|
30745 | 1 # coding=UTF-8 |
2 | |
3 from __future__ import absolute_import | |
4 | |
5 import base64 | |
6 import zlib | |
7 | |
8 from mercurial import ( | |
9 changegroup, | |
31832
77f746e5383a
test-flagprocessor: use changegroup3 in bundle2
Jun Wu <quark@fb.com>
parents:
30745
diff
changeset
|
10 exchange, |
30745 | 11 extensions, |
12 revlog, | |
13 util, | |
14 ) | |
15 | |
16 # Test only: These flags are defined here only in the context of testing the | |
17 # behavior of the flag processor. The canonical way to add flags is to get in | |
18 # touch with the community and make them known in revlog. | |
19 REVIDX_NOOP = (1 << 3) | |
20 REVIDX_BASE64 = (1 << 2) | |
21 REVIDX_GZIP = (1 << 1) | |
22 REVIDX_FAIL = 1 | |
23 | |
24 def validatehash(self, text): | |
25 return True | |
26 | |
27 def bypass(self, text): | |
28 return False | |
29 | |
30 def noopdonothing(self, text): | |
31 return (text, True) | |
32 | |
33 def b64encode(self, text): | |
34 return (base64.b64encode(text), False) | |
35 | |
36 def b64decode(self, text): | |
37 return (base64.b64decode(text), True) | |
38 | |
39 def gzipcompress(self, text): | |
40 return (zlib.compress(text), False) | |
41 | |
42 def gzipdecompress(self, text): | |
43 return (zlib.decompress(text), True) | |
44 | |
45 def supportedoutgoingversions(orig, repo): | |
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 | 50 return versions |
51 | |
52 def allsupportedversions(orig, ui): | |
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 | 55 return versions |
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 | 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 | 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 | 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 | 92 |
93 def extsetup(ui): | |
94 # Enable changegroup3 for flags to be sent over the wire | |
95 wrapfunction = extensions.wrapfunction | |
96 wrapfunction(changegroup, | |
97 'supportedoutgoingversions', | |
98 supportedoutgoingversions) | |
99 wrapfunction(changegroup, | |
100 'allsupportedversions', | |
101 allsupportedversions) | |
102 | |
103 # Teach revlog about our test flags | |
104 flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL] | |
105 revlog.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags) | |
106 revlog.REVIDX_FLAGS_ORDER.extend(flags) | |
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 | 112 # Register flag processors for each extension |
113 revlog.addflagprocessor( | |
114 REVIDX_NOOP, | |
115 ( | |
116 noopdonothing, | |
117 noopdonothing, | |
118 validatehash, | |
119 ) | |
120 ) | |
121 revlog.addflagprocessor( | |
122 REVIDX_BASE64, | |
123 ( | |
124 b64decode, | |
125 b64encode, | |
126 bypass, | |
127 ), | |
128 ) | |
129 revlog.addflagprocessor( | |
130 REVIDX_GZIP, | |
131 ( | |
132 gzipdecompress, | |
133 gzipcompress, | |
134 bypass | |
135 ) | |
136 ) |