Removed libbe.storage.vcs.base._get_version
authorW. Trevor King <wking@drexel.edu>
Sat, 26 Jun 2010 15:58:08 +0000 (11:58 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 26 Jun 2010 15:58:08 +0000 (11:58 -0400)
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
libbe/storage/vcs/bzr.py
libbe/storage/vcs/darcs.py

index 62f4576a467b8f1894dadd5162c4ea4a1d72fcb0..594a10c1109104995b7a6f5eec7eaa65cf1391b3 100644 (file)
@@ -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='.'):
index facb8695b9b82082f7f4b1bf838e23c30a75e52a..45a6cd2fbce31581aca831f81cdd6e808e2b8a1b 100644 (file)
@@ -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
index 556404e1b9456cd1565d3fbfd87703ef30dc7500..7ff45544adc6a960711835e341a4e8857ff67fed 100644 (file)
@@ -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