Mercurial > hg
changeset 42989:50d9de61ce02
flagprocessors: make `_processflagsfunc` a module level function
This is the first step toward removing the flag processing mixin.
Differential Revision: https://phab.mercurial-scm.org/D6817
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 06 Sep 2019 23:43:06 +0200 |
parents | f4caf910669e |
children | a04b2c010d03 |
files | mercurial/revlogutils/flagutil.py |
diffstat | 1 files changed, 46 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revlogutils/flagutil.py Wed Sep 04 00:53:27 2019 +0200 +++ b/mercurial/revlogutils/flagutil.py Fri Sep 06 23:43:06 2019 +0200 @@ -118,7 +118,7 @@ processed text and ``validatehash`` is a bool indicating whether the returned text should be checked for hash integrity. """ - return self._processflagsfunc(text, flags, 'read') + return _processflagsfunc(self, text, flags, 'read') def _processflagswrite(self, text, flags, sidedata): """Inspect revision data flags and applies write transformations defined @@ -136,8 +136,8 @@ processed text and ``validatehash`` is a bool indicating whether the returned text should be checked for hash integrity. """ - return self._processflagsfunc(text, flags, 'write', - sidedata=sidedata)[:2] + return _processflagsfunc(self, text, flags, 'write', + sidedata=sidedata)[:2] def _processflagsraw(self, text, flags): """Inspect revision data flags to check is the content hash should be @@ -155,48 +155,52 @@ processed text and ``validatehash`` is a bool indicating whether the returned text should be checked for hash integrity. """ - return self._processflagsfunc(text, flags, 'raw')[1] + return _processflagsfunc(self, text, flags, 'raw')[1] + +def _processflagsfunc(revlog, text, flags, operation, sidedata=None): + """internal function to process flag on a revlog - def _processflagsfunc(self, text, flags, operation, sidedata=None): - # fast path: no flag processors will run - if flags == 0: - return text, True, {} - if operation not in ('read', 'write', 'raw'): - raise error.ProgrammingError(_("invalid '%s' operation") % - operation) - # Check all flags are known. - if flags & ~REVIDX_KNOWN_FLAGS: - raise self._flagserrorclass(_("incompatible revision flag '%#x'") % - (flags & ~REVIDX_KNOWN_FLAGS)) - validatehash = True - # Depending on the operation (read or write), the order might be - # reversed due to non-commutative transforms. - orderedflags = REVIDX_FLAGS_ORDER - if operation == 'write': - orderedflags = reversed(orderedflags) + This function is private to this module, code should never needs to call it + directly.""" + # fast path: no flag processors will run + if flags == 0: + return text, True, {} + if operation not in ('read', 'write', 'raw'): + raise error.ProgrammingError(_("invalid '%s' operation") % + operation) + # Check all flags are known. + if flags & ~REVIDX_KNOWN_FLAGS: + raise revlog._flagserrorclass(_("incompatible revision flag '%#x'") % + (flags & ~REVIDX_KNOWN_FLAGS)) + validatehash = True + # Depending on the operation (read or write), the order might be + # reversed due to non-commutative transforms. + orderedflags = REVIDX_FLAGS_ORDER + if operation == 'write': + orderedflags = reversed(orderedflags) - outsidedata = {} - for flag in orderedflags: - # If a flagprocessor has been registered for a known flag, apply the - # related operation transform and update result tuple. - if flag & flags: - vhash = True + outsidedata = {} + for flag in orderedflags: + # If a flagprocessor has been registered for a known flag, apply the + # related operation transform and update result tuple. + if flag & flags: + vhash = True - if flag not in self._flagprocessors: - message = _("missing processor for flag '%#x'") % (flag) - raise self._flagserrorclass(message) + if flag not in revlog._flagprocessors: + message = _("missing processor for flag '%#x'") % (flag) + raise revlog._flagserrorclass(message) - processor = self._flagprocessors[flag] - if processor is not None: - readtransform, writetransform, rawtransform = processor + processor = revlog._flagprocessors[flag] + if processor is not None: + readtransform, writetransform, rawtransform = processor - if operation == 'raw': - vhash = rawtransform(self, text) - elif operation == 'read': - text, vhash, s = readtransform(self, text) - outsidedata.update(s) - else: # write operation - text, vhash = writetransform(self, text, sidedata) - validatehash = validatehash and vhash + if operation == 'raw': + vhash = rawtransform(revlog, text) + elif operation == 'read': + text, vhash, s = readtransform(revlog, text) + outsidedata.update(s) + else: # write operation + text, vhash = writetransform(revlog, text, sidedata) + validatehash = validatehash and vhash - return text, validatehash, outsidedata + return text, validatehash, outsidedata