changeset 8456:e9e2a2c9b294

convert: use set instead of dict
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sun, 17 May 2009 03:04:17 +0200
parents a858b54d072b
children e33baed7c1bc
files hgext/convert/convcmd.py hgext/convert/cvsps.py hgext/convert/git.py hgext/convert/hg.py
diffstat 4 files changed, 14 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/convcmd.py	Sun May 17 03:02:12 2009 +0200
+++ b/hgext/convert/convcmd.py	Sun May 17 03:04:17 2009 +0200
@@ -100,12 +100,12 @@
         '''Return a mapping that identifies the uncommitted parents of every
         uncommitted changeset.'''
         visit = heads
-        known = {}
+        known = set()
         parents = {}
         while visit:
             n = visit.pop(0)
             if n in known or n in self.map: continue
-            known[n] = 1
+            known.add(n)
             commit = self.cachecommit(n)
             parents[n] = []
             for p in commit.parents:
@@ -118,14 +118,14 @@
         '''Return an ordering such that every uncommitted changeset is
         preceeded by all its uncommitted ancestors.'''
         visit = parents.keys()
-        seen = {}
+        seen = set()
         children = {}
         actives = []
 
         while visit:
             n = visit.pop(0)
             if n in seen: continue
-            seen[n] = 1
+            seen.add(n)
             # Ensure that nodes without parents are present in the 'children'
             # mapping.
             children.setdefault(n, [])
--- a/hgext/convert/cvsps.py	Sun May 17 03:02:12 2009 +0200
+++ b/hgext/convert/cvsps.py	Sun May 17 03:04:17 2009 +0200
@@ -463,7 +463,7 @@
     listsort(log, key=lambda x:(x.comment, x.author, x.branch, x.date))
 
     changesets = []
-    files = {}
+    files = set()
     c = None
     for i, e in enumerate(log):
 
@@ -480,13 +480,13 @@
                           branch=e.branch, date=e.date, entries=[],
                           mergepoint=getattr(e, 'mergepoint', None))
             changesets.append(c)
-            files = {}
+            files = set()
             if len(changesets) % 100 == 0:
                 t = '%d %s' % (len(changesets), repr(e.comment)[1:-1])
                 ui.status(util.ellipsis(t, 80) + '\n')
 
         c.entries.append(e)
-        files[e.file] = True
+        files.add(e.file)
         c.date = e.date       # changeset date is date of latest commit in it
 
     # Mark synthetic changesets
@@ -564,19 +564,18 @@
 
     globaltags = {}
     for c in changesets:
-        tags = {}
         for e in c.entries:
             for tag in e.tags:
                 # remember which is the latest changeset to have this tag
                 globaltags[tag] = c
 
     for c in changesets:
-        tags = {}
+        tags = set()
         for e in c.entries:
             for tag in e.tags:
-                tags[tag] = True
+                tags.add(tag)
         # remember tags only if this is the latest changeset to have it
-        c.tags = sorted([tag for tag in tags if globaltags[tag] is c])
+        c.tags = sorted(tag for tag in tags if globaltags[tag] is c)
 
     # Find parent changesets, handle {{mergetobranch BRANCHNAME}}
     # by inserting dummy changesets with two parents, and handle
--- a/hgext/convert/git.py	Sun May 17 03:02:12 2009 +0200
+++ b/hgext/convert/git.py	Sun May 17 03:04:17 2009 +0200
@@ -63,7 +63,7 @@
         self.modecache = {}
         fh = self.gitcmd("git diff-tree -z --root -m -r %s" % version)
         changes = []
-        seen = {}
+        seen = set()
         entry = None
         for l in fh.read().split('\x00'):
             if not entry:
@@ -73,7 +73,7 @@
                 continue
             f = l
             if f not in seen:
-                seen[f] = 1
+                seen.add(f)
                 entry = entry.split()
                 h = entry[3]
                 p = (entry[1] == "100755")
--- a/hgext/convert/hg.py	Sun May 17 03:02:12 2009 +0200
+++ b/hgext/convert/hg.py	Sun May 17 03:04:17 2009 +0200
@@ -195,7 +195,7 @@
     def __init__(self, ui, path, rev=None):
         converter_source.__init__(self, ui, path, rev)
         self.ignoreerrors = ui.configbool('convert', 'hg.ignoreerrors', False)
-        self.ignored = {}
+        self.ignored = set()
         self.saverev = ui.configbool('convert', 'hg.saverev', False)
         try:
             self.repo = hg.repository(self.ui, path)
@@ -288,7 +288,7 @@
             except error.LookupError, e:
                 if not self.ignoreerrors:
                     raise
-                self.ignored[name] = 1
+                self.ignored.add(name)
                 self.ui.warn(_('ignoring: %s\n') % e)
         return copies