aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/storage/vcs
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2010-01-23 11:16:42 -0500
committerW. Trevor King <wking@drexel.edu>2010-01-23 11:16:42 -0500
commit4ea7a28e1bd97df5997b5f884378bd7d64edff6e (patch)
tree8be1029b10240e9280581359e32aee4acf30ae75 /libbe/storage/vcs
parente0ce49ffa3d09d37310ce04c50268275b8e2ca54 (diff)
parent2f7045deeb0225fed1692b3390502077e4907758 (diff)
downloadbugseverywhere-4ea7a28e1bd97df5997b5f884378bd7d64edff6e.tar.gz
Fixed some bugs in settings_object handling and got test_usage.sh working.
Highlights: * clarified settings_object handling and improved unittests * added `be list --mine` * fixed some bugs in List, Import_XML, Init * added Storage.exists() (haven't implemented it in all VCS backends though). * added VCS.path()
Diffstat (limited to 'libbe/storage/vcs')
-rw-r--r--libbe/storage/vcs/base.py62
-rw-r--r--libbe/storage/vcs/bzr.py9
2 files changed, 45 insertions, 26 deletions
diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py
index 9fc43c1..7d4383f 100644
--- a/libbe/storage/vcs/base.py
+++ b/libbe/storage/vcs/base.py
@@ -504,6 +504,12 @@ os.listdir(self.get_path("bugs")):
"""
pass
+ def _vcs_exists(self, path, revision=None):
+ """
+ Does the path exist in a given revision? (True/False)
+ """
+ raise NotImplementedError
+
def _vcs_remove(self, path):
"""
Remove the file at path from version control. Optionally
@@ -550,7 +556,7 @@ os.listdir(self.get_path("bugs")):
def _vcs_path(self, id, revision):
"""
- Return the path to object id as of revision.
+ Return the relative path to object id as of revision.
Revision will not be None.
"""
@@ -694,6 +700,17 @@ os.listdir(self.get_path("bugs")):
def _disconnect(self):
self._cached_path_id.disconnect()
+ def path(self, id, revision=None, relpath=True):
+ if revision == None:
+ path = self._cached_path_id.path(id)
+ if relpath == True:
+ return self._u_rel_path(path)
+ return path
+ path = self._vcs_path(id, revision)
+ if relpath == True:
+ return path
+ return os.path.join(self.repo, path)
+
def _add_path(self, path, directory=False):
relpath = self._u_rel_path(path)
reldirs = relpath.split(os.path.sep)
@@ -716,6 +733,16 @@ os.listdir(self.get_path("bugs")):
path = self._cached_path_id.add_id(id, parent)
self._add_path(path, **kwargs)
+ def _exists(self, id, revision=None):
+ if revision == None:
+ try:
+ path = self.path(id, revision, relpath=False)
+ except InvalidID, e:
+ return False
+ return os.path.exists(path)
+ path = self.path(id, revision, relpath=True)
+ return self._vcs_exists(relpath, revision)
+
def _remove(self, id):
path = self._cached_path_id.path(id)
if os.path.exists(path):
@@ -746,15 +773,10 @@ os.listdir(self.get_path("bugs")):
self._cached_path_id.remove_id(id)
def _ancestors(self, id=None, revision=None):
- if revision == None:
- id_to_path = self._cached_path_id.path
- else:
- id_to_path = lambda id : os.path.join(
- self.repo, self._vcs_path(id, revision))
if id==None:
path = self.be_dir
else:
- path = id_to_path(id)
+ path = self.path(id, revision, relpath=False)
ancestors = []
while True:
if not path.startswith(self.repo + os.path.sep):
@@ -769,12 +791,9 @@ os.listdir(self.get_path("bugs")):
def _children(self, id=None, revision=None):
if revision == None:
- id_to_path = self._cached_path_id.path
isdir = os.path.isdir
listdir = os.listdir
else:
- id_to_path = lambda id : os.path.join(
- self.repo, self._vcs_path(id, revision))
isdir = lambda path : self._vcs_isdir(
self._u_rel_path(path), revision)
listdir = lambda path : self._vcs_listdir(
@@ -782,7 +801,7 @@ os.listdir(self.get_path("bugs")):
if id==None:
path = self.be_dir
else:
- path = id_to_path(id)
+ path = self.path(id, revision, relpath=False)
if isdir(path) == False:
return []
children = listdir(path)
@@ -810,25 +829,18 @@ os.listdir(self.get_path("bugs")):
def _get(self, id, default=libbe.util.InvalidObject, revision=None):
try:
- path = self._cached_path_id.path(id)
+ relpath = self.path(id, revision, relpath=True)
+ contents = self._vcs_get_file_contents(relpath, revision)
except InvalidID, e:
if default == libbe.util.InvalidObject:
raise e
return default
- relpath = self._u_rel_path(path)
- try:
- contents = self._vcs_get_file_contents(relpath, revision)
- except InvalidID, e:
- if e.id == None:
- e.id = id
- if e.revision == None:
- e.revision = revision
- raise
if contents in [libbe.storage.base.InvalidDirectory,
- libbe.util.InvalidObject]:
- raise InvalidID(id, revision)
- elif len(contents) == 0:
- return None
+ libbe.util.InvalidObject] \
+ or len(contents) == 0:
+ if default == libbe.util.InvalidObject:
+ raise InvalidID(id, revision)
+ return default
return contents
def _set(self, id, value):
diff --git a/libbe/storage/vcs/bzr.py b/libbe/storage/vcs/bzr.py
index e1cd2e5..1db50f8 100644
--- a/libbe/storage/vcs/bzr.py
+++ b/libbe/storage/vcs/bzr.py
@@ -98,6 +98,13 @@ class Bzr(base.VCS):
cmd.outf = StringIO.StringIO()
cmd.run(file_list=[path], file_ids_from=self.repo)
+ def _vcs_exists(self, path, revision=None):
+ manifest = self._vcs_listdir(
+ self.repo, revision=revision, recursive=True)
+ if path in manifest:
+ return True
+ return False
+
def _vcs_remove(self, path):
# --force to also remove unversioned files.
path = os.path.join(self.repo, path)
@@ -131,7 +138,7 @@ class Bzr(base.VCS):
if 'not present in revision' in str(e):
raise base.InvalidPath(path, root=self.repo, revision=revision)
raise
- return cmd.outf.getvalue()
+ return cmd.outf.getvalue()
def _vcs_path(self, id, revision):
manifest = self._vcs_listdir(