[Pkg-bazaar-commits] ./bzr/unstable r543: - More cleanups for set type

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:19:11 UTC 2009


------------------------------------------------------------
revno: 543
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Thu 2005-05-19 19:59:49 +1000
message:
  - More cleanups for set type
  
  - Clean up Inventory cmp method
  
  - Remove the Inventory.id_set and Tree.id_set methods: don't built
    sets when just using the dictionaries will do.
modified:
  bzrlib/__init__.py
  bzrlib/check.py
  bzrlib/inventory.py
  bzrlib/remotebranch.py
  bzrlib/tree.py
-------------- next part --------------
=== modified file 'bzrlib/__init__.py'
--- a/bzrlib/__init__.py	2005-05-19 06:37:21 +0000
+++ b/bzrlib/__init__.py	2005-05-19 09:59:49 +0000
@@ -47,19 +47,3 @@
 __copyright__ = "Copyright 2005 Canonical Development Ltd."
 __author__ = "Martin Pool <mbp at canonical.com>"
 __version__ = '0.0.5pre'
-
-
-# in python2.4 there is a 'set' builtin type; in 2.3 we need to use
-# the slower pure-python 'sets' module.
-import sys
-if sys.version_info < (2, 4):
-    import sets
-    set = sets.Set
-    frozenset = sets.ImmutableSet
-    del sets
-else:
-    import __builtin__
-    set = __builtin__.set
-    frozenset = __builtin__.frozenset
-    del __builtin__
-    

=== modified file 'bzrlib/check.py'
--- a/bzrlib/check.py	2005-05-19 06:37:21 +0000
+++ b/bzrlib/check.py	2005-05-19 09:59:49 +0000
@@ -27,8 +27,6 @@
 import osutils
 
 def check(branch, progress=True):
-    from bzrlib import set
-
     out = sys.stdout
 
     # TODO: factor out
@@ -46,7 +44,7 @@
 
     p('history of %r' % branch.base)
     last_ptr = None
-    checked_revs = set()
+    checked_revs = {}
     
     history = branch.revision_history()
     revno = 0
@@ -66,20 +64,20 @@
         last_ptr = rid
         if rid in checked_revs:
             bailout('repeated revision {%s}' % rid)
-        checked_revs.add(rid)
+        checked_revs[rid] = True
 
         ## TODO: Check all the required fields are present on the revision.
 
         inv = branch.get_inventory(rev.inventory_id)
-        seen_ids = set()
-        seen_names = set()
+        seen_ids = {}
+        seen_names = {}
 
         p('revision %d/%d file ids' % (revno, revcount))
         for file_id in inv:
             if file_id in seen_ids:
                 bailout('duplicated file_id {%s} in inventory for revision {%s}'
                         % (file_id, rid))
-            seen_ids.add(file_id)
+            seen_ids[file_id] = True
 
         i = 0
         len_inv = len(inv)
@@ -119,7 +117,7 @@
         for path, ie in inv.iter_entries():
             if path in seen_names:
                 bailout('duplicated path %r in inventory for revision {%s}' % (path, revid))
-            seen_names.add(path)
+            seen_names[path] = True
 
 
     p('done')

=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2005-05-19 06:37:21 +0000
+++ b/bzrlib/inventory.py	2005-05-19 09:59:49 +0000
@@ -453,11 +453,6 @@
         del self[ie.parent_id].children[ie.name]
 
 
-    def id_set(self):
-        from bzrlib import frozenset
-        return frozenset(self._byid)
-
-
     def to_element(self):
         """Convert to XML Element"""
         e = Element('inventory')
@@ -506,13 +501,24 @@
         if not isinstance(other, Inventory):
             return NotImplemented
 
-        if self.id_set() ^ other.id_set():
-            return 1
+        byid = self._byid
+        otherids = other._byid
 
-        for file_id in self._byid:
-            c = cmp(self[file_id], other[file_id])
+        if len(byid) != len(otherids):
+            # shortcut: obviously not the same
+            return 1                    
+        
+        for file_id in byid:
+            if file_id not in otherids:
+                return 1
+            
+            c = cmp(byid[file_id], otherids[file_id])
             if c: return c
 
+        for file_id in otherids:
+            if file_id not in byid:
+                return 1
+
         return 0
 
 

=== modified file 'bzrlib/remotebranch.py'
--- a/bzrlib/remotebranch.py	2005-05-19 06:37:21 +0000
+++ b/bzrlib/remotebranch.py	2005-05-19 09:59:49 +0000
@@ -169,10 +169,9 @@
     from revision import Revision
     from branch import Branch
     from inventory import Inventory
-    from bzrlib import set
 
-    got_invs = set()
-    got_texts = set()
+    got_invs = {}
+    got_texts = {}
 
     print 'read history'
     history = get_url('/.bzr/revision-history').readlines()
@@ -206,9 +205,9 @@
                 print '  fetch %s text {%s}' % (path, text_id)
                 text_f = get_url('/.bzr/text-store/%s' % text_id,
                                  compressed=True)
-                got_texts.add(text_id)
+                got_texts[text_id] = True
 
-            got_invs.add(inv_id)
+            got_invs.add[inv_id] = True
 
         print '----'
 

=== modified file 'bzrlib/tree.py'
--- a/bzrlib/tree.py	2005-05-11 07:45:56 +0000
+++ b/bzrlib/tree.py	2005-05-19 09:59:49 +0000
@@ -63,10 +63,6 @@
 
     __contains__ = has_id
 
-    def id_set(self):
-        """Return set of all ids in this tree."""
-        return self.inventory.id_set()
-
     def __iter__(self):
         return iter(self.inventory)
 



More information about the Pkg-bazaar-commits mailing list