[PATCH 10 of 10] effectflag: detect when diff changed

Augie Fackler raf at durin42.com
Fri Jul 14 13:48:03 EDT 2017


On Fri, Jul 07, 2017 at 02:38:39PM +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld at octobus.net>
> # Date 1499346007 -7200
> #      Thu Jul 06 15:00:07 2017 +0200
> # Node ID 449fc1c748c6e058e892a4c940e20137e52e7808
> # Parent  6a40d87dfedcce4064eb4bcdb131ed4d427fd4de
> # EXP-Topic effectflag
> effectflag: detect when diff changed

I've done some thinking about this, and I'd like to see a bit of a
unified story between these bits of metadata and
https://www.mercurial-scm.org/wiki/CommitCustodyConcept - I know
Mozilla is super-interested in that, and I think it's got a lot of
merit generally (instead of just recording how things mutate, we could
also do things like have a CI system sign off on a revision in an
in-history way, for example).

I'm a little curious about the decision to use a metadata field but
then do a bitfield inside the metadata. Any reason to not use
comma-separated verbs or something? Just a space constraint concern?

(A v2 of this series, should we go that route, probably also wants to
document the nature of the ef1 field someplace.)

>
> Store in effect flag when the diff changed between the predecessor and
> its successors.
>
> Comparing the diff is not easy because we do not want to incorrectly detect a
> diff modification when the changeset has only been rebased.
>
> diff -r 6a40d87dfedc -r 449fc1c748c6 mercurial/obsutil.py
> --- a/mercurial/obsutil.py	Thu Jul 06 14:58:44 2017 +0200
> +++ b/mercurial/obsutil.py	Thu Jul 06 15:00:07 2017 +0200
> @@ -542,6 +542,7 @@
>  DESCCHANGED = 1 << 0 # action changed the description
>  METACHANGED = 1 << 1 # action change the meta
>  PARENTCHANGED = 1 << 2 # action change the parent
> +DIFFCHANGED = 1 << 3 # action change diff introduced by the changeset
>  USERCHANGED = 1 << 4 # the user changed
>  DATECHANGED = 1 << 5 # the date changed
>  BRANCHCHANGED = 1 << 6 # the branch changed
> @@ -565,6 +566,46 @@
>
>      return True
>
> +def _prepare_hunk(hunk):
> +    """Drop all information but the username and patch"""
> +    cleanunk = []
> +    for line in hunk.splitlines():
> +        if line.startswith(b'# User') or not line.startswith(b'#'):
> +            if line.startswith(b'@@'):
> +                line = b'@@\n'
> +            cleanunk.append(line)
> +    return cleanunk
> +
> +def _getdifflines(iterdiff):
> +    """return a cleaned up lines"""
> +    try:
> +        lines = next(iterdiff)
> +    except StopIteration:
> +        return None
> +    return _prepare_hunk(lines)
> +
> +def _cmpdiff(leftctx, rightctx):
> +    """return True if both ctx introduce the "same diff"
> +
> +    This is a first and basic implementation, with many shortcoming.
> +    """
> +
> +    # Leftctx or right ctx might be filtered, so we need to use the contexts
> +    # with an unfiltered repository to safely compute the diff
> +    leftunfi = leftctx._repo.unfiltered()[leftctx.rev()]
> +    leftdiff = leftunfi.diff(git=1)
> +    rightunfi = rightctx._repo.unfiltered()[rightctx.rev()]
> +    rightdiff = rightunfi.diff(git=1)
> +
> +    left, right = (0, 0)
> +    while None not in (left, right):
> +        left = _getdifflines(leftdiff)
> +        right = _getdifflines(rightdiff)
> +
> +        if left != right:
> +            return False
> +    return True
> +
>  def geteffectflag(relation):
>      """ From an obs-marker relation, compute what changed between the
>      predecessor and the successor.
> @@ -604,4 +645,12 @@
>          if ctxmeta != srcmeta:
>              effects |= METACHANGED
>
> +        # Check if at least one of the parent has changed
> +        if changectx.parents() != source.parents():
> +            effects |= PARENTCHANGED
> +
> +        # Check if the diff has changed
> +        if not _cmpdiff(source, changectx):
> +            effects |= DIFFCHANGED
> +
>      return effects
> diff -r 6a40d87dfedc -r 449fc1c748c6 tests/test-obsmarkers-effectflag.t
> --- a/tests/test-obsmarkers-effectflag.t	Thu Jul 06 14:58:44 2017 +0200
> +++ b/tests/test-obsmarkers-effectflag.t	Thu Jul 06 15:00:07 2017 +0200
> @@ -95,7 +95,7 @@
>
>    $ hg debugobsolete --rev .
>    d6f4d8b8d3c8cde990f13915bced7f92ce1cc54f 0 {ebfe0333e0d96f68a917afd97c0a0af87f1c3b5f} (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'user': 'test'}
> -  ebfe0333e0d96f68a917afd97c0a0af87f1c3b5f 75781fdbdbf58a987516b00c980bccda1e9ae588 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '0', 'user': 'test'}
> +  ebfe0333e0d96f68a917afd97c0a0af87f1c3b5f 75781fdbdbf58a987516b00c980bccda1e9ae588 0 (Thu Jan 01 00:00:00 1970 +0000) {'ef1': '8', 'user': 'test'}
>
>  amend with multiple effect (desc and meta)
>  -------------------------------------------
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list