From 8d7ee45073087fddf3155c08ae51dfc97b0927fa Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 26 Jun 2010 11:58:08 -0400 Subject: Removed libbe.storage.vcs.base._get_version It had been catching exceptions from ._vcs_version, but ._vcs_version should catch its own exceptions. Also use cached results from .version in Darcs and Bzr.version_cmp() rather than calling ._vcs_version directly. --- libbe/storage/vcs/base.py | 19 ++++++------------- libbe/storage/vcs/bzr.py | 8 ++++---- libbe/storage/vcs/darcs.py | 8 ++++---- 3 files changed, 14 insertions(+), 21 deletions(-) (limited to 'libbe/storage/vcs') diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index 62f4576..594a10c 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -518,21 +518,9 @@ class VCS (libbe.storage.base.VersionedStorage): def version(self): # Cache version string for efficiency. if not hasattr(self, '_version'): - self._version = self._get_version() + self._version = self._vcs_version() return self._version - def _get_version(self): - try: - ret = self._vcs_version() - return ret - except OSError, e: - if e.errno == errno.ENOENT: - return None - else: - raise OSError, e - except CommandError: - return None - def installed(self): if self.version() != None: return True @@ -547,6 +535,11 @@ class VCS (libbe.storage.base.VersionedStorage): """ if not hasattr(self, 'user_id'): self.user_id = self._vcs_get_user_id() + if self.user_id == None: + # guess missing info + name = libbe.ui.util.user.get_fallback_username() + email = libbe.ui.util.user.get_fallback_email() + self.user_id = libbe.ui.util.user.create_user_id(name, email) return self.user_id def _detect(self, path='.'): diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py index facb869..45a6cd2 100644 --- a/libbe/storage/vcs/bzr.py +++ b/libbe/storage/vcs/bzr.py @@ -81,7 +81,7 @@ class Bzr(base.VCS): -------- >>> b = Bzr(repo='.') - >>> b._vcs_version = lambda : "2.3.1 (release)" + >>> b._version = '2.3.1 (release)' >>> b.version_cmp(2,3,1) 0 >>> b.version_cmp(2,3,2) @@ -90,7 +90,7 @@ class Bzr(base.VCS): 1 >>> b.version_cmp(3) -1 - >>> b._vcs_version = lambda : "2.0.0pre2" + >>> b._version = '2.0.0pre2' >>> b._parsed_version = None >>> b.version_cmp(3) -1 @@ -101,7 +101,7 @@ class Bzr(base.VCS): """ if not hasattr(self, '_parsed_version') \ or self._parsed_version == None: - num_part = self._vcs_version().split(' ')[0] + num_part = self.version().split(' ')[0] self._parsed_version = [] for num in num_part.split('.'): try: @@ -112,7 +112,7 @@ class Bzr(base.VCS): if type(current) != types.IntType: raise NotImplementedError( 'Cannot parse non-integer portion "%s" of Bzr version "%s"' - % (current, self._vcs_version())) + % (current, self.version())) c = cmp(current,other) if c != 0: return c diff --git a/libbe/storage/vcs/darcs.py b/libbe/storage/vcs/darcs.py index 556404e..7ff4554 100644 --- a/libbe/storage/vcs/darcs.py +++ b/libbe/storage/vcs/darcs.py @@ -74,7 +74,7 @@ class Darcs(base.VCS): -------- >>> d = Darcs(repo='.') - >>> d._vcs_version = lambda : "2.3.1 (release)" + >>> d._version = '2.3.1 (release)' >>> d.version_cmp(2,3,1) 0 >>> d.version_cmp(2,3,2) @@ -83,7 +83,7 @@ class Darcs(base.VCS): 1 >>> d.version_cmp(3) -1 - >>> d._vcs_version = lambda : "2.0.0pre2" + >>> d._version = '2.0.0pre2' >>> d._parsed_version = None >>> d.version_cmp(3) -1 @@ -94,7 +94,7 @@ class Darcs(base.VCS): """ if not hasattr(self, '_parsed_version') \ or self._parsed_version == None: - num_part = self._vcs_version().split(' ')[0] + num_part = self.version().split(' ')[0] self._parsed_version = [] for num in num_part.split('.'): try: @@ -105,7 +105,7 @@ class Darcs(base.VCS): if type(current) != types.IntType: raise NotImplementedError( 'Cannot parse non-integer portion "%s" of Darcs version "%s"' - % (current, self._vcs_version())) + % (current, self.version())) c = cmp(current,other) if c != 0: return c -- cgit