[Pkg-bazaar-commits] ./bzr/unstable r540: - use builtin set object in python2.4

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


------------------------------------------------------------
revno: 540
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Thu 2005-05-19 16:37:21 +1000
message:
  - use builtin set object in python2.4 
    (suggested by Mario Pernici)
  - clean up some uses of set() that can simply be lists or dicts
  - remove some imports from the bzrlib namespace 
modified:
  bzrlib/__init__.py
  bzrlib/branch.py
  bzrlib/check.py
  bzrlib/commands.py
  bzrlib/diff.py
  bzrlib/info.py
  bzrlib/inventory.py
  bzrlib/remotebranch.py
  bzrlib/statcache.py
-------------- next part --------------
=== modified file 'bzrlib/__init__.py'
--- a/bzrlib/__init__.py	2005-05-17 07:51:51 +0000
+++ b/bzrlib/__init__.py	2005-05-19 06:37:21 +0000
@@ -42,8 +42,24 @@
 
 import locale
 user_encoding = locale.getpreferredencoding()
+del locale
 
 __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/branch.py'
--- a/bzrlib/branch.py	2005-05-17 08:39:35 +0000
+++ b/bzrlib/branch.py	2005-05-19 06:37:21 +0000
@@ -15,8 +15,6 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
-from sets import Set
-
 import sys, os, os.path, random, time, sha, sets, types, re, shutil, tempfile
 import traceback, socket, fnmatch, difflib, time
 from binascii import hexlify
@@ -679,7 +677,7 @@
         if to_dir_ie.kind not in ('directory', 'root_directory'):
             bailout("destination %r is not a directory" % to_abs)
 
-        to_idpath = Set(inv.get_idpath(to_dir_id))
+        to_idpath = inv.get_idpath(to_dir_id)
 
         for f in from_paths:
             if not tree.has_filename(f):

=== modified file 'bzrlib/check.py'
--- a/bzrlib/check.py	2005-04-13 04:56:45 +0000
+++ b/bzrlib/check.py	2005-05-19 06:37:21 +0000
@@ -21,13 +21,14 @@
 # consistency checks
 
 import sys
-from sets import Set
 
 from trace import mutter
 from errors import bailout
 import osutils
 
 def check(branch, progress=True):
+    from bzrlib import set
+
     out = sys.stdout
 
     # TODO: factor out
@@ -45,7 +46,7 @@
 
     p('history of %r' % branch.base)
     last_ptr = None
-    checked_revs = Set()
+    checked_revs = set()
     
     history = branch.revision_history()
     revno = 0
@@ -70,8 +71,8 @@
         ## 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 = set()
+        seen_names = set()
 
         p('revision %d/%d file ids' % (revno, revcount))
         for file_id in inv:

=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2005-05-17 08:27:03 +0000
+++ b/bzrlib/commands.py	2005-05-19 06:37:21 +0000
@@ -17,7 +17,6 @@
 
 
 import sys, os, time, os.path
-from sets import Set
 
 import bzrlib
 from bzrlib.trace import mutter, note, log_error

=== modified file 'bzrlib/diff.py'
--- a/bzrlib/diff.py	2005-05-17 08:20:31 +0000
+++ b/bzrlib/diff.py	2005-05-19 06:37:21 +0000
@@ -15,8 +15,6 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from sets import Set, ImmutableSet
-
 from trace import mutter
 from errors import BzrError
 

=== modified file 'bzrlib/info.py'
--- a/bzrlib/info.py	2005-05-11 06:12:44 +0000
+++ b/bzrlib/info.py	2005-05-19 06:37:21 +0000
@@ -16,7 +16,6 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from sets import Set
 import time
 
 from osutils import format_date
@@ -82,9 +81,9 @@
     history = b.revision_history()
     revno = len(history)
     print '  %8d revision%s' % (revno, plural(revno))
-    committers = Set()
+    committers = {}
     for rev in history:
-        committers.add(b.get_revision(rev).committer)
+        committers[b.get_revision(rev).committer)] = True
     print '  %8d committer%s' % (len(committers), plural(len(committers)))
     if revno > 0:
         firstrev = b.get_revision(history[0])

=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2005-05-12 02:19:09 +0000
+++ b/bzrlib/inventory.py	2005-05-19 06:37:21 +0000
@@ -21,7 +21,6 @@
 
 
 import sys, os.path, types, re
-from sets import Set
 
 try:
     from cElementTree import Element, ElementTree, SubElement
@@ -455,7 +454,8 @@
 
 
     def id_set(self):
-        return Set(self._byid)
+        from bzrlib import frozenset
+        return frozenset(self._byid)
 
 
     def to_element(self):

=== modified file 'bzrlib/remotebranch.py'
--- a/bzrlib/remotebranch.py	2005-05-17 08:34:38 +0000
+++ b/bzrlib/remotebranch.py	2005-05-19 06:37:21 +0000
@@ -25,7 +25,6 @@
 
 
 import gzip
-from sets import Set
 from cStringIO import StringIO
 import urllib2
 
@@ -170,9 +169,10 @@
     from revision import Revision
     from branch import Branch
     from inventory import Inventory
+    from bzrlib import set
 
-    got_invs = Set()
-    got_texts = Set()
+    got_invs = set()
+    got_texts = set()
 
     print 'read history'
     history = get_url('/.bzr/revision-history').readlines()

=== modified file 'bzrlib/statcache.py'
--- a/bzrlib/statcache.py	2005-05-17 09:05:11 +0000
+++ b/bzrlib/statcache.py	2005-05-19 06:37:21 +0000
@@ -136,10 +136,9 @@
         
         
 def load_cache(basedir):
-    from sets import Set
     import re
     cache = {}
-    seen_paths = Set()
+    seen_paths = {}
 
     sha_re = re.compile(r'[a-f0-9]{40}')
 
@@ -168,7 +167,7 @@
         path = a2b_qp(f[2]).decode('utf-8')
         if path in seen_paths:
             raise BzrCheckError("duplicated path in cache: %r" % path)
-        seen_paths.add(path)
+        seen_paths[path] = True
         
         entry = (file_id, text_sha, path) + tuple([long(x) for x in f[3:]])
         if len(entry) != 8:
@@ -218,15 +217,12 @@
 
     to_update -- Sequence of (file_id, path) pairs to check.
     """
-
-    from sets import Set
-
     stat_cnt = missing_cnt = hardcheck = change_cnt = 0
 
-    # files that have been recently touched and can't be
+    # dangerfiles have been recently touched and can't be
     # committed to a persistent cache yet.
+    dangerfiles = {}
     
-    dangerfiles = Set()
     now = int(time.time())
 
     ## mutter('update statcache under %r' % basedir)
@@ -245,7 +241,7 @@
             continue
 
         if (fp[FP_MTIME] >= now) or (fp[FP_CTIME] >= now):
-            dangerfiles.add(file_id)
+            dangerfiles[file_id] = True
 
         if cacheentry and (cacheentry[3:] == fp):
             continue                    # all stat fields unchanged



More information about the Pkg-bazaar-commits mailing list