From ed6e3707a45804a282601ab9ec1ac2b5c8ef47c0 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 18 Jan 2010 08:06:08 -0500 Subject: Add .changed() support to VCS --- libbe/storage/vcs/base.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libbe/storage/vcs/base.py') diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index 8390cbc..e837780 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -597,6 +597,14 @@ os.listdir(self.get_path("bugs")): """ return None + def _vcs_changed(self, revision): + """ + Return a tuple of lists of ids + (new, modified, removed) + from the specified revision to the current situation. + """ + return ([], [], []) + def version(self): # Cache version string for efficiency. if not hasattr(self, '_version'): @@ -839,6 +847,13 @@ os.listdir(self.get_path("bugs")): raise libbe.storage.base.InvalidRevision(index) return revid + def changed(self, revision): + new,mod,rem = self._vcs_changed(revision) + new = [self._u_path_to_id(p) for p in new] + mod = [self._u_path_to_id(p) for p in mod] + rem = [self._u_path_to_id(p) for p in rem] + return (new, mod, rem) + def _u_any_in_string(self, list, string): """ Return True if any of the strings in list are in string. -- cgit From ba583f2af95291bf210da819978810dbbb9bfb56 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 18 Jan 2010 09:26:53 -0500 Subject: Ignore paths with _u_path_to_id errors in VCS.changed --- libbe/storage/vcs/base.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'libbe/storage/vcs/base.py') diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index e837780..1719f06 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -363,7 +363,7 @@ class VCS (libbe.storage.base.VersionedStorage): BugDir to search for an installed Storage backend and initialize it in the root directory. This is a convenience option for supporting tests of versioning functionality - (e.g. .duplicate_bugdir). + (e.g. RevisionedBugDir). Disable encoding manipulation ============================= @@ -849,10 +849,17 @@ os.listdir(self.get_path("bugs")): def changed(self, revision): new,mod,rem = self._vcs_changed(revision) - new = [self._u_path_to_id(p) for p in new] - mod = [self._u_path_to_id(p) for p in mod] - rem = [self._u_path_to_id(p) for p in rem] - return (new, mod, rem) + def paths_to_ids(paths): + for p in paths: + try: + id = self._u_path_to_id(p) + yield id + except (SpacerCollision, InvalidPath): + pass + new_id = list(paths_to_ids(new)) + mod_id = list(paths_to_ids(mod)) + rem_id = list(paths_to_ids(rem)) + return (new_id, mod_id, rem_id) def _u_any_in_string(self, list, string): """ -- cgit From 8e0e670cb788d941d3ce109da41d1d4491c85032 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 18 Jan 2010 10:10:30 -0500 Subject: Added VCS._ancestors --- libbe/storage/vcs/base.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libbe/storage/vcs/base.py') diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index 1719f06..692064c 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -745,6 +745,27 @@ os.listdir(self.get_path("bugs")): if p.startswith(path): 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 : self._vcs_path(id, revision) + if id==None: + path = self.be_dir + else: + path = id_to_path(id) + ancestors = [] + while True: + if path == self.repo: + break + path = os.path.dirname(path) + try: + id = self._u_path_to_id(path) + ancestors.append(id) + except (SpacerCollision, InvalidPath): + pass + return ancestors + def _children(self, id=None, revision=None): if revision == None: id_to_path = self._cached_path_id.path -- cgit From c7945daa3e1413b7c789df182b39c12dfbe2b4db Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 18 Jan 2010 10:12:25 -0500 Subject: Adjust VCSTestCase method docstrings for unittest. --- libbe/storage/vcs/base.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'libbe/storage/vcs/base.py') diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index 692064c..716283a 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -1066,8 +1066,7 @@ if libbe.TESTING == True: class VCS_installed_TestCase (VCSTestCase): def test_installed(self): - """ - See if the VCS is installed. + """See if the VCS is installed. """ self.failUnless(self.s.installed() == True, '%(name)s VCS not found' % vars(self.Class)) @@ -1075,8 +1074,7 @@ if libbe.TESTING == True: class VCS_detection_TestCase (VCSTestCase): def test_detection(self): - """ - See if the VCS detects its installed repository + """See if the VCS detects its installed repository """ if self.s.installed(): self.s.disconnect() @@ -1086,8 +1084,7 @@ if libbe.TESTING == True: self.s.connect() def test_no_detection(self): - """ - See if the VCS detects its installed repository + """See if the VCS detects its installed repository """ if self.s.installed() and self.Class.name != 'None': self.s.disconnect() -- cgit From 7ae29f930fe73adada5174a2ce74266411809ac7 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 18 Jan 2010 12:25:17 -0500 Subject: Added VCS._u_find_id_from_manifest for faster id->path calculation --- libbe/storage/vcs/base.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'libbe/storage/vcs/base.py') diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index 716283a..fa64b4e 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -756,7 +756,7 @@ os.listdir(self.get_path("bugs")): path = id_to_path(id) ancestors = [] while True: - if path == self.repo: + if not path.startswith(self.repo + os.path.sep): break path = os.path.dirname(path) try: @@ -926,6 +926,33 @@ os.listdir(self.get_path("bugs")): return None return ret + def _u_find_id_from_manifest(self, id, manifest, revision=None): + """ + Search for the relative path to id using manifest, a list of all files. + + Returns None if the id is not found. + """ + be_dir = self._cached_path_id._spacer_dirs[0] + be_dir_sep = self._cached_path_id._spacer_dirs[0] + os.path.sep + files = [f for f in manifest if f.startswith(be_dir_sep)] + for file in files: + if not file.startswith(be_dir+os.path.sep): + continue + parts = file.split(os.path.sep) + dir = parts.pop(0) # don't add the first spacer dir + for part in parts[:-1]: + dir = os.path.join(dir, part) + if not dir in files: + files.append(dir) + for file in files: + try: + p_id = self._u_path_to_id(file) + if p_id == id: + return file + except (SpacerCollision, InvalidPath): + pass + raise InvalidID(id, revision=revision) + def _u_find_id(self, id, revision): """ Search for the relative path to id as of revision. -- cgit From 7c1df98108a94f14c7bdfa635f489aff7c1f52af Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 18 Jan 2010 12:46:56 -0500 Subject: Fix VCS doctest for +revision InvalidID error message --- libbe/storage/vcs/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libbe/storage/vcs/base.py') diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index fa64b4e..aa2bbaf 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -168,7 +168,7 @@ class CachedPathID (object): >>> c.path('qrs') Traceback (most recent call last): ... - InvalidID: 'qrs' + InvalidID: qrs in revision None >>> c.disconnect() >>> c.destroy() >>> dir.cleanup() -- cgit From d616494d67e5d50f85fccf12c2e679389f7445e1 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 19 Jan 2010 09:02:45 -0500 Subject: Better error messages in VCS._get --- libbe/storage/vcs/base.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libbe/storage/vcs/base.py') diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py index aa2bbaf..15460b0 100644 --- a/libbe/storage/vcs/base.py +++ b/libbe/storage/vcs/base.py @@ -815,12 +815,14 @@ os.listdir(self.get_path("bugs")): try: contents = self._vcs_get_file_contents(relpath, revision) except InvalidID, e: - if InvalidID == None: - e.id = InvalidID + 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) + raise InvalidID(id, revision) elif len(contents) == 0: return None return contents -- cgit