Patchwork [2,of,3] simplemerge: leverage pycompat function to convert byte string to set

login
register
mail settings
Submitter Yuya Nishihara
Date June 4, 2020, 2:15 p.m.
Message ID <dba0ac9b68381e9610f2.1591280142@mimosa>
Download mbox | patch
Permalink /patch/46463/
State Accepted
Headers show

Comments

Yuya Nishihara - June 4, 2020, 2:15 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1591101649 -32400
#      Tue Jun 02 21:40:49 2020 +0900
# Node ID dba0ac9b68381e9610f25d9991bd623f85cbdefd
# Parent  8e111a6aabc5efd7ef414b9b1b6fa46eeaa569f4
simplemerge: leverage pycompat function to convert byte string to set
Pierre-Yves David - June 5, 2020, 2:21 p.m.
Ha, I missed those when writing this code

+1 for this patch

On 6/4/20 4:15 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1591101649 -32400
> #      Tue Jun 02 21:40:49 2020 +0900
> # Node ID dba0ac9b68381e9610f25d9991bd623f85cbdefd
> # Parent  8e111a6aabc5efd7ef414b9b1b6fa46eeaa569f4
> simplemerge: leverage pycompat function to convert byte string to set
> 
> diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
> --- a/mercurial/simplemerge.py
> +++ b/mercurial/simplemerge.py
> @@ -451,11 +451,6 @@ def _picklabels(defaults, overrides):
>       return result
>   
>   
> -def _bytes_to_set(b):
> -    """turns a multiple bytes (usually flags) into a set of individual byte"""
> -    return set(b[x : x + 1] for x in range(len(b)))
> -
> -
>   def is_not_null(ctx):
>       if not util.safehasattr(ctx, "node"):
>           return False
> @@ -518,10 +513,10 @@ def simplemerge(ui, localctx, basectx, o
>   
>       # merge flags if necessary
>       flags = localctx.flags()
> -    localflags = _bytes_to_set(flags)
> -    otherflags = _bytes_to_set(otherctx.flags())
> +    localflags = set(pycompat.iterbytestr(flags))
> +    otherflags = set(pycompat.iterbytestr(otherctx.flags()))
>       if is_not_null(basectx) and localflags != otherflags:
> -        baseflags = _bytes_to_set(basectx.flags())
> +        baseflags = set(pycompat.iterbytestr(basectx.flags()))
>           flags = localflags & otherflags
>           for f in localflags.symmetric_difference(otherflags):
>               if f not in baseflags:
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -451,11 +451,6 @@  def _picklabels(defaults, overrides):
     return result
 
 
-def _bytes_to_set(b):
-    """turns a multiple bytes (usually flags) into a set of individual byte"""
-    return set(b[x : x + 1] for x in range(len(b)))
-
-
 def is_not_null(ctx):
     if not util.safehasattr(ctx, "node"):
         return False
@@ -518,10 +513,10 @@  def simplemerge(ui, localctx, basectx, o
 
     # merge flags if necessary
     flags = localctx.flags()
-    localflags = _bytes_to_set(flags)
-    otherflags = _bytes_to_set(otherctx.flags())
+    localflags = set(pycompat.iterbytestr(flags))
+    otherflags = set(pycompat.iterbytestr(otherctx.flags()))
     if is_not_null(basectx) and localflags != otherflags:
-        baseflags = _bytes_to_set(basectx.flags())
+        baseflags = set(pycompat.iterbytestr(basectx.flags()))
         flags = localflags & otherflags
         for f in localflags.symmetric_difference(otherflags):
             if f not in baseflags: