py3: call branchmap.items() on py3 and continue to call iteritems() on py2
authorMartin von Zweigbergk <martinvonz@google.com>
Sat, 13 Jul 2019 00:17:03 -0700
changeset 4743 92e3db149d7d
parent 4742 db3e7f6b5ceb
child 4744 45afcbfea417
py3: call branchmap.items() on py3 and continue to call iteritems() on py2 Mercurial's source transformer also replaces the 'def iteritems(' in branchmap by 'def items(', so we need to call whichever version is there.
hgext3rd/topic/compat.py
hgext3rd/topic/discovery.py
hgext3rd/topic/flow.py
--- a/hgext3rd/topic/compat.py	Fri Jul 12 23:24:04 2019 -0700
+++ b/hgext3rd/topic/compat.py	Sat Jul 13 00:17:03 2019 -0700
@@ -9,6 +9,7 @@
 
 from mercurial import (
     obsolete,
+    pycompat,
 )
 
 getmarkers = None
@@ -24,3 +25,10 @@
     getmarkers = obsolete.getmarkers
 if successorssets is None:
     successorssets = obsolete.successorssets
+
+if pycompat.ispy3:
+    def branchmapitems(branchmap):
+        return branchmap.items()
+else:
+    def branchmapitems(branchmap):
+        return branchmap.iteritems()
--- a/hgext3rd/topic/discovery.py	Fri Jul 12 23:24:04 2019 -0700
+++ b/hgext3rd/topic/discovery.py	Sat Jul 13 00:17:03 2019 -0700
@@ -14,6 +14,7 @@
 )
 from . import (
     common,
+    compat,
 )
 
 try:
@@ -49,7 +50,7 @@
     def remotebranchmap():
         # drop topic information from changeset about to be published
         result = collections.defaultdict(list)
-        for branch, heads in origremotebranchmap().iteritems():
+        for branch, heads in compat.branchmapitems(origremotebranchmap()):
             if ':' not in branch:
                 result[branch].extend(heads)
             else:
--- a/hgext3rd/topic/flow.py	Fri Jul 12 23:24:04 2019 -0700
+++ b/hgext3rd/topic/flow.py	Sat Jul 13 00:17:03 2019 -0700
@@ -11,8 +11,13 @@
 
 from mercurial.i18n import _
 
+from . import (
+    compat,
+)
+
 def enforcesinglehead(repo, tr):
-    for name, heads in repo.filtered('visible').branchmap().iteritems():
+    branchmap = repo.filtered('visible').branchmap()
+    for name, heads in compat.branchmapitems(branchmap):
         if len(heads) > 1:
             hexs = [node.short(n) for n in heads]
             raise error.Abort(_('%d heads on "%s"') % (len(heads), name),