From 76d983ec670ec7f09dace232e8553a80b2a08878 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 28 Jan 2010 11:47:59 -0500 Subject: Fix bzrlib.builtins.cmd_ls() recursion argument for pre 2.0 bzrlibs. $ python test.py libbe.storage.vcs.bzr ... ====================================================================== ERROR: Children list should be revision dependent. ---------------------------------------------------------------------- Traceback (most recent call last): File ".../libbe/storage/base.py", line 997, in test_ get_previous_children ret = sorted(self.s.children('parent', revision=revs[i])) File ".../libbe/storage/base.py", line 314, in child ren return self._children(*args, **kwargs) File ".../libbe/storage/vcs/base.py", line 811, in _ children path = self.path(id, revision, relpath=False) File ".../libbe/storage/vcs/base.py", line 716, in p ath path = self._vcs_path(id, revision) File ".../libbe/storage/vcs/bzr.py", line 145, in _v cs_path self.repo, revision=revision, recursive=True) File ".../libbe/storage/vcs/bzr.py", line 163, in _v cs_listdir cmd.run(revision=revision, path=path, recursive=recursive) File "/usr/lib/python2.5/site-packages/bzrlib/commands.py", line 800, in ignor e_pipe result = func(*args, **kwargs) TypeError: run() got an unexpected keyword argument 'recursive' ... The change is due to (in bzr.dev): revno: 4206.2.1 revision-id: ian.clatworthy@canonical.com-20090326133831-orvicmmc6w29mpfp parent: pqm@pqm.ubuntu.com-20090326063330-evutyvml3067dpsz committer: Ian Clatworthy branch nick: bzr.ls-recursive-off timestamp: Thu 2009-03-26 23:38:31 +1000 message: ls should be non-recursive by default Which occured between bzr-1.9rc1 and 2.0rc1.: bzr.dev$ bzr tags 2.0rc1 4634.9.1 ... bzr-1.9rc1 3815.3.1 bzr-2.0.1 4634.73.2 ... --- libbe/storage/vcs/bzr.py | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py index 1db50f8..b617d68 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: @@ -160,7 +200,11 @@ 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) == 1: + cmd.run(revision=revision, path=path, recursive=recursive) + else: # Pre-2.0 Bazaar + cmd.run(revision=revision, path=path, + non_recursive=not recursive) except bzrlib.errors.BzrCommandError, e: if 'not present in revision' in str(e): raise base.InvalidPath(path, root=self.repo, revision=revision) -- cgit From 9ef5ba29e9fc2804784b7f33dde80000a16f43cb Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 28 Jan 2010 12:46:18 -0500 Subject: Fix bzrlib.builtins.cmd_cat() output for pre 1.6.0 bzrlibs. Fixed in bzr.dev revno: 3341.2.1 revision-id: bialix@ukr.net-20080407074826-5lwuyv4dn1qlijg4 parent: pqm@pqm.ubuntu.com-20080407044456-s1a9orh0kssphdh9 committer: Alexander Belchenko branch nick: cmd-cat timestamp: Mon 2008-04-07 10:48:26 +0300 message: `bzr cat` no more internally used Tree.print_file(). Merged into bzr.dev's trunk revno: 3512 [merge] revision-id: pqm@pqm.ubuntu.com-20080626004245-dnw85so4xqg8r9hy parent: pqm@pqm.ubuntu.com-20080625230724-lyux37pu8nx8tq34 parent: aaron@aaronbentley.com-20080626001706-wo3w74fwgliy12s4 committer: Canonical.com Patch Queue Manager branch nick: +trunk timestamp: Thu 2008-06-26 01:42:45 +0100 message: (bialix) Deprectate (Branch|Repository).print_file, fix cmd_cat Before bzr branch 1.6 bzr.dev$ bzr tags ... bzr-1.5rc1 3418.6.3 bzr-1.6 3606.5.9 ... Fixes: python test.py -q libbe.storage.vcs.bzr ...............................FSome value:1E.. ====================================================================== ERROR: Get should be able to return the previous version. ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/wking/src/fun/be/be.wtk/libbe/storage/base.py", line 976, in test_ get_previous_version ret = self.s.get(self.id, revision=revs[i]) File "/home/wking/src/fun/be/be.wtk/libbe/storage/base.py", line 335, in get value = self._get(*args, **kwargs) File "/home/wking/src/fun/be/be.wtk/libbe/storage/vcs/base.py", line 849, in _ get raise InvalidID(id, revision) InvalidID: unlikely id in revision 1 ... --- libbe/storage/vcs/bzr.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py index b617d68..03a64f8 100644 --- a/libbe/storage/vcs/bzr.py +++ b/libbe/storage/vcs/bzr.py @@ -172,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) == -1: + # 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) == -1: + cmd.outf = sys.stdout + sys.stdout = stdout return cmd.outf.getvalue() def _vcs_path(self, id, revision): @@ -200,7 +208,7 @@ class Bzr(base.VCS): cmd = bzrlib.builtins.cmd_ls() cmd.outf = StringIO.StringIO() try: - if self.version_cmp(2,0,0) == 1: + if self.version_cmp(2,0,0) >= 0: cmd.run(revision=revision, path=path, recursive=recursive) else: # Pre-2.0 Bazaar cmd.run(revision=revision, path=path, -- cgit From 7e120421446f88f9bde0674f57fb1667c5f70ebd Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 28 Jan 2010 13:06:06 -0500 Subject: Work around "bzr ls --non-recursive PATH : no list" bug in old bzrlib. See: https://bugs.launchpad.net/bzr/+bug/158690 Bug affected versions: 0.90.0 (reported) 1.3.1 (my test suite hit it) Doesn't affect versions: 2.0+ (non_recursive -> recursive) But I haven't isolated the source more specifically. Working around it for everything < 2.0 should be safe, but the cutoff could be fine-tuned if someone wants to dig through the bzr.dev history... --- libbe/storage/vcs/bzr.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py index 03a64f8..ce140bc 100644 --- a/libbe/storage/vcs/bzr.py +++ b/libbe/storage/vcs/bzr.py @@ -172,7 +172,7 @@ 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) == -1: + 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 @@ -183,7 +183,7 @@ class Bzr(base.VCS): raise base.InvalidPath(path, root=self.repo, revision=revision) raise finally: - if self.version_cmp(2,0,0) == -1: + if self.version_cmp(2,0,0) < 0: cmd.outf = sys.stdout sys.stdout = stdout return cmd.outf.getvalue() @@ -210,15 +210,20 @@ class Bzr(base.VCS): try: if self.version_cmp(2,0,0) >= 0: cmd.run(revision=revision, path=path, recursive=recursive) - else: # Pre-2.0 Bazaar + 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=not recursive) + 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): -- cgit