Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No branch id in filepath #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 25 additions & 55 deletions pycvsanaly2/DBContentHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -418,32 +408,28 @@ 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)

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 = "%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)

dbfilecopy = DBFileCopy (None, file_id)
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,
Expand All @@ -460,18 +446,11 @@ 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)

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 = "%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)

Expand All @@ -481,19 +460,15 @@ def __action_copy (self, path, prefix, 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 = "%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)
Expand All @@ -504,19 +479,15 @@ 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)

# 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 = "%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]

Expand Down Expand Up @@ -548,7 +519,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
Expand Down Expand Up @@ -592,12 +563,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]
Expand All @@ -606,13 +576,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:
Expand Down