From bb645f8e489b9f50cd0aec7237ec9adb721797a8 Mon Sep 17 00:00:00 2001 From: Phil Schumm Date: Thu, 28 Jul 2011 07:42:11 -0500 Subject: Fixed problem with Hg support under version 1.9 (mercurial.dispatch.dispatch() now takes a single request object with option for capturing output stream) --- libbe/storage/vcs/hg.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'libbe/storage/vcs') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index d2274ee..acf391d 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -83,14 +83,12 @@ class Hg(base.VCS): assert len(kwargs) == 1, kwargs fullargs = ['--cwd', kwargs['cwd']] fullargs.extend(args) - stdout = sys.stdout - tmp_stdout = StringIO.StringIO() - sys.stdout = tmp_stdout + output = StringIO.StringIO() cwd = os.getcwd() - mercurial.dispatch.dispatch(fullargs) + req = mercurial.dispatch.request(fullargs, fout=output) + mercurial.dispatch.dispatch(req) os.chdir(cwd) - sys.stdout = stdout - return tmp_stdout.getvalue().rstrip('\n') + return output.getvalue().rstrip('\n') def _vcs_get_user_id(self): output = self._u_invoke_client( -- cgit From a37004c5e4b80a775cbb43e2f25b3376ae1673c0 Mon Sep 17 00:00:00 2001 From: Michel Alexandre Salim Date: Thu, 4 Aug 2011 17:50:32 +0200 Subject: Enhance Bzr.version_cmp to handle non-numeric versions bzr uses non-numeric tags to indicate prereleases; previously, this triggers an exception in be's Bzr module as version comparison is only supported between version strings that only contain numbers and dots. This patch extends version_cmp to support a single non-numeric pre-release string of arbitrary length (e.g. 'a', 'b', 'pre', 'rc'), and extends the docstring tests to cover this extension. Signed-off-by: Michel Alexandre Salim --- libbe/storage/vcs/bzr.py | 59 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 9 deletions(-) (limited to 'libbe/storage/vcs') diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py index 0a4275b..00435cb 100644 --- a/libbe/storage/vcs/bzr.py +++ b/libbe/storage/vcs/bzr.py @@ -87,8 +87,14 @@ class Bzr(base.VCS): 0 >>> b.version_cmp(2,3,2) -1 + >>> b.version_cmp(2,3,'a',5) + 1 >>> b.version_cmp(2,3,0) 1 + >>> b.version_cmp(2,3,1,'a',5) + 1 + >>> b.version_cmp(2,3,1,1) + -1 >>> b.version_cmp(3) -1 >>> b._version = '2.0.0pre2' @@ -96,9 +102,17 @@ class Bzr(base.VCS): >>> b.version_cmp(3) -1 >>> b.version_cmp(2,0,1) - Traceback (most recent call last): - ... - NotImplementedError: Cannot parse non-integer portion "0pre2" of Bzr version "2.0.0pre2" + -1 + >>> b.version_cmp(2,0,0,'pre',1) + 1 + >>> b.version_cmp(2,0,0,'pre',2) + 0 + >>> b.version_cmp(2,0,0,'pre',3) + -1 + >>> b.version_cmp(2,0,0,'a',3) + 1 + >>> b.version_cmp(2,0,0,'rc',1) + -1 """ if not hasattr(self, '_parsed_version') \ or self._parsed_version == None: @@ -108,16 +122,43 @@ class Bzr(base.VCS): try: self._parsed_version.append(int(num)) except ValueError, e: - self._parsed_version.append(num) + # bzr version number might contain non-numerical tags + import re + splitter = re.compile(r'[\D]') # Match non-digits + splits = splitter.split(num) + # if len(tag) > 1 some splits will be empty; remove + splits = filter(lambda s: s != '', splits) + tag_starti = len(splits[0]) + num_starti = num.find(splits[1], tag_starti) + tag = num[tag_starti:num_starti] + self._parsed_version.append(int(splits[0])) + self._parsed_version.append(tag) + self._parsed_version.append(int(splits[1])) for current,other in zip(self._parsed_version, args): - if type(current) != types.IntType: - raise NotImplementedError( - 'Cannot parse non-integer portion "%s" of Bzr version "%s"' - % (current, self.version())) + if type(current) != type (other): + # one of them is a pre-release string + if type(current) != types.IntType: + return -1 + else: + return 1 c = cmp(current,other) if c != 0: return c - return 0 + # see if one is longer than the other + verlen = len(self._parsed_version) + arglen = len(args) + if verlen == arglen: + return 0 + elif verlen > arglen: + if type(self._parsed_version[arglen]) != types.IntType: + return -1 # self is a prerelease + else: + return 1 + else: + if type(args[verlen]) != types.IntType: + return 1 # args is a prerelease + else: + return -1 def _vcs_get_user_id(self): # excerpted from bzrlib.builtins.cmd_whoami.run() -- cgit From b479cd6b717053c3fe119012e491e0ef447cb46a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 7 Sep 2011 22:09:00 -0400 Subject: Remove redundant re import from previous bzr version_cmp patch. --- libbe/storage/vcs/bzr.py | 1 - 1 file changed, 1 deletion(-) (limited to 'libbe/storage/vcs') diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py index 00435cb..6b625c2 100644 --- a/libbe/storage/vcs/bzr.py +++ b/libbe/storage/vcs/bzr.py @@ -123,7 +123,6 @@ class Bzr(base.VCS): self._parsed_version.append(int(num)) except ValueError, e: # bzr version number might contain non-numerical tags - import re splitter = re.compile(r'[\D]') # Match non-digits splits = splitter.split(num) # if len(tag) > 1 some splits will be empty; remove -- cgit From d5e6385f6fa162a4f41219d4f523cc27446defcd Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 7 Sep 2011 22:47:14 -0400 Subject: Move Bzr.version_cmp to VCS.version_cmp. The version comparison code will be useful for all VCSs. --- libbe/storage/vcs/base.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++ libbe/storage/vcs/bzr.py | 92 ----------------------------------------------- 2 files changed, 91 insertions(+), 92 deletions(-) (limited to 'libbe/storage/vcs') diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index d377398..22874a5 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -521,6 +521,97 @@ class VCS (libbe.storage.base.VersionedStorage): self._version = self._vcs_version() return self._version + def version_cmp(self, *args): + """Compare the installed VCS version `V_i` with another version + `V_o` (given in `*args`). Returns + + === =============== + 1 if `V_i > V_o` + 0 if `V_i == V_o` + -1 if `V_i < V_o` + === =============== + + Examples + -------- + + >>> v = VCS(repo='.') + >>> v._version = '2.3.1 (release)' + >>> v.version_cmp(2,3,1) + 0 + >>> v.version_cmp(2,3,2) + -1 + >>> v.version_cmp(2,3,'a',5) + 1 + >>> v.version_cmp(2,3,0) + 1 + >>> v.version_cmp(2,3,1,'a',5) + 1 + >>> v.version_cmp(2,3,1,1) + -1 + >>> v.version_cmp(3) + -1 + >>> v._version = '2.0.0pre2' + >>> v._parsed_version = None + >>> v.version_cmp(3) + -1 + >>> v.version_cmp(2,0,1) + -1 + >>> v.version_cmp(2,0,0,'pre',1) + 1 + >>> v.version_cmp(2,0,0,'pre',2) + 0 + >>> v.version_cmp(2,0,0,'pre',3) + -1 + >>> v.version_cmp(2,0,0,'a',3) + 1 + >>> v.version_cmp(2,0,0,'rc',1) + -1 + """ + if not hasattr(self, '_parsed_version') \ + or self._parsed_version == None: + num_part = self.version().split(' ')[0] + self._parsed_version = [] + for num in num_part.split('.'): + try: + self._parsed_version.append(int(num)) + except ValueError, e: + # bzr version number might contain non-numerical tags + splitter = re.compile(r'[\D]') # Match non-digits + splits = splitter.split(num) + # if len(tag) > 1 some splits will be empty; remove + splits = filter(lambda s: s != '', splits) + tag_starti = len(splits[0]) + num_starti = num.find(splits[1], tag_starti) + tag = num[tag_starti:num_starti] + self._parsed_version.append(int(splits[0])) + self._parsed_version.append(tag) + self._parsed_version.append(int(splits[1])) + for current,other in zip(self._parsed_version, args): + if type(current) != type (other): + # one of them is a pre-release string + if type(current) != types.IntType: + return -1 + else: + return 1 + c = cmp(current,other) + if c != 0: + return c + # see if one is longer than the other + verlen = len(self._parsed_version) + arglen = len(args) + if verlen == arglen: + return 0 + elif verlen > arglen: + if type(self._parsed_version[arglen]) != types.IntType: + return -1 # self is a prerelease + else: + return 1 + else: + if type(args[verlen]) != types.IntType: + return 1 # args is a prerelease + else: + return -1 + def installed(self): if self.version() != None: return True diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py index 6b625c2..c01b6c7 100644 --- a/libbe/storage/vcs/bzr.py +++ b/libbe/storage/vcs/bzr.py @@ -40,7 +40,6 @@ import re import shutil import StringIO import sys -import types import libbe import base @@ -68,97 +67,6 @@ 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` - -1 if `V_i < V_o` - === =============== - - Examples - -------- - - >>> b = Bzr(repo='.') - >>> b._version = '2.3.1 (release)' - >>> b.version_cmp(2,3,1) - 0 - >>> b.version_cmp(2,3,2) - -1 - >>> b.version_cmp(2,3,'a',5) - 1 - >>> b.version_cmp(2,3,0) - 1 - >>> b.version_cmp(2,3,1,'a',5) - 1 - >>> b.version_cmp(2,3,1,1) - -1 - >>> b.version_cmp(3) - -1 - >>> b._version = '2.0.0pre2' - >>> b._parsed_version = None - >>> b.version_cmp(3) - -1 - >>> b.version_cmp(2,0,1) - -1 - >>> b.version_cmp(2,0,0,'pre',1) - 1 - >>> b.version_cmp(2,0,0,'pre',2) - 0 - >>> b.version_cmp(2,0,0,'pre',3) - -1 - >>> b.version_cmp(2,0,0,'a',3) - 1 - >>> b.version_cmp(2,0,0,'rc',1) - -1 - """ - if not hasattr(self, '_parsed_version') \ - or self._parsed_version == None: - num_part = self.version().split(' ')[0] - self._parsed_version = [] - for num in num_part.split('.'): - try: - self._parsed_version.append(int(num)) - except ValueError, e: - # bzr version number might contain non-numerical tags - splitter = re.compile(r'[\D]') # Match non-digits - splits = splitter.split(num) - # if len(tag) > 1 some splits will be empty; remove - splits = filter(lambda s: s != '', splits) - tag_starti = len(splits[0]) - num_starti = num.find(splits[1], tag_starti) - tag = num[tag_starti:num_starti] - self._parsed_version.append(int(splits[0])) - self._parsed_version.append(tag) - self._parsed_version.append(int(splits[1])) - for current,other in zip(self._parsed_version, args): - if type(current) != type (other): - # one of them is a pre-release string - if type(current) != types.IntType: - return -1 - else: - return 1 - c = cmp(current,other) - if c != 0: - return c - # see if one is longer than the other - verlen = len(self._parsed_version) - arglen = len(args) - if verlen == arglen: - return 0 - elif verlen > arglen: - if type(self._parsed_version[arglen]) != types.IntType: - return -1 # self is a prerelease - else: - return 1 - else: - if type(args[verlen]) != types.IntType: - return 1 # args is a prerelease - else: - return -1 - def _vcs_get_user_id(self): # excerpted from bzrlib.builtins.cmd_whoami.run() try: -- cgit From 7d207f7c040db85da48ce3930663cfa10aa88864 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 7 Sep 2011 22:54:00 -0400 Subject: Adjust Mercurial execution so it works with version 1.9 and earlier. This makes the changes for 1.9 brought in by bb645f8e489b9f50cd0aec7237ec9adb721797a8 optional. If the Mercurial version is 1.9 or greater, the new code is used. Otherwise, the old code is used. --- libbe/storage/vcs/hg.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'libbe/storage/vcs') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index acf391d..b61e796 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -83,10 +83,16 @@ class Hg(base.VCS): assert len(kwargs) == 1, kwargs fullargs = ['--cwd', kwargs['cwd']] fullargs.extend(args) - output = StringIO.StringIO() cwd = os.getcwd() - req = mercurial.dispatch.request(fullargs, fout=output) - mercurial.dispatch.dispatch(req) + output = StringIO.StringIO() + if self.version_cmp(1,9): + req = mercurial.dispatch.request(fullargs, fout=output) + mercurial.dispatch.dispatch(req) + else: + stdout = sys.stdout + sys.stdout = output + mercurial.dispatch.dispatch(fullargs) + sys.stdout = stdout os.chdir(cwd) return output.getvalue().rstrip('\n') -- cgit From 86a140aaf4b799ee78864c7a520ba9fde9fb3382 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 7 Sep 2011 23:20:54 -0400 Subject: Oops, that forgot the equals part of Mercurial 1.9 or greater. --- libbe/storage/vcs/hg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libbe/storage/vcs') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index b61e796..758ea5a 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -85,7 +85,7 @@ class Hg(base.VCS): fullargs.extend(args) cwd = os.getcwd() output = StringIO.StringIO() - if self.version_cmp(1,9): + if self.version_cmp(1,9) >= 0: req = mercurial.dispatch.request(fullargs, fout=output) mercurial.dispatch.dispatch(req) else: -- cgit From 567c3151cab38140eb40eb2b0a08ba0c2ac6ec89 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 9 Nov 2011 06:54:43 -0500 Subject: Ran update_copyright.py. --- libbe/storage/vcs/bzr.py | 1 + libbe/storage/vcs/hg.py | 1 + 2 files changed, 2 insertions(+) (limited to 'libbe/storage/vcs') diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py index c01b6c7..865df6b 100644 --- a/libbe/storage/vcs/bzr.py +++ b/libbe/storage/vcs/bzr.py @@ -3,6 +3,7 @@ # Chris Ball # Gianluca Montecchi # Marien Zwart +# Michel Alexandre Salim # W. Trevor King # # This file is part of Bugs Everywhere. diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index 758ea5a..eade02e 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -3,6 +3,7 @@ # Chris Ball # Gianluca Montecchi # Marien Zwart +# Phil Schumm # W. Trevor King # # This file is part of Bugs Everywhere. -- cgit From 6f2d652b2697d7aec6bb48a2bf4d6fff1ef03521 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 13 Nov 2011 21:06:43 -0500 Subject: Fix my busted 1512c0e2a64e patch to libbe/util/encoding.py. Some temporary changes to encoding.py seem to have been added to commit 1512c0e2a64e19c8d4e5697257a4df5ddd8bc727 Author: W. Trevor King Date: Tue Nov 8 07:14:43 2011 -0500 by accident. The initial change came from discussions with Niall Douglas, during which I realized that "filesystem encoding" ususally means the encoding for the *path*, not the *contents*. To avoid further confusion I'd renamed `get_filesystem_encoding` to the less ambiguous `get_text_file_encoding`. This commit should complete the transition. --- libbe/storage/vcs/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libbe/storage/vcs') diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index 22874a5..eaaf2d8 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -199,7 +199,7 @@ class CachedPathID (object): >>> dir.cleanup() """ def __init__(self, encoding=None): - self.encoding = libbe.util.encoding.get_filesystem_encoding() + self.encoding = libbe.util.encoding.get_text_file_encoding() self._spacer_dirs = ['.be', 'bugs', 'comments'] def root(self, path): @@ -350,7 +350,7 @@ class VCS (libbe.storage.base.VersionedStorage): def __init__(self, *args, **kwargs): if 'encoding' not in kwargs: - kwargs['encoding'] = libbe.util.encoding.get_filesystem_encoding() + kwargs['encoding'] = libbe.util.encoding.get_text_file_encoding() libbe.storage.base.VersionedStorage.__init__(self, *args, **kwargs) self.versioned = False self.interspersed_vcs_files = False -- cgit