aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2010-01-28 13:17:42 -0500
committerW. Trevor King <wking@drexel.edu>2010-01-28 13:17:42 -0500
commita4b5a5e599d090e77374dce5738cf71261b2f00f (patch)
tree0a08c4a643585300a631bd63c1c8fb457c2bf0ff
parent811117714a99252782a3eb064ff9e6346b77403a (diff)
parent7e120421446f88f9bde0674f57fb1667c5f70ebd (diff)
downloadbugseverywhere-a4b5a5e599d090e77374dce5738cf71261b2f00f.tar.gz
Add some workarounds for older bzrlibs. Tested on 1.3.1
-rw-r--r--libbe/storage/vcs/bzr.py59
1 files changed, 58 insertions, 1 deletions
diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py
index 1db50f8..ce140bc 100644
--- a/libbe/storage/vcs/bzr.py
+++ b/libbe/storage/vcs/bzr.py
@@ -62,6 +62,46 @@ class Bzr(base.VCS):
return None
return bzrlib.__version__
+ def version_cmp(self, *args):
+ """
+ Compare the installed Bazaar version V_i with another version
+ V_o (given in *args). Returns
+ 1 if V_i > V_o,
+ 0 if V_i == V_o, and
+ -1 if V_i < V_o
+ >>> b = Bzr(repo='.')
+ >>> b._vcs_version = lambda : "2.3.1 (release)"
+ >>> b.version_cmp(2,3,1)
+ 0
+ >>> b.version_cmp(2,3,2)
+ -1
+ >>> b.version_cmp(2,3,0)
+ 1
+ >>> b.version_cmp(3)
+ -1
+ >>> b._vcs_version = lambda : "2.0.0pre2"
+ >>> b._parsed_version = None
+ >>> b.version_cmp(3)
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: Cannot parse "2.0.0pre2" portion of Bazaar version "2.0.0pre2"
+ invalid literal for int() with base 10: '0pre2'
+ """
+ if not hasattr(self, '_parsed_version') \
+ or self._parsed_version == None:
+ num_part = self._vcs_version().split(' ')[0]
+ try:
+ self._parsed_version = [int(i) for i in num_part.split('.')]
+ except ValueError, e:
+ raise NotImplementedError(
+ 'Cannot parse "%s" portion of Bazaar version "%s"\n %s'
+ % (num_part, self._vcs_version(), str(e)))
+ cmps = [cmp(a,b) for a,b in zip(self._parsed_version, args)]
+ for c in cmps:
+ if c != 0:
+ return c
+ return 0
+
def _vcs_get_user_id(self):
# excerpted from bzrlib.builtins.cmd_whoami.run()
try:
@@ -132,12 +172,20 @@ class Bzr(base.VCS):
revision = self._parse_revision_string(revision)
cmd = bzrlib.builtins.cmd_cat()
cmd.outf = StringIO.StringIO()
+ if self.version_cmp(1,6,0) < 0:
+ # old bzrlib cmd_cat uses sys.stdout not self.outf for output.
+ stdout = sys.stdout
+ sys.stdout = cmd.outf
try:
cmd.run(filename=path, revision=revision)
except bzrlib.errors.BzrCommandError, e:
if 'not present in revision' in str(e):
raise base.InvalidPath(path, root=self.repo, revision=revision)
raise
+ finally:
+ if self.version_cmp(2,0,0) < 0:
+ cmd.outf = sys.stdout
+ sys.stdout = stdout
return cmd.outf.getvalue()
def _vcs_path(self, id, revision):
@@ -160,13 +208,22 @@ class Bzr(base.VCS):
cmd = bzrlib.builtins.cmd_ls()
cmd.outf = StringIO.StringIO()
try:
- cmd.run(revision=revision, path=path, recursive=recursive)
+ if self.version_cmp(2,0,0) >= 0:
+ cmd.run(revision=revision, path=path, recursive=recursive)
+ else:
+ # Pre-2.0 Bazaar (non_recursive)
+ # + working around broken non_recursive+path implementation
+ # (https://bugs.launchpad.net/bzr/+bug/158690)
+ cmd.run(revision=revision, path=path,
+ non_recursive=False)
except bzrlib.errors.BzrCommandError, e:
if 'not present in revision' in str(e):
raise base.InvalidPath(path, root=self.repo, revision=revision)
raise
children = cmd.outf.getvalue().rstrip('\n').splitlines()
children = [self._u_rel_path(c, path) for c in children]
+ if self.version_cmp(2,0,0) < 0 and recursive == False:
+ children = [c for c in children if os.path.sep not in c]
return children
def _vcs_commit(self, commitfile, allow_empty=False):