[PATCH 3 of 3] simplemerge: rewrite flag merging loop as expression
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Fri Jun 5 14:24:17 UTC 2020
On 6/4/20 4:15 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya at tcha.org>
> # Date 1591101897 -32400
> # Tue Jun 02 21:44:57 2020 +0900
> # Node ID 970abb8ea2a2d6a086ebfdd9a1130b2fb777640e
> # Parent dba0ac9b68381e9610f25d9991bd623f85cbdefd
> simplemerge: rewrite flag merging loop as expression
>
> I feel binary operations are more readable.
The fact also merge "flag removal" become implicit and might be less
clear to reader. I like the use of binary operation, but can we add a
comment about the removed flag ?
>
> diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
> --- a/mercurial/simplemerge.py
> +++ b/mercurial/simplemerge.py
> @@ -517,11 +517,9 @@ def simplemerge(ui, localctx, basectx, o
> otherflags = set(pycompat.iterbytestr(otherctx.flags()))
> if is_not_null(basectx) and localflags != otherflags:
> baseflags = set(pycompat.iterbytestr(basectx.flags()))
> - flags = localflags & otherflags
> - for f in localflags.symmetric_difference(otherflags):
> - if f not in baseflags:
> - flags.add(f)
> - flags = b''.join(sorted(flags))
> + commonflags = localflags & otherflags
> + addedflags = (localflags ^ otherflags) - baseflags
> + flags = b''.join(sorted(commonflags | addedflags))
>
> if not opts.get(b'print'):
> localctx.write(mergedtext, flags)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
--
Pierre-Yves David
More information about the Mercurial-devel
mailing list