[PATCH] Factorize VC constructor code
- From: Vincent Legoll <vincent legoll gmail com>
- To: meld-list <meld-list gnome org>
- Subject: [PATCH] Factorize VC constructor code
- Date: Sat, 4 Apr 2009 19:06:08 +0200
The attached patch should be a no-op, behavior-wise
and remove some duplicated code in VC constructors.
CVS, RCS & SVN, now don't need one any more.
The remaining specific constructors are:
- git: handle tree cache, GIT_DIR
- monotone: tree cache, find mtn version
- bzr, darcs, tla: tree cache
They now use super() to get access to parent's
constructor.
I'll remove the tree-cache need next.
--
Vincent Legoll
Index: vc/cvs.py
===================================================================
--- vc/cvs.py (revision 1326)
+++ vc/cvs.py (working copy)
@@ -33,13 +33,9 @@
CMD = "cvs"
NAME = "CVS"
VC_DIR = "CVS"
+ VC_ROOT_WALK = False
PATCH_INDEX_RE = "^Index:(.*)$"
- def __init__(self, location):
- if not os.path.isdir(os.path.join(location, self.VC_DIR)):
- raise ValueError
- self.root = location
-
def commit_command(self, message):
return [self.CMD,"commit","-m",message]
def diff_command(self):
Index: vc/darcs.py
===================================================================
--- vc/darcs.py (revision 1326)
+++ vc/darcs.py (working copy)
@@ -43,7 +43,7 @@
def __init__(self, location):
self._cached_statuses = None
- _vc.Vc.__init__(self, location)
+ super(Vc, self).__init__(location)
def commit_command(self, message):
return [self.CMD, "record",
Index: vc/bzr.py
===================================================================
--- vc/bzr.py (revision 1326)
+++ vc/bzr.py (working copy)
@@ -36,7 +36,7 @@
def __init__(self, location):
self._tree_cache = None
- _vc.Vc.__init__(self, location)
+ super(Vc, self).__init__(location)
def commit_command(self, message):
return [self.CMD,"commit","-m",message]
Index: vc/monotone.py
===================================================================
--- vc/monotone.py (revision 1326)
+++ vc/monotone.py (working copy)
@@ -27,29 +27,29 @@
import errno
class Vc(_vc.Vc):
- CMD = "mtn"
NAME = "Monotone"
PATCH_STRIP_NUM = 0
PATCH_INDEX_RE = "^[+]{3,3} ([^ ]*)\t[0-9a-f]{40,40}$"
def __init__(self, location):
self._tree_cache = None
- location = os.path.normpath(location)
-
+ self.interface_version = 0.0
+ self.CMD = None
+ self.choose_monotone_version()
+ super(Vc, self).__init__(os.path.normpath(location))
+
+ def choose_monotone_version(self):
try:
# for monotone >= 0.26
self.VC_DIR = "_MTN"
- self.root = self.find_repo_root(location)
- self.interface_version = float(os.popen("mtn" + " automate interface_version").read())
+ self.CMD = "mtn"
+ self.interface_version = float(os.popen(self.CMD + " automate interface_version").read())
if self.interface_version > 9.0:
print "WARNING: Unsupported interface version (please report any problems to the meld mailing list)"
- return
except ValueError:
- # for monotone <= 0.25 (different metadata directory, different executable)
+ # for monotone <= 0.25
self.VC_DIR = "MT"
self.CMD = "monotone"
- self.root = self.find_repo_root(location)
- return
def commit_command(self, message):
return [self.CMD,"commit","-m",message]
Index: vc/svn.py
===================================================================
--- vc/svn.py (revision 1326)
+++ vc/svn.py (working copy)
@@ -30,6 +30,7 @@
CMD = "svn"
NAME = "Subversion"
VC_DIR = ".svn"
+ VC_ROOT_WALK = False
PATCH_INDEX_RE = "^Index:(.*)$"
state_map = {
"?": _vc.STATE_NONE,
@@ -42,11 +43,6 @@
"C": _vc.STATE_CONFLICT,
}
- def __init__(self, location):
- if not os.path.isdir(os.path.join(location, self.VC_DIR)):
- raise ValueError()
- self.root = location
-
def commit_command(self, message):
return [self.CMD,"commit","-m",message]
def diff_command(self):
Index: vc/_vc.py
===================================================================
--- vc/_vc.py (revision 1326)
+++ vc/_vc.py (working copy)
@@ -71,9 +71,13 @@
PATCH_STRIP_NUM = 0
PATCH_INDEX_RE = ''
VC_DIR = None
+ VC_ROOT_WALK = True
def __init__(self, location):
- self.root = self.find_repo_root(location)
+ if self.VC_ROOT_WALK:
+ self.root = self.find_repo_root(location)
+ else:
+ self.root = self.is_repo_root(location)
def commit_command(self, message):
raise NotImplementedError()
@@ -90,14 +94,19 @@
def patch_command(self, workdir):
return ["patch","--strip=%i"%self.PATCH_STRIP_NUM,"--reverse","--directory=%s" % workdir]
- def find_repo_root(self, start):
+ def is_repo_root(self, location):
+ if not os.path.isdir(os.path.join(location, self.VC_DIR)):
+ raise ValueError
+ return location
+
+ def find_repo_root(self, location):
while True:
- if os.path.isdir(os.path.join(start, self.VC_DIR)):
- return start
- tmp = os.path.dirname(start)
- if tmp == start:
+ if os.path.isdir(os.path.join(location, self.VC_DIR)):
+ return location
+ tmp = os.path.dirname(location)
+ if tmp == location:
break
- start = tmp
+ location = tmp
raise ValueError()
def get_working_directory(self, workdir):
Index: vc/tla.py
===================================================================
--- vc/tla.py (revision 1326)
+++ vc/tla.py (working copy)
@@ -67,7 +67,7 @@
def __init__(self, location):
self._cached_statuses = None
- _vc.Vc.__init__(self, location)
+ super(Vc, self).__init__(location)
def commit_command(self, message):
return [self.CMD, "commit",
Index: vc/git.py
===================================================================
--- vc/git.py (revision 1326)
+++ vc/git.py (working copy)
@@ -42,7 +42,7 @@
def __init__(self, location):
self._tree_cache = None
try:
- _vc.Vc.__init__(self, location)
+ super(Vc, self).__init__(location)
except ValueError:
gitdir = os.environ.get("GIT_DIR")
if gitdir and os.path.isdir(gitdir):
Index: vc/rcs.py
===================================================================
--- vc/rcs.py (revision 1326)
+++ vc/rcs.py (working copy)
@@ -29,14 +29,10 @@
CMD = "rcs"
NAME = "RCS"
VC_DIR = "RCS"
+ VC_ROOT_WALK = False
PATCH_STRIP_NUM = 0
PATCH_INDEX_RE = "^[+]{3} ([^\t]*)\t.*$"
- def __init__(self, location):
- if not os.path.isdir(os.path.join(location, self.VC_DIR)):
- raise ValueError
- self.root = location
-
def commit_command(self, message):
return ["ci", "-l", "-m", message]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]