From 5323cc1ba94095938c54a2853a3827c14b420e66 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 6 Oct 2009 06:37:21 -0400 Subject: Moved VCS detection from _vcs_help() to _vcs_version(). 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 | 4 ++-- libbe/bzr.py | 4 ++-- libbe/darcs.py | 10 ++++++---- libbe/git.py | 4 ++-- libbe/hg.py | 4 ++-- libbe/vcs.py | 25 +++++++++++++++---------- 6 files changed, 29 insertions(+), 22 deletions(-) (limited to 'libbe') diff --git a/libbe/arch.py b/libbe/arch.py index c2d7cde..daa8ac6 100644 --- a/libbe/arch.py +++ b/libbe/arch.py @@ -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""" diff --git a/libbe/bzr.py b/libbe/bzr.py index e9e0649..ed9e032 100644 --- a/libbe/bzr.py +++ b/libbe/bzr.py @@ -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 : diff --git a/libbe/darcs.py b/libbe/darcs.py index 16005f2..a46403c 100644 --- a/libbe/darcs.py +++ b/libbe/darcs.py @@ -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", diff --git a/libbe/git.py b/libbe/git.py index 3abe3b8..628f9b9 100644 --- a/libbe/git.py +++ b/libbe/git.py @@ -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 : diff --git a/libbe/hg.py b/libbe/hg.py index f8f8121..7cd4c2f 100644 --- a/libbe/hg.py +++ b/libbe/hg.py @@ -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""" diff --git a/libbe/vcs.py b/libbe/vcs.py index 6975a83..7484660 100644 --- a/libbe/vcs.py +++ b/libbe/vcs.py @@ -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. -- cgit From 5ccc639e7c04abc97db15eb15677a256e9400b44 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 6 Oct 2009 06:47:10 -0400 Subject: Oops, fixed return typo in libbe.darcs.Darcs._vcs_get_file_contents() For self.parsed_version[0] >= 2, was returning the entire output of ._u_invoke_client() (status, output, and error). Now it just returns the output, which is what we want. This fixes Chris' failed test: ====================================================================== FAIL: Should get file contents as committed to specified revision. ---------------------------------------------------------------------- Traceback (most recent call last): File "libbe/vcs.py", line 852, in test_revision_file_contents_as_committed self.test_contents['rev_1'], committed_contents) AssertionError: 'Lorem ipsum' != (0, 'Lorem ipsum', '') ---------------------------------------------------------------------- --- libbe/darcs.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'libbe') diff --git a/libbe/darcs.py b/libbe/darcs.py index a46403c..9115886 100644 --- a/libbe/darcs.py +++ b/libbe/darcs.py @@ -97,20 +97,20 @@ class Darcs(vcs.VCS): def _vcs_get_file_contents(self, path, revision=None, binary=False): if revision == None: return vcs.VCS._vcs_get_file_contents(self, path, revision, - binary=binary) + binary=binary) else: if self.parsed_version[0] >= 2: - return self._u_invoke_client("show", "contents", "--patch", revision, path) + status,output,error = self._u_invoke_client( \ + "show", "contents", "--patch", revision, path) + return output else: # Darcs versions < 2.0.0pre2 lack the "show contents" command - status,output,error = self._u_invoke_client("diff", "--unified", - "--from-patch", - revision, path) + status,output,error = self._u_invoke_client( \ + "diff", "--unified", "--from-patch", revision, path) major_patch = output - status,output,error = self._u_invoke_client("diff", "--unified", - "--patch", - revision, path) + status,output,error = self._u_invoke_client( \ + "diff", "--unified", "--patch", revision, path) target_patch = output # "--output -" to be supported in GNU patch > 2.5.9 -- cgit