Patchwork [1,of,5,stable] patch: update copying of dict keys and values to work on Python 3

login
register
mail settings
Submitter Augie Fackler
Date July 24, 2017, 9:08 p.m.
Message ID <a67471f29dbb38e5ac51.1500930489@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/22546/
State Accepted
Headers show

Comments

Augie Fackler - July 24, 2017, 9:08 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1500921775 14400
#      Mon Jul 24 14:42:55 2017 -0400
# Branch stable
# Node ID a67471f29dbb38e5ac51a9bacf4bb5fff076e1bb
# Parent  e12c3049af8ee85dfcf0575297fd568dde5cc8d2
patch: update copying of dict keys and values to work on Python 3
via Mercurial-devel - July 24, 2017, 9:27 p.m.
On Mon, Jul 24, 2017 at 2:08 PM, Augie Fackler <raf@durin42.com> wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1500921775 14400
> #      Mon Jul 24 14:42:55 2017 -0400
> # Branch stable
> # Node ID a67471f29dbb38e5ac51a9bacf4bb5fff076e1bb
> # Parent  e12c3049af8ee85dfcf0575297fd568dde5cc8d2
> patch: update copying of dict keys and values to work on Python 3
>
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -2569,7 +2569,7 @@ def trydiff(repo, revs, ctx1, ctx2, modi
>
>      if relroot != '' and (repo.ui.configbool('devel', 'all-warnings')
>                            or repo.ui.configbool('devel', 'check-relroot')):
> -        for f in modified + added + removed + copy.keys() + copy.values():
> +        for f in modified + added + removed + list(copy) + list(copy.values()):

For default, would itertools.chain(modified, added, removed, copy,
copy.values()) be better? OTOH, it's only run when developer warnings
are on, so it's just a matter of aesthetics, I guess.

>              if f is not None and not f.startswith(relroot):
>                  raise AssertionError(
>                      "file %s doesn't start with relroot %s" % (f, relroot))
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Augie Fackler - July 24, 2017, 11:13 p.m.
On Jul 24, 2017 5:27 PM, "Martin von Zweigbergk" <martinvonz@google.com>
wrote:

On Mon, Jul 24, 2017 at 2:08 PM, Augie Fackler <raf@durin42.com> wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1500921775 14400
> #      Mon Jul 24 14:42:55 2017 -0400
> # Branch stable
> # Node ID a67471f29dbb38e5ac51a9bacf4bb5fff076e1bb
> # Parent  e12c3049af8ee85dfcf0575297fd568dde5cc8d2
> patch: update copying of dict keys and values to work on Python 3
>
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -2569,7 +2569,7 @@ def trydiff(repo, revs, ctx1, ctx2, modi
>
>      if relroot != '' and (repo.ui.configbool('devel', 'all-warnings')
>                            or repo.ui.configbool('devel',
'check-relroot')):
> -        for f in modified + added + removed + copy.keys() +
copy.values():
> +        for f in modified + added + removed + list(copy) +
list(copy.values()):

For default, would itertools.chain(modified, added, removed, copy,
copy.values()) be better? OTOH, it's only run when developer warnings
are on, so it's just a matter of aesthetics, I guess.


Probably not, since we're making a full copy and the iterator overhead is
probably higher than the raw copies are.

I didn't check though.


>              if f is not None and not f.startswith(relroot):
>                  raise AssertionError(
>                      "file %s doesn't start with relroot %s" % (f,
relroot))
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2569,7 +2569,7 @@  def trydiff(repo, revs, ctx1, ctx2, modi
 
     if relroot != '' and (repo.ui.configbool('devel', 'all-warnings')
                           or repo.ui.configbool('devel', 'check-relroot')):
-        for f in modified + added + removed + copy.keys() + copy.values():
+        for f in modified + added + removed + list(copy) + list(copy.values()):
             if f is not None and not f.startswith(relroot):
                 raise AssertionError(
                     "file %s doesn't start with relroot %s" % (f, relroot))