From 320b0adac68d8d00cea9f4887a31a28537c77be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlick=20Claes?= Date: Thu, 28 Nov 2013 14:58:03 +0100 Subject: [PATCH 1/2] Branch id removed from filepath in DBContentHandler when adding new file. This should partially fix issue #42. --- pycvsanaly2/DBContentHandler.py | 70 ++++++++++++--------------------- 1 file changed, 26 insertions(+), 44 deletions(-) diff --git a/pycvsanaly2/DBContentHandler.py b/pycvsanaly2/DBContentHandler.py index 4b0066d..6a1f8bc 100644 --- a/pycvsanaly2/DBContentHandler.py +++ b/pycvsanaly2/DBContentHandler.py @@ -170,9 +170,6 @@ def __add_new_file_and_link (self, file_name, parent_id, commit_id, file_path): return dbfile.id - def __remove_branch_from_file_path(self, path): - return path.split("://", 1)[1] - def __add_new_copy (self, dbfilecopy): self.cursor.execute (statement (DBFileCopy.__insert__, self.db.place_holder), (dbfilecopy.id, dbfilecopy.to_id, dbfilecopy.from_id, @@ -326,33 +323,26 @@ def ensure_path (path, commit_id): profiler_start ("Ensuring path %s for repository %d", (path, self.repo_id)) printdbg ("DBContentHandler: ensure_path %s", (path,)) - prefix, lpath = path.split ("://", 1) - prefix += "://" - tokens = lpath.strip ('/').split ('/') + tokens = path.strip ('/').split ('/') parent = -1 node_id = None for i, token in enumerate (tokens): file_path = '/'.join (tokens[:i + 1]) - rpath = prefix + '/' + file_path - if not ":///" in path: - # If the repo paths don't start with / - # remove it here - rpath = rpath.replace (':///', '://') - printdbg ("DBContentHandler: rpath: %s", (rpath,)) + printdbg ("DBContentHandler: file_path: %s", (file_path,)) try: - node_id, parent_id = self.file_cache[rpath] + node_id, parent_id = self.file_cache[file_path] parent = node_id continue except: pass - # Rpath not in cache, add it + # file_path not in cache, add it node_id = self.__add_new_file_and_link (token, parent, commit_id, file_path) parent_id = parent parent = node_id - self.file_cache[rpath] = (node_id, parent_id) + self.file_cache[file_path] = (node_id, parent_id) assert node_id is not None @@ -390,17 +380,17 @@ def ensure_path (path, commit_id): # so it was copied at some point return ensure_path (path, commit_id) - def __action_add (self, path, prefix, log): + def __action_add (self, path, log): """Process a new file added""" parent_path = os.path.dirname (path) file_name = os.path.basename (path) - if not parent_path or parent_path == prefix.strip ('/'): + if not parent_path: parent_id = -1 else: parent_id = self.__get_file_for_path (parent_path, log.id)[0] - file_id = self.__add_new_file_and_link (file_name, parent_id, log.id, self.__remove_branch_from_file_path(path)) + file_id = self.__add_new_file_and_link (file_name, parent_id, log.id, path) self.file_cache[path] = (file_id, parent_id) return file_id @@ -418,7 +408,7 @@ def __action_delete (self, path, log): return file_id - def __action_rename (self, path, prefix, log, action, dbaction): + def __action_rename (self, path, log, action, dbaction): """Process a renamed file""" new_parent_path = os.path.dirname (path) new_file_name = os.path.basename (path) @@ -427,9 +417,7 @@ def __action_rename (self, path, prefix, log, action, dbaction): if action.branch_f2: branch_f2_id = self.__get_branch (action.branch_f2) - old_path = "%d://%s" % (branch_f2_id, action.f2) - else: - old_path = prefix + action.f2 + old_path = action.f2 file_id, parent_id = self.__get_file_for_path (old_path, from_commit_id, True) @@ -437,13 +425,13 @@ def __action_rename (self, path, prefix, log, action, dbaction): dbfilecopy.action_id = dbaction.id dbfilecopy.from_commit = from_commit_id - if not new_parent_path or new_parent_path == prefix.strip ('/'): + if not new_parent_path: new_parent_id = -1 else: new_parent_id = self.__get_file_for_path (new_parent_path, log.id)[0] parent_id = new_parent_id - dblink = DBFileLink (None, parent_id, file_id, self.__remove_branch_from_file_path(path)) + dblink = DBFileLink (None, parent_id, file_id, path) dblink.commit_id = log.id self.cursor.execute (statement (DBFileLink.__insert__, self.db.place_holder), (dblink.id, dblink.parent, dblink.child, @@ -460,7 +448,7 @@ def __action_rename (self, path, prefix, log, action, dbaction): return file_id - def __action_copy (self, path, prefix, log, action, dbaction): + def __action_copy (self, path, log, action, dbaction): """Process a copied file""" new_parent_path = os.path.dirname (path) new_file_name = os.path.basename (path) @@ -469,9 +457,8 @@ def __action_copy (self, path, prefix, log, action, dbaction): if action.branch_f2: branch_f2_id = self.__get_branch (action.branch_f2) - old_path = "%d://%s" % (branch_f2_id, action.f2) - else: - old_path = prefix + action.f2 + + old_path = action.f2 file_id, parent_id = self.__get_file_for_path (old_path, from_commit_id, True) @@ -483,17 +470,15 @@ def __action_copy (self, path, prefix, log, action, dbaction): if action.branch_f2: branch_f2_id = self.__get_branch (action.branch_f2) - old_path = "%d://%s" % (branch_f2_id, action.f2) - else: - old_path = prefix + action.f2 + old_path = action.f2 from_file_id = self.__get_file_for_path (old_path, from_commit_id, True)[0] - if not parent_path or parent_path == prefix.strip ('/'): + if not parent_path: parent_id = -1 else: parent_id = self.__get_file_for_path (parent_path, log.id)[0] - file_id = self.__add_new_file_and_link (file_name, parent_id, log.id, self.__remove_branch_from_file_path(path)) + file_id = self.__add_new_file_and_link (file_name, parent_id, log.id, path) self.file_cache[path] = (file_id, parent_id) dbfilecopy = DBFileCopy (None, file_id) @@ -504,7 +489,7 @@ def __action_copy (self, path, prefix, log, action, dbaction): return file_id - def __action_replace (self, path, prefix, log, action, dbaction): + def __action_replace (self, path, log, action, dbaction): # Replace action: Path has been removed and # a new one has been added with the same path file_name = os.path.basename (path) @@ -514,9 +499,7 @@ def __action_replace (self, path, prefix, log, action, dbaction): if action.f2 is not None: if action.branch_f2: branch_f2_id = self.__get_branch (action.branch_f2) - old_path = "%d://%s" % (branch_f2_id, action.f2) - else: - old_path = prefix + action.f2 + old_path = action.f2 from_commit_id = self.revision_cache.get (action.rev, None) from_file_id = self.__get_file_for_path (old_path, from_commit_id, True)[0] @@ -548,7 +531,7 @@ def __action_replace (self, path, prefix, log, action, dbaction): self.__move_path_to_deletes_cache (cpath) # Add the new path - new_file_id = self.__add_new_file_and_link (file_name, parent_id, log.id, self.__remove_branch_from_file_path(path)) + new_file_id = self.__add_new_file_and_link (file_name, parent_id, log.id, path) self.file_cache[path] = (new_file_id, parent_id) # Register the action in the copies table in order to @@ -592,12 +575,11 @@ def commit (self, commit): branch_id = self.__get_branch (branch) dbaction.branch_id = branch_id - prefix = "%d://" % (branch_id) - path = prefix + action.f1 + path = action.f1 if action.type == 'A': # A file has been added - file_id = self.__action_add (path, prefix, log) + file_id = self.__action_add (path, log) elif action.type == 'M': # A file has been modified file_id = self.__get_file_for_path (path, log.id)[0] @@ -606,13 +588,13 @@ def commit (self, commit): file_id = self.__action_delete (path, log) elif action.type == 'V': # A file has been renamed - file_id = self.__action_rename (path, prefix, log, action, dbaction) + file_id = self.__action_rename (path, log, action, dbaction) elif action.type == 'C': # A file has been copied - file_id = self.__action_copy (path, prefix, log, action, dbaction) + file_id = self.__action_copy (path, log, action, dbaction) elif action.type == 'R': # A file has been replaced - file_id = self.__action_replace (path, prefix, log, action, dbaction) + file_id = self.__action_replace (path, log, action, dbaction) if file_id is None: continue else: From 411772a5cde7f85504305621f412be7e3ae4b4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlick=20Claes?= Date: Mon, 9 Dec 2013 10:02:25 +0100 Subject: [PATCH 2/2] Unused local variables removed --- pycvsanaly2/DBContentHandler.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/pycvsanaly2/DBContentHandler.py b/pycvsanaly2/DBContentHandler.py index 6a1f8bc..62b3749 100644 --- a/pycvsanaly2/DBContentHandler.py +++ b/pycvsanaly2/DBContentHandler.py @@ -415,8 +415,6 @@ def __action_rename (self, path, log, action, dbaction): from_commit_id = self.revision_cache.get (action.rev, None) - if action.branch_f2: - branch_f2_id = self.__get_branch (action.branch_f2) old_path = action.f2 file_id, parent_id = self.__get_file_for_path (old_path, from_commit_id, True) @@ -450,14 +448,8 @@ def __action_rename (self, path, log, action, dbaction): def __action_copy (self, path, log, action, dbaction): """Process a copied file""" - new_parent_path = os.path.dirname (path) - new_file_name = os.path.basename (path) - from_commit_id = self.revision_cache.get (action.rev, None) - if action.branch_f2: - branch_f2_id = self.__get_branch (action.branch_f2) - old_path = action.f2 file_id, parent_id = self.__get_file_for_path (old_path, from_commit_id, True) @@ -468,8 +460,6 @@ def __action_copy (self, path, log, action, dbaction): from_commit_id = self.revision_cache.get (action.rev, None) - if action.branch_f2: - branch_f2_id = self.__get_branch (action.branch_f2) old_path = action.f2 from_file_id = self.__get_file_for_path (old_path, from_commit_id, True)[0] @@ -497,8 +487,6 @@ def __action_replace (self, path, log, action, dbaction): # The replace action is over the old file_id file_id, parent_id = self.__get_file_for_path (path, log.id) if action.f2 is not None: - if action.branch_f2: - branch_f2_id = self.__get_branch (action.branch_f2) old_path = action.f2 from_commit_id = self.revision_cache.get (action.rev, None) from_file_id = self.__get_file_for_path (old_path, from_commit_id, True)[0]