##// END OF EJS Templates
flagutil: move addflagprocessor to the new module (API)
marmoute -
r42958:6d61be15 default
parent child Browse files
Show More
@@ -125,33 +125,6 b' ellipsisprocessor = ('
125 125 ellipsisrawprocessor,
126 126 )
127 127
128 def addflagprocessor(flag, processor):
129 """Register a flag processor on a revision data flag.
130
131 Invariant:
132 - Flags need to be defined in REVIDX_KNOWN_FLAGS and REVIDX_FLAGS_ORDER,
133 and REVIDX_RAWTEXT_CHANGING_FLAGS if they can alter rawtext.
134 - Only one flag processor can be registered on a specific flag.
135 - flagprocessors must be 3-tuples of functions (read, write, raw) with the
136 following signatures:
137 - (read) f(self, rawtext) -> text, bool
138 - (write) f(self, text) -> rawtext, bool
139 - (raw) f(self, rawtext) -> bool
140 "text" is presented to the user. "rawtext" is stored in revlog data, not
141 directly visible to the user.
142 The boolean returned by these transforms is used to determine whether
143 the returned text can be used for hash integrity checking. For example,
144 if "write" returns False, then "text" is used to generate hash. If
145 "write" returns True, that basically means "rawtext" returned by "write"
146 should be used to generate hash. Usually, "write" and "read" return
147 different booleans. And "raw" returns a same boolean as "write".
148
149 Note: The 'raw' transform is used for changegroup generation and in some
150 debug commands. In this case the transform only indicates whether the
151 contents can be used for hash integrity checks.
152 """
153 flagutil.insertflagprocessor(flag, processor, flagutil.flagprocessors)
154
155 128 def getoffset(q):
156 129 return int(q >> 16)
157 130
@@ -2609,7 +2582,7 b' class revlog(object):'
2609 2582 #
2610 2583 # L1 should be equal to L2. L3 could be different from them.
2611 2584 # "text" may or may not affect commit hash depending on flag
2612 # processors (see revlog.addflagprocessor).
2585 # processors (see flagutil.addflagprocessor).
2613 2586 #
2614 2587 # | common | rename | meta | ext
2615 2588 # -------------------------------------------------
@@ -40,6 +40,33 b' flagprocessors = {'
40 40 REVIDX_ISCENSORED: None,
41 41 }
42 42
43 def addflagprocessor(flag, processor):
44 """Register a flag processor on a revision data flag.
45
46 Invariant:
47 - Flags need to be defined in REVIDX_KNOWN_FLAGS and REVIDX_FLAGS_ORDER,
48 and REVIDX_RAWTEXT_CHANGING_FLAGS if they can alter rawtext.
49 - Only one flag processor can be registered on a specific flag.
50 - flagprocessors must be 3-tuples of functions (read, write, raw) with the
51 following signatures:
52 - (read) f(self, rawtext) -> text, bool
53 - (write) f(self, text) -> rawtext, bool
54 - (raw) f(self, rawtext) -> bool
55 "text" is presented to the user. "rawtext" is stored in revlog data, not
56 directly visible to the user.
57 The boolean returned by these transforms is used to determine whether
58 the returned text can be used for hash integrity checking. For example,
59 if "write" returns False, then "text" is used to generate hash. If
60 "write" returns True, that basically means "rawtext" returned by "write"
61 should be used to generate hash. Usually, "write" and "read" return
62 different booleans. And "raw" returns a same boolean as "write".
63
64 Note: The 'raw' transform is used for changegroup generation and in some
65 debug commands. In this case the transform only indicates whether the
66 contents can be used for hash integrity checks.
67 """
68 insertflagprocessor(flag, processor, flagprocessors)
69
43 70 def insertflagprocessor(flag, processor, flagprocessors):
44 71 if not flag & REVIDX_KNOWN_FLAGS:
45 72 msg = _("cannot register processor on unknown flag '%#x'.") % (flag)
@@ -113,7 +113,7 b' def extsetup(ui):'
113 113 exchange._bundlespeccontentopts[k][b"cg.version"] = b"03"
114 114
115 115 # Register flag processors for each extension
116 revlog.addflagprocessor(
116 flagutil.addflagprocessor(
117 117 REVIDX_NOOP,
118 118 (
119 119 noopdonothing,
@@ -121,7 +121,7 b' def extsetup(ui):'
121 121 validatehash,
122 122 )
123 123 )
124 revlog.addflagprocessor(
124 flagutil.addflagprocessor(
125 125 REVIDX_BASE64,
126 126 (
127 127 b64decode,
@@ -129,7 +129,7 b' def extsetup(ui):'
129 129 bypass,
130 130 ),
131 131 )
132 revlog.addflagprocessor(
132 flagutil.addflagprocessor(
133 133 REVIDX_GZIP,
134 134 (
135 135 gzipdecompress,
@@ -205,8 +205,8 b' Ensure the data got to the server OK'
205 205 extsetup(ui)
206 206 File "*/tests/flagprocessorext.py", line *, in extsetup (glob)
207 207 validatehash,
208 File "*/mercurial/revlog.py", line *, in addflagprocessor (glob)
209 flagutil.insertflagprocessor(flag, processor, flagutil.flagprocessors)
208 File "*/mercurial/revlogutils/flagutil.py", line *, in addflagprocessor (glob)
209 insertflagprocessor(flag, processor, flagprocessors)
210 210 File "*/mercurial/revlogutils/flagutil.py", line *, in insertflagprocessor (glob)
211 211 raise error.Abort(msg)
212 212 mercurial.error.Abort: b"cannot register multiple processors on flag '0x8'." (py3 !)
@@ -16,6 +16,7 b' from mercurial import ('
16 16
17 17 from mercurial.revlogutils import (
18 18 deltas,
19 flagutil,
19 20 )
20 21
21 22 # TESTTMP is optional. This makes it convenient to run without run-tests.py
@@ -56,7 +57,7 b' def rawprocessor(self, rawtext):'
56 57 # can be used to verify hash.
57 58 return False
58 59
59 revlog.addflagprocessor(revlog.REVIDX_EXTSTORED,
60 flagutil.addflagprocessor(revlog.REVIDX_EXTSTORED,
60 61 (readprocessor, writeprocessor, rawprocessor))
61 62
62 63 # Utilities about reading and appending revlog
General Comments 0
You need to be logged in to leave comments. Login now