Patchwork [4,of,4,py3] manifest: use itertools.chain() instead of + for Python 3 compat

login
register
mail settings
Submitter Augie Fackler
Date May 29, 2017, 1:43 a.m.
Message ID <0ecde7127f8816ca7252.1496022185@imladris.local>
Download mbox | patch
Permalink /patch/21028/
State Accepted
Headers show

Comments

Augie Fackler - May 29, 2017, 1:43 a.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1496021398 14400
#      Sun May 28 21:29:58 2017 -0400
# Node ID 0ecde7127f8816ca725282db684870ea8a8ad60f
# Parent  d7743001547ef1de565717cebf7e88e31e60433c
manifest: use itertools.chain() instead of + for Python 3 compat

This is all pure-Python code, so I'm not too worried about perf here,
but we can come back and fix it should it be a problem.

With this change, the manifest code passes most unit tests on Python 3
(once the tests are corrected with many b prefixes. I've got a little
more to sort out there and then I'll mail that change too.
Yuya Nishihara - May 29, 2017, 1:31 p.m.
On Sun, 28 May 2017 21:43:05 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1496021398 14400
> #      Sun May 28 21:29:58 2017 -0400
> # Node ID 0ecde7127f8816ca725282db684870ea8a8ad60f
> # Parent  d7743001547ef1de565717cebf7e88e31e60433c
> manifest: use itertools.chain() instead of + for Python 3 compat
> 
> This is all pure-Python code, so I'm not too worried about perf here,
> but we can come back and fix it should it be a problem.
> 
> With this change, the manifest code passes most unit tests on Python 3
> (once the tests are corrected with many b prefixes. I've got a little
> more to sort out there and then I'll mail that change too.

Great. Queued these, thanks.

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -8,6 +8,7 @@ 
 from __future__ import absolute_import
 
 import heapq
+import itertools
 import os
 import struct
 
@@ -779,7 +780,8 @@  class treemanifest(object):
 
     def iterentries(self):
         self._load()
-        for p, n in sorted(self._dirs.items() + self._files.items()):
+        for p, n in sorted(itertools.chain(self._dirs.items(),
+                                           self._files.items())):
             if p in self._files:
                 yield self._subpath(p), n, self._flags.get(p, '')
             else:
@@ -788,7 +790,8 @@  class treemanifest(object):
 
     def iteritems(self):
         self._load()
-        for p, n in sorted(self._dirs.items() + self._files.items()):
+        for p, n in sorted(itertools.chain(self._dirs.items(),
+                                           self._files.items())):
             if p in self._files:
                 yield self._subpath(p), n
             else:
@@ -797,7 +800,7 @@  class treemanifest(object):
 
     def iterkeys(self):
         self._load()
-        for p in sorted(self._dirs.keys() + self._files.keys()):
+        for p in sorted(itertools.chain(self._dirs, self._files)):
             if p in self._files:
                 yield self._subpath(p)
             else: