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

Augie Fackler raf at durin42.com
Sun May 28 21:43:05 EDT 2017


# HG changeset patch
# User Augie Fackler <raf at 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.

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:


More information about the Mercurial-devel mailing list