Show More
@@ -125,33 +125,6 b' ellipsisprocessor = (' | |||||
125 | ellipsisrawprocessor, |
|
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 | def getoffset(q): |
|
128 | def getoffset(q): | |
156 | return int(q >> 16) |
|
129 | return int(q >> 16) | |
157 |
|
130 | |||
@@ -2609,7 +2582,7 b' class revlog(object):' | |||||
2609 | # |
|
2582 | # | |
2610 | # L1 should be equal to L2. L3 could be different from them. |
|
2583 | # L1 should be equal to L2. L3 could be different from them. | |
2611 | # "text" may or may not affect commit hash depending on flag |
|
2584 | # "text" may or may not affect commit hash depending on flag | |
2612 |
# processors (see |
|
2585 | # processors (see flagutil.addflagprocessor). | |
2613 | # |
|
2586 | # | |
2614 | # | common | rename | meta | ext |
|
2587 | # | common | rename | meta | ext | |
2615 | # ------------------------------------------------- |
|
2588 | # ------------------------------------------------- |
@@ -40,6 +40,33 b' flagprocessors = {' | |||||
40 | REVIDX_ISCENSORED: None, |
|
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 | def insertflagprocessor(flag, processor, flagprocessors): |
|
70 | def insertflagprocessor(flag, processor, flagprocessors): | |
44 | if not flag & REVIDX_KNOWN_FLAGS: |
|
71 | if not flag & REVIDX_KNOWN_FLAGS: | |
45 | msg = _("cannot register processor on unknown flag '%#x'.") % (flag) |
|
72 | msg = _("cannot register processor on unknown flag '%#x'.") % (flag) |
@@ -113,7 +113,7 b' def extsetup(ui):' | |||||
113 | exchange._bundlespeccontentopts[k][b"cg.version"] = b"03" |
|
113 | exchange._bundlespeccontentopts[k][b"cg.version"] = b"03" | |
114 |
|
114 | |||
115 | # Register flag processors for each extension |
|
115 | # Register flag processors for each extension | |
116 |
|
|
116 | flagutil.addflagprocessor( | |
117 | REVIDX_NOOP, |
|
117 | REVIDX_NOOP, | |
118 | ( |
|
118 | ( | |
119 | noopdonothing, |
|
119 | noopdonothing, | |
@@ -121,7 +121,7 b' def extsetup(ui):' | |||||
121 | validatehash, |
|
121 | validatehash, | |
122 | ) |
|
122 | ) | |
123 | ) |
|
123 | ) | |
124 |
|
|
124 | flagutil.addflagprocessor( | |
125 | REVIDX_BASE64, |
|
125 | REVIDX_BASE64, | |
126 | ( |
|
126 | ( | |
127 | b64decode, |
|
127 | b64decode, | |
@@ -129,7 +129,7 b' def extsetup(ui):' | |||||
129 | bypass, |
|
129 | bypass, | |
130 | ), |
|
130 | ), | |
131 | ) |
|
131 | ) | |
132 |
|
|
132 | flagutil.addflagprocessor( | |
133 | REVIDX_GZIP, |
|
133 | REVIDX_GZIP, | |
134 | ( |
|
134 | ( | |
135 | gzipdecompress, |
|
135 | gzipdecompress, |
@@ -205,8 +205,8 b' Ensure the data got to the server OK' | |||||
205 | extsetup(ui) |
|
205 | extsetup(ui) | |
206 | File "*/tests/flagprocessorext.py", line *, in extsetup (glob) |
|
206 | File "*/tests/flagprocessorext.py", line *, in extsetup (glob) | |
207 | validatehash, |
|
207 | validatehash, | |
208 | File "*/mercurial/revlog.py", line *, in addflagprocessor (glob) |
|
208 | File "*/mercurial/revlogutils/flagutil.py", line *, in addflagprocessor (glob) | |
209 |
|
|
209 | insertflagprocessor(flag, processor, flagprocessors) | |
210 | File "*/mercurial/revlogutils/flagutil.py", line *, in insertflagprocessor (glob) |
|
210 | File "*/mercurial/revlogutils/flagutil.py", line *, in insertflagprocessor (glob) | |
211 | raise error.Abort(msg) |
|
211 | raise error.Abort(msg) | |
212 | mercurial.error.Abort: b"cannot register multiple processors on flag '0x8'." (py3 !) |
|
212 | mercurial.error.Abort: b"cannot register multiple processors on flag '0x8'." (py3 !) |
@@ -16,6 +16,7 b' from mercurial import (' | |||||
16 |
|
16 | |||
17 | from mercurial.revlogutils import ( |
|
17 | from mercurial.revlogutils import ( | |
18 | deltas, |
|
18 | deltas, | |
|
19 | flagutil, | |||
19 | ) |
|
20 | ) | |
20 |
|
21 | |||
21 | # TESTTMP is optional. This makes it convenient to run without run-tests.py |
|
22 | # TESTTMP is optional. This makes it convenient to run without run-tests.py | |
@@ -56,7 +57,7 b' def rawprocessor(self, rawtext):' | |||||
56 | # can be used to verify hash. |
|
57 | # can be used to verify hash. | |
57 | return False |
|
58 | return False | |
58 |
|
59 | |||
59 |
|
|
60 | flagutil.addflagprocessor(revlog.REVIDX_EXTSTORED, | |
60 | (readprocessor, writeprocessor, rawprocessor)) |
|
61 | (readprocessor, writeprocessor, rawprocessor)) | |
61 |
|
62 | |||
62 | # Utilities about reading and appending revlog |
|
63 | # Utilities about reading and appending revlog |
General Comments 0
You need to be logged in to leave comments.
Login now