Moved VCS detection from _vcs_help() to _vcs_version().
authorW. Trevor King <wking@drexel.edu>
Tue, 6 Oct 2009 10:37:21 +0000 (06:37 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 6 Oct 2009 10:37:21 +0000 (06:37 -0400)
The version string is useful information to have around, while the
help string is probably not.  For example, we use it in
darcs.Darcs._vcs_get_file_contents() to construct an incantation
appropriate to the version we're dealing with.

libbe/arch.py
libbe/bzr.py
libbe/darcs.py
libbe/git.py
libbe/hg.py
libbe/vcs.py

index c2d7cdec7234c3356b4b7b427a196b9866ae9833..daa8ac6114773997abfa4ed14ecc3705cbc833ab 100644 (file)
@@ -53,8 +53,8 @@ class Arch(vcs.VCS):
     _project_name = None
     _tmp_project = False
     _arch_paramdir = os.path.expanduser("~/.arch-params")
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         """Detect whether a directory is revision-controlled using Arch"""
index e9e0649615ef86a0c618228fa091f3f42c1f2221..ed9e03297b10d4b0641f94c282b128242ddbc91b 100644 (file)
@@ -37,8 +37,8 @@ class Bzr(vcs.VCS):
     name = "bzr"
     client = "bzr"
     versioned = True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output        
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, ".bzr") != None :
index 16005f2a71e065f2fbb8155920bf0fabea6632a9..a46403c33ebe0de165f88b174fe2c7a718bb60c9 100644 (file)
@@ -40,8 +40,10 @@ class Darcs(vcs.VCS):
     name="darcs"
     client="darcs"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
+        num_part = output.split(" ")[0]
+        self.parsed_version = [int(i) for i in num_part.split(".")]
         return output
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, "_darcs") != None :
@@ -97,9 +99,9 @@ class Darcs(vcs.VCS):
             return vcs.VCS._vcs_get_file_contents(self, path, revision,
                                               binary=binary)
         else:
-            try:
+            if self.parsed_version[0] >= 2:
                 return self._u_invoke_client("show", "contents", "--patch", revision, path)
-            except vcs.CommandError:
+            else:
                 # Darcs versions < 2.0.0pre2 lack the "show contents" command
 
                 status,output,error = self._u_invoke_client("diff", "--unified",
index 3abe3b816bd4bc5c63ed22f7578e7fe62391e416..628f9b9697f4273e75e59663a84f6722ceb8df48 100644 (file)
@@ -36,8 +36,8 @@ class Git(vcs.VCS):
     name="git"
     client="git"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         if self._u_search_parent_directories(path, ".git") != None :
index f8f8121dd9f63669e7bbfb7a592427ecc6c1105a..7cd4c2fa60146110c4fb372df5dd888c7401d25b 100644 (file)
@@ -36,8 +36,8 @@ class Hg(vcs.VCS):
     name="hg"
     client="hg"
     versioned=True
-    def _vcs_help(self):
-        status,output,error = self._u_invoke_client("--help")
+    def _vcs_version(self):
+        status,output,error = self._u_invoke_client("--version")
         return output
     def _vcs_detect(self, path):
         """Detect whether a directory is revision-controlled using Mercurial"""
index 6975a83a9e7a9aa53e09e4b8588a18f7f2e58468..74846608a5eb47de9f3818bbf6b87567d0a2dcd3 100644 (file)
@@ -124,13 +124,12 @@ class VCS(object):
         self._duplicateBasedir = None
         self._duplicateDirname = None
         self.encoding = encoding
-
-    def _vcs_help(self):
+        self.version = self._get_version()
+    def _vcs_version(self):
         """
-        Return the command help string.
-        (Allows a simple test to see if the client is installed.)
+        Return the VCS version string.
         """
-        pass
+        return "0.0"
     def _vcs_detect(self, path=None):
         """
         Detect whether a directory is revision controlled with this VCS.
@@ -229,15 +228,21 @@ class VCS(object):
         specified revision does not exist.
         """
         return None
-    def installed(self):
+    def _get_version(self):
         try:
-            self._vcs_help()
-            return True
+            ret = self._vcs_version()
+            return ret
         except OSError, e:
             if e.errno == errno.ENOENT:
-                return False
+                return None
+            else:
+                raise OSError, e
         except CommandError:
-            return False
+            return None
+    def installed(self):
+        if self.version != None:
+            return True
+        return False
     def detect(self, path="."):
         """
         Detect whether a directory is revision controlled with this VCS.