minor patch using the set builtin
Mario Pernici
Mario.Pernici at mi.infn.it
Wed May 18 17:29:15 BST 2005
Hello,
Bazaar-ng is very interesting!
As a newbie to revision control, I find it easy to use;
and being in Python, I have a chance of seeing how it works.
I have a couple of comments:
-one can use the built-ins basestring and set instead of
types.StringTypes and sets.Set respectively (see attached patch);
-in the tutorial .bzr.log is in the repository directory,
while it is really in $HOME .
Bye
Mario
-------------- next part --------------
*** modified file 'branch.py'
--- branch.py
+++ branch.py
@@ -15,9 +15,10 @@
# 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
+try: set
+except NameError: from sets import Set as set
+
+import sys, os, os.path, random, time, sha, sets, re, shutil, tempfile
import traceback, socket, fnmatch, difflib, time
from binascii import hexlify
@@ -146,7 +147,7 @@
def controlfilename(self, file_or_path):
"""Return location relative to branch."""
- if isinstance(file_or_path, types.StringTypes):
+ if isinstance(file_or_path, basestring):
file_or_path = [file_or_path]
return os.path.join(self.base, bzrlib.BZRDIR, *file_or_path)
@@ -288,7 +289,7 @@
# TODO: Re-adding a file that is removed in the working copy
# should probably put it back with the previous ID.
- if isinstance(files, types.StringTypes):
+ if isinstance(files, basestring):
files = [files]
inv = self.read_working_inventory()
@@ -372,7 +373,7 @@
## TODO: Normalize names
## TODO: Remove nested loops; better scalability
- if isinstance(files, types.StringTypes):
+ if isinstance(files, basestring):
files = [files]
tree = self.working_tree()
@@ -838,7 +839,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 = set(inv.get_idpath(to_dir_id))
for f in from_paths:
if not tree.has_filename(f):
*** modified file 'check.py'
--- check.py
+++ check.py
@@ -21,7 +21,9 @@
# consistency checks
import sys
-from sets import Set
+try: set
+except NameError: from sets import Set as set
+
from trace import mutter
from errors import bailout
@@ -45,7 +47,7 @@
p('history of %r' % branch.base)
last_ptr = None
- checked_revs = Set()
+ checked_revs = set()
history = branch.revision_history()
revno = 0
@@ -70,8 +72,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 'commands.py'
--- commands.py
+++ commands.py
@@ -62,8 +62,7 @@
-import sys, os, time, types, shutil, tempfile, fnmatch, difflib, os.path
-from sets import Set
+import sys, os, time, shutil, tempfile, fnmatch, difflib, os.path
from pprint import pprint
from stat import *
from glob import glob
@@ -467,7 +466,7 @@
fromfile=DEVNULL,
tofile=new_label + new_name + idlabel)
elif file_state == 'D':
- assert isinstance(old_name, types.StringTypes)
+ assert isinstance(old_name, basestring)
print '*** deleted %s %r' % (kind, old_name)
if kind == 'file':
diffit(old_tree.get_file(fid).readlines(), [],
@@ -717,6 +716,7 @@
TODO: Command to show only the email-address part as parsed out.
"""
+ print 'Just checking...'
print bzrlib.osutils.username()
*** modified file 'diff.py'
--- diff.py
+++ diff.py
@@ -15,7 +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
from trace import mutter
*** modified file 'info.py'
--- info.py
+++ info.py
@@ -16,7 +16,9 @@
# 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
+try: set
+except NameError: from sets import Set as set
+
import time
import bzrlib
@@ -60,7 +62,7 @@
history = b.revision_history()
revno = len(history)
print ' %8d revision%s' % (revno, plural(revno))
- committers = Set()
+ committers = set()
for rev in history:
committers.add(b.get_revision(rev).committer)
print ' %8d committer%s' % (len(committers), plural(len(committers)))
*** modified file 'inventory.py'
--- inventory.py
+++ inventory.py
@@ -23,8 +23,10 @@
ROOT_ID = "TREE_ROOT"
-import sys, os.path, types, re
-from sets import Set
+import sys, os.path, re
+try: set
+except NameError: from sets import Set as set
+
try:
from cElementTree import Element, ElementTree, SubElement
@@ -470,7 +472,7 @@
def id_set(self):
- return Set(self._byid)
+ return set(self._byid)
def to_element(self):
@@ -570,7 +572,7 @@
Returns None iff the path is not found.
"""
- if isinstance(name, types.StringTypes):
+ if isinstance(name, basestring):
name = splitpath(name)
mutter("lookup path %r" % name)
*** modified file 'remotebranch.py'
--- remotebranch.py
+++ remotebranch.py
@@ -22,7 +22,9 @@
import urllib2, gzip, zlib
-from sets import Set
+try: set
+except NameError: from sets import Set as set
+
from cStringIO import StringIO
from errors import BzrError
@@ -58,8 +60,8 @@
raise BzrError("remote fetch failed: %r: %s" % (url, e))
-got_invs = Set()
-got_texts = Set()
+got_invs = set()
+got_texts = set()
print 'read history'
history = get_url('/.bzr/revision-history').readlines()
*** modified file 'store.py'
--- store.py
+++ store.py
@@ -22,7 +22,7 @@
__copyright__ = "Copyright (C) 2005 Canonical Ltd."
__author__ = "Martin Pool <mbp at canonical.com>"
-import os, tempfile, types, osutils, gzip, errno
+import os, tempfile, osutils, gzip, errno
from stat import ST_SIZE
from StringIO import StringIO
from trace import mutter
@@ -87,7 +87,7 @@
# TODO: Can be optimized by copying at the same time as
# computing the sum.
mutter("add store entry %r" % (fileid))
- if isinstance(f, types.StringTypes):
+ if isinstance(f, basestring):
content = f
else:
content = f.read()
More information about the bazaar
mailing list