Skip to content
Snippets Groups Projects
Commit 50d9de61ce02 authored by Pierre-Yves David's avatar Pierre-Yves David :octopus:
Browse files

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
parent f4caf910669e
No related branches found
No related tags found
No related merge requests found
......@@ -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,5 +155,8 @@
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
......@@ -159,19 +162,20 @@
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)
......@@ -177,8 +181,8 @@
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
......@@ -184,5 +188,5 @@
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)
......@@ -188,5 +192,5 @@
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
......@@ -192,10 +196,10 @@
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
......@@ -201,2 +205,2 @@
return text, validatehash, outsidedata
return text, validatehash, outsidedata
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment