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,
|
|
10 extensions,
|
|
11 filelog,
|
|
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)
|
|
47 versions.discard('01')
|
|
48 versions.discard('02')
|
|
49 versions.add('03')
|
|
50 return versions
|
|
51
|
|
52 def allsupportedversions(orig, ui):
|
|
53 versions = orig(ui)
|
|
54 versions.add('03')
|
|
55 return versions
|
|
56
|
|
57 def noopaddrevision(orig, self, text, transaction, link, p1, p2,
|
|
58 cachedelta=None, node=None,
|
|
59 flags=revlog.REVIDX_DEFAULT_FLAGS):
|
|
60 if '[NOOP]' in text:
|
|
61 flags |= REVIDX_NOOP
|
|
62 return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta,
|
|
63 node=node, flags=flags)
|
|
64
|
|
65 def b64addrevision(orig, self, text, transaction, link, p1, p2,
|
|
66 cachedelta=None, node=None,
|
|
67 flags=revlog.REVIDX_DEFAULT_FLAGS):
|
|
68 if '[BASE64]' in text:
|
|
69 flags |= REVIDX_BASE64
|
|
70 return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta,
|
|
71 node=node, flags=flags)
|
|
72
|
|
73 def gzipaddrevision(orig, self, text, transaction, link, p1, p2,
|
|
74 cachedelta=None, node=None,
|
|
75 flags=revlog.REVIDX_DEFAULT_FLAGS):
|
|
76 if '[GZIP]' in text:
|
|
77 flags |= REVIDX_GZIP
|
|
78 return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta,
|
|
79 node=node, flags=flags)
|
|
80
|
|
81 def failaddrevision(orig, self, text, transaction, link, p1, p2,
|
|
82 cachedelta=None, node=None,
|
|
83 flags=revlog.REVIDX_DEFAULT_FLAGS):
|
|
84 # This addrevision wrapper is meant to add a flag we will not have
|
|
85 # transforms registered for, ensuring we handle this error case.
|
|
86 if '[FAIL]' in text:
|
|
87 flags |= REVIDX_FAIL
|
|
88 return orig(self, text, transaction, link, p1, p2, cachedelta=cachedelta,
|
|
89 node=node, flags=flags)
|
|
90
|
|
91 def extsetup(ui):
|
|
92 # Enable changegroup3 for flags to be sent over the wire
|
|
93 wrapfunction = extensions.wrapfunction
|
|
94 wrapfunction(changegroup,
|
|
95 'supportedoutgoingversions',
|
|
96 supportedoutgoingversions)
|
|
97 wrapfunction(changegroup,
|
|
98 'allsupportedversions',
|
|
99 allsupportedversions)
|
|
100
|
|
101 # Teach revlog about our test flags
|
|
102 flags = [REVIDX_NOOP, REVIDX_BASE64, REVIDX_GZIP, REVIDX_FAIL]
|
|
103 revlog.REVIDX_KNOWN_FLAGS |= util.bitsfrom(flags)
|
|
104 revlog.REVIDX_FLAGS_ORDER.extend(flags)
|
|
105
|
|
106 # Add wrappers for addrevision, responsible to set flags depending on the
|
|
107 # revision data contents.
|
|
108 wrapfunction(filelog.filelog, 'addrevision', noopaddrevision)
|
|
109 wrapfunction(filelog.filelog, 'addrevision', b64addrevision)
|
|
110 wrapfunction(filelog.filelog, 'addrevision', gzipaddrevision)
|
|
111 wrapfunction(filelog.filelog, 'addrevision', failaddrevision)
|
|
112
|
|
113 # Register flag processors for each extension
|
|
114 revlog.addflagprocessor(
|
|
115 REVIDX_NOOP,
|
|
116 (
|
|
117 noopdonothing,
|
|
118 noopdonothing,
|
|
119 validatehash,
|
|
120 )
|
|
121 )
|
|
122 revlog.addflagprocessor(
|
|
123 REVIDX_BASE64,
|
|
124 (
|
|
125 b64decode,
|
|
126 b64encode,
|
|
127 bypass,
|
|
128 ),
|
|
129 )
|
|
130 revlog.addflagprocessor(
|
|
131 REVIDX_GZIP,
|
|
132 (
|
|
133 gzipdecompress,
|
|
134 gzipcompress,
|
|
135 bypass
|
|
136 )
|
|
137 )
|