author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Fri, 09 Apr 2021 03:36:24 +0200 | |
changeset 46883 | df76da69f5b1 |
parent 46709 | 3d740058b467 |
child 47077 | 119790e1c67c |
permissions | -rw-r--r-- |
42728
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
1 |
# flagutils.py - code to deal with revlog flags and their processors |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
2 |
# |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
3 |
# Copyright 2016 Remi Chaintron <remi@fb.com> |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 |
# Copyright 2016-2019 Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
5 |
# |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
6 |
# This software may be used and distributed according to the terms of the |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
7 |
# GNU General Public License version 2 or any later version. |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 |
|
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 |
from __future__ import absolute_import |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 |
|
42731
5109217a9ab6
flagutil: move insertflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
11 |
from ..i18n import _ |
5109217a9ab6
flagutil: move insertflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
12 |
|
42728
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 |
from .constants import ( |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 |
REVIDX_DEFAULT_FLAGS, |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 |
REVIDX_ELLIPSIS, |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 |
REVIDX_EXTSTORED, |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 |
REVIDX_FLAGS_ORDER, |
45671
2d6aea053153
copies: add a HASCOPIESINFO flag to highlight rev with useful data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
18 |
REVIDX_HASCOPIESINFO, |
42728
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 |
REVIDX_ISCENSORED, |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 |
REVIDX_RAWTEXT_CHANGING_FLAGS, |
43037
142deb539ccf
sidedata: register the flag processors if the repository allows for it
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42995
diff
changeset
|
21 |
REVIDX_SIDEDATA, |
42728
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
22 |
) |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
23 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43037
diff
changeset
|
24 |
from .. import error, util |
42730
92ac6b1697a7
flagutil: move REVIDX_KNOWN_FLAGS source of truth in flagutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42729
diff
changeset
|
25 |
|
42728
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
26 |
# blanked usage of all the name to prevent pyflakes constraints |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
27 |
# We need these name available in the module for extensions. |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
28 |
REVIDX_ISCENSORED |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
29 |
REVIDX_ELLIPSIS |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
30 |
REVIDX_EXTSTORED |
43037
142deb539ccf
sidedata: register the flag processors if the repository allows for it
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42995
diff
changeset
|
31 |
REVIDX_SIDEDATA |
45671
2d6aea053153
copies: add a HASCOPIESINFO flag to highlight rev with useful data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
32 |
REVIDX_HASCOPIESINFO, |
42728
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
33 |
REVIDX_DEFAULT_FLAGS |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
34 |
REVIDX_FLAGS_ORDER |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
35 |
REVIDX_RAWTEXT_CHANGING_FLAGS |
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
36 |
|
42730
92ac6b1697a7
flagutil: move REVIDX_KNOWN_FLAGS source of truth in flagutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42729
diff
changeset
|
37 |
REVIDX_KNOWN_FLAGS = util.bitsfrom(REVIDX_FLAGS_ORDER) |
92ac6b1697a7
flagutil: move REVIDX_KNOWN_FLAGS source of truth in flagutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42729
diff
changeset
|
38 |
|
42729
05c80f9ef100
flagutil: move the `flagprocessors` mapping in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42728
diff
changeset
|
39 |
# Store flag processors (cf. 'addflagprocessor()' to register) |
05c80f9ef100
flagutil: move the `flagprocessors` mapping in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42728
diff
changeset
|
40 |
flagprocessors = { |
05c80f9ef100
flagutil: move the `flagprocessors` mapping in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42728
diff
changeset
|
41 |
REVIDX_ISCENSORED: None, |
45671
2d6aea053153
copies: add a HASCOPIESINFO flag to highlight rev with useful data
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43077
diff
changeset
|
42 |
REVIDX_HASCOPIESINFO: None, |
42729
05c80f9ef100
flagutil: move the `flagprocessors` mapping in the new module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42728
diff
changeset
|
43 |
} |
42728
ca5ca3badd3c
flagutil: create a `mercurial.revlogutils.flagutil` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
44 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43037
diff
changeset
|
45 |
|
42732
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
46 |
def addflagprocessor(flag, processor): |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
47 |
"""Register a flag processor on a revision data flag. |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
48 |
|
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
49 |
Invariant: |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
50 |
- Flags need to be defined in REVIDX_KNOWN_FLAGS and REVIDX_FLAGS_ORDER, |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
51 |
and REVIDX_RAWTEXT_CHANGING_FLAGS if they can alter rawtext. |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
52 |
- Only one flag processor can be registered on a specific flag. |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
53 |
- flagprocessors must be 3-tuples of functions (read, write, raw) with the |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
54 |
following signatures: |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
55 |
- (read) f(self, rawtext) -> text, bool |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
56 |
- (write) f(self, text) -> rawtext, bool |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
57 |
- (raw) f(self, rawtext) -> bool |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
58 |
"text" is presented to the user. "rawtext" is stored in revlog data, not |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
59 |
directly visible to the user. |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
60 |
The boolean returned by these transforms is used to determine whether |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
61 |
the returned text can be used for hash integrity checking. For example, |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
62 |
if "write" returns False, then "text" is used to generate hash. If |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
63 |
"write" returns True, that basically means "rawtext" returned by "write" |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
64 |
should be used to generate hash. Usually, "write" and "read" return |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
65 |
different booleans. And "raw" returns a same boolean as "write". |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
66 |
|
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
67 |
Note: The 'raw' transform is used for changegroup generation and in some |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
68 |
debug commands. In this case the transform only indicates whether the |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
69 |
contents can be used for hash integrity checks. |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
70 |
""" |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
71 |
insertflagprocessor(flag, processor, flagprocessors) |
6d61be152c55
flagutil: move addflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
72 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43037
diff
changeset
|
73 |
|
42731
5109217a9ab6
flagutil: move insertflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
74 |
def insertflagprocessor(flag, processor, flagprocessors): |
5109217a9ab6
flagutil: move insertflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
75 |
if not flag & REVIDX_KNOWN_FLAGS: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
76 |
msg = _(b"cannot register processor on unknown flag '%#x'.") % flag |
42731
5109217a9ab6
flagutil: move insertflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
77 |
raise error.ProgrammingError(msg) |
5109217a9ab6
flagutil: move insertflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
78 |
if flag not in REVIDX_FLAGS_ORDER: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
79 |
msg = _(b"flag '%#x' undefined in REVIDX_FLAGS_ORDER.") % flag |
42731
5109217a9ab6
flagutil: move insertflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
80 |
raise error.ProgrammingError(msg) |
5109217a9ab6
flagutil: move insertflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
81 |
if flag in flagprocessors: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
82 |
msg = _(b"cannot register multiple processors on flag '%#x'.") % flag |
42731
5109217a9ab6
flagutil: move insertflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
83 |
raise error.Abort(msg) |
5109217a9ab6
flagutil: move insertflagprocessor to the new module (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42730
diff
changeset
|
84 |
flagprocessors[flag] = processor |
42871
5bb68fb72df2
flagutil: introduce a flagprocessorsmixin class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
85 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43037
diff
changeset
|
86 |
|
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
87 |
def processflagswrite(revlog, text, flags): |
42990
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
88 |
"""Inspect revision data flags and applies write transformations defined |
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
89 |
by registered flag processors. |
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
90 |
|
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
91 |
``text`` - the revision data to process |
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
92 |
``flags`` - the revision flags |
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
93 |
|
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
94 |
This method processes the flags in the order (or reverse order if |
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
95 |
``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the |
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
96 |
flag processors registered for present flags. The order of flags defined |
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
97 |
in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity. |
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
98 |
|
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
99 |
Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the |
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
100 |
processed text and ``validatehash`` is a bool indicating whether the |
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
101 |
returned text should be checked for hash integrity. |
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
102 |
""" |
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
103 |
return _processflagsfunc( |
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
104 |
revlog, |
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
105 |
text, |
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
106 |
flags, |
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
107 |
b'write', |
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
108 |
)[:2] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43037
diff
changeset
|
109 |
|
42990
a04b2c010d03
flagprocessors: make `processflagswrite` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42989
diff
changeset
|
110 |
|
42991
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
111 |
def processflagsread(revlog, text, flags): |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
112 |
"""Inspect revision data flags and applies read transformations defined |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
113 |
by registered flag processors. |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
114 |
|
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
115 |
``text`` - the revision data to process |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
116 |
``flags`` - the revision flags |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
117 |
``raw`` - an optional argument describing if the raw transform should be |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
118 |
applied. |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
119 |
|
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
120 |
This method processes the flags in the order (or reverse order if |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
121 |
``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
122 |
flag processors registered for present flags. The order of flags defined |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
123 |
in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity. |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
124 |
|
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
125 |
Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
126 |
processed text and ``validatehash`` is a bool indicating whether the |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
127 |
returned text should be checked for hash integrity. |
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
128 |
""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
129 |
return _processflagsfunc(revlog, text, flags, b'read') |
42991
eb5048f8c533
flagprocessors: make `processflagsread` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42990
diff
changeset
|
130 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43037
diff
changeset
|
131 |
|
42992
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
132 |
def processflagsraw(revlog, text, flags): |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
133 |
"""Inspect revision data flags to check is the content hash should be |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
134 |
validated. |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
135 |
|
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
136 |
``text`` - the revision data to process |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
137 |
``flags`` - the revision flags |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
138 |
|
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
139 |
This method processes the flags in the order (or reverse order if |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
140 |
``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
141 |
flag processors registered for present flags. The order of flags defined |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
142 |
in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity. |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
143 |
|
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
144 |
Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
145 |
processed text and ``validatehash`` is a bool indicating whether the |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
146 |
returned text should be checked for hash integrity. |
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
147 |
""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
148 |
return _processflagsfunc(revlog, text, flags, b'raw')[1] |
42992
dff95420480f
flagprocessors: make `processflagsraw` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42991
diff
changeset
|
149 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43037
diff
changeset
|
150 |
|
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
151 |
def _processflagsfunc(revlog, text, flags, operation): |
42989
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
152 |
"""internal function to process flag on a revlog |
42875
87a934684c3b
flagprocessors: introduce specialized functions
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42873
diff
changeset
|
153 |
|
42989
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
154 |
This function is private to this module, code should never needs to call it |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
155 |
directly.""" |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
156 |
# fast path: no flag processors will run |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
157 |
if flags == 0: |
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
158 |
return text, True |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
159 |
if operation not in (b'read', b'write', b'raw'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
160 |
raise error.ProgrammingError(_(b"invalid '%s' operation") % operation) |
42989
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
161 |
# Check all flags are known. |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
162 |
if flags & ~REVIDX_KNOWN_FLAGS: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43037
diff
changeset
|
163 |
raise revlog._flagserrorclass( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
164 |
_(b"incompatible revision flag '%#x'") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43037
diff
changeset
|
165 |
% (flags & ~REVIDX_KNOWN_FLAGS) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43037
diff
changeset
|
166 |
) |
42989
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
167 |
validatehash = True |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
168 |
# Depending on the operation (read or write), the order might be |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
169 |
# reversed due to non-commutative transforms. |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
170 |
orderedflags = REVIDX_FLAGS_ORDER |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
171 |
if operation == b'write': |
42989
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
172 |
orderedflags = reversed(orderedflags) |
42871
5bb68fb72df2
flagutil: introduce a flagprocessorsmixin class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
173 |
|
42989
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
174 |
for flag in orderedflags: |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
175 |
# If a flagprocessor has been registered for a known flag, apply the |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
176 |
# related operation transform and update result tuple. |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
177 |
if flag & flags: |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
178 |
vhash = True |
42871
5bb68fb72df2
flagutil: introduce a flagprocessorsmixin class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
179 |
|
42989
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
180 |
if flag not in revlog._flagprocessors: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
181 |
message = _(b"missing processor for flag '%#x'") % flag |
42989
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
182 |
raise revlog._flagserrorclass(message) |
42871
5bb68fb72df2
flagutil: introduce a flagprocessorsmixin class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
183 |
|
42989
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
184 |
processor = revlog._flagprocessors[flag] |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
185 |
if processor is not None: |
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
186 |
readtransform, writetransform, rawtransform = processor |
42871
5bb68fb72df2
flagutil: introduce a flagprocessorsmixin class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
187 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
188 |
if operation == b'raw': |
42989
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
189 |
vhash = rawtransform(revlog, text) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
190 |
elif operation == b'read': |
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
191 |
text, vhash = readtransform(revlog, text) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43037
diff
changeset
|
192 |
else: # write operation |
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
193 |
text, vhash = writetransform(revlog, text) |
42989
50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42988
diff
changeset
|
194 |
validatehash = validatehash and vhash |
42871
5bb68fb72df2
flagutil: introduce a flagprocessorsmixin class
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42732
diff
changeset
|
195 |
|
46709
3d740058b467
sidedata: move to new sidedata storage in revlogv2
Raphaël Gomès <rgomes@octobus.net>
parents:
45671
diff
changeset
|
196 |
return text, validatehash |