D6800: flagprocessors: introduce specialized functions

2019-09-07 Thread indygreg (Gregory Szorc)
indygreg added inline comments.

INLINE COMMENTS

> flagutil.py:151
> +
> +Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the
> +processed text and ``validatehash`` is a bool indicating whether the

Please follow-up with a fix for the docstring to reflect that this does not 
return a 2-tuple.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6800/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6800

To: marmoute, yuja, durin42, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6800: flagprocessors: introduce specialized functions

2019-09-07 Thread marmoute (Pierre-Yves David)
Closed by commit rHG87a934684c3b: flagprocessors: introduce specialized 
functions (authored by marmoute).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6800?vs=16405&id=16438

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6800/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6800

AFFECTED FILES
  mercurial/revlogutils/flagutil.py

CHANGE DETAILS

diff --git a/mercurial/revlogutils/flagutil.py 
b/mercurial/revlogutils/flagutil.py
--- a/mercurial/revlogutils/flagutil.py
+++ b/mercurial/revlogutils/flagutil.py
@@ -90,12 +90,20 @@
 _flagserrorclass = error.RevlogError
 
 def _processflags(self, text, flags, operation, raw=False):
-"""Inspect revision data flags and applies transforms defined by
-registered flag processors.
+"""deprecated entry point to access flag processors"""
+if raw:
+return text, self._processflagsraw(text, flags)
+elif operation == 'read':
+return self._processflagsread(text, flags)
+else: # write operation
+return self._processflagswrite(text, flags)
+
+def _processflagsread(self, text, flags):
+"""Inspect revision data flags and applies read transformations defined
+by registered flag processors.
 
 ``text`` - the revision data to process
 ``flags`` - the revision flags
-``operation`` - the operation being performed (read or write)
 ``raw`` - an optional argument describing if the raw transform should 
be
 applied.
 
@@ -107,10 +115,46 @@
 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the
 processed text and ``validatehash`` is a bool indicating whether the
 returned text should be checked for hash integrity.
+"""
+return self._processflagsfunc(text, flags, 'read')
 
-Note: If the ``raw`` argument is set, it has precedence over the
-operation and will only update the value of ``validatehash``.
+def _processflagswrite(self, text, flags):
+"""Inspect revision data flags and applies write transformations 
defined
+by registered flag processors.
+
+``text`` - the revision data to process
+``flags`` - the revision flags
+
+This method processes the flags in the order (or reverse order if
+``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the
+flag processors registered for present flags. The order of flags 
defined
+in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity.
+
+Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the
+processed text and ``validatehash`` is a bool indicating whether the
+returned text should be checked for hash integrity.
 """
+return self._processflagsfunc(text, flags, 'write')
+
+def _processflagsraw(self, text, flags):
+"""Inspect revision data flags to check is the content hash should be
+validated.
+
+``text`` - the revision data to process
+``flags`` - the revision flags
+
+This method processes the flags in the order (or reverse order if
+``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the
+flag processors registered for present flags. The order of flags 
defined
+in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity.
+
+Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the
+processed text and ``validatehash`` is a bool indicating whether the
+returned text should be checked for hash integrity.
+"""
+return self._processflagsfunc(text, flags, 'read', raw=True)[1]
+
+def _processflagsfunc(self, text, flags, operation, raw=False):
 # fast path: no flag processors will run
 if flags == 0:
 return text, True



To: marmoute, yuja, durin42, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6800: flagprocessors: introduce specialized functions

2019-09-07 Thread indygreg (Gregory Szorc)
This revision is now accepted and ready to land.
indygreg added inline comments.
indygreg accepted this revision.

INLINE COMMENTS

> flagutil.py:98
> +return self._processflagsread(text, flags)
> +else: # write operation
> +return self._processflagswrite(text, flags)

Please follow up to make this more strongly typed by checking `operation == 
'write'`.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6800/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D6800

To: marmoute, yuja, durin42, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D6800: flagprocessors: introduce specialized functions

2019-09-07 Thread marmoute (Pierre-Yves David)
marmoute created this revision.
marmoute added reviewers: yuja, durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This make the call site clearer and the open the way to more diverse return
  types.
  
  For now, the same old code is still in use under the hood.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6800

AFFECTED FILES
  mercurial/revlogutils/flagutil.py

CHANGE DETAILS

diff --git a/mercurial/revlogutils/flagutil.py 
b/mercurial/revlogutils/flagutil.py
--- a/mercurial/revlogutils/flagutil.py
+++ b/mercurial/revlogutils/flagutil.py
@@ -90,12 +90,20 @@
 _flagserrorclass = error.RevlogError
 
 def _processflags(self, text, flags, operation, raw=False):
-"""Inspect revision data flags and applies transforms defined by
-registered flag processors.
+"""deprecated entry point to access flag processors"""
+if raw:
+return text, self._processflagsraw(text, flags)
+elif operation == 'read':
+return self._processflagsread(text, flags)
+else: # write operation
+return self._processflagswrite(text, flags)
+
+def _processflagsread(self, text, flags):
+"""Inspect revision data flags and applies read transformations defined
+by registered flag processors.
 
 ``text`` - the revision data to process
 ``flags`` - the revision flags
-``operation`` - the operation being performed (read or write)
 ``raw`` - an optional argument describing if the raw transform should 
be
 applied.
 
@@ -107,10 +115,46 @@
 Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the
 processed text and ``validatehash`` is a bool indicating whether the
 returned text should be checked for hash integrity.
+"""
+return self._processflagsfunc(text, flags, 'read')
 
-Note: If the ``raw`` argument is set, it has precedence over the
-operation and will only update the value of ``validatehash``.
+def _processflagswrite(self, text, flags):
+"""Inspect revision data flags and applies write transformations 
defined
+by registered flag processors.
+
+``text`` - the revision data to process
+``flags`` - the revision flags
+
+This method processes the flags in the order (or reverse order if
+``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the
+flag processors registered for present flags. The order of flags 
defined
+in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity.
+
+Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the
+processed text and ``validatehash`` is a bool indicating whether the
+returned text should be checked for hash integrity.
 """
+return self._processflagsfunc(text, flags, 'write')
+
+def _processflagsraw(self, text, flags):
+"""Inspect revision data flags to check is the content hash should be
+validated.
+
+``text`` - the revision data to process
+``flags`` - the revision flags
+
+This method processes the flags in the order (or reverse order if
+``operation`` is 'write') defined by REVIDX_FLAGS_ORDER, applying the
+flag processors registered for present flags. The order of flags 
defined
+in REVIDX_FLAGS_ORDER needs to be stable to allow non-commutativity.
+
+Returns a 2-tuple of ``(text, validatehash)`` where ``text`` is the
+processed text and ``validatehash`` is a bool indicating whether the
+returned text should be checked for hash integrity.
+"""
+return self._processflagsfunc(text, flags, 'read', raw=True)[1]
+
+def _processflagsfunc(self, text, flags, operation, raw=False):
 # fast path: no flag processors will run
 if flags == 0:
 return text, True



To: marmoute, yuja, durin42, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel