Example #1
0
    def __action_replace(self, path, prefix, 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
            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]

            # The file is replaced from itself, we can just
            # ignore this action.
            #
            # Fixes problems when building paths in situations like this one:
            #
            #r76 | mhr3 | 2006-10-18 18:07:11 +0200 (Wed, 18 Oct 2006) | 1 line
            #Changed paths:
            #   A /scripts/sframework (from /sframework:74)
            #   R /scripts/sframework/branches (from /sframework/branches:75)
            #   R /scripts/sframework/tags (from /sframework/tags:75)
            #   R /scripts/sframework/trunk (from /sframework/trunk:75)
            #   D /sframework
            if from_file_id == file_id:
                # Returning None to tell the program back to not process
                # it.
                return None
        else:
            from_commit_id = None
            from_file_id = file_id

        self.__move_path_to_deletes_cache(path)
        # Remove the old references
        dirpath = path.rstrip("/") + "/"
        for cpath in self.file_cache.keys():
            if cpath.startswith(dirpath):
                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))
        self.file_cache[path] = (new_file_id, parent_id)

        # Register the action in the copies table in order to
        # be able to know which file replaced this file
        dbfilecopy = DBFileCopy(None, new_file_id)
        dbfilecopy.from_id = from_file_id
        dbfilecopy.action_id = dbaction.id
        dbfilecopy.from_commit = from_commit_id
        self.__add_new_copy(dbfilecopy)

        return file_id
    def __action_replace(self, path, prefix, 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
            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]

            # The file is replaced from itself, we can just
            # ignore this action.
            #
            # Fixes problems when building paths in situations like this one:
            #
            # r76 | mhr3 | 2006-10-18 18:07:11 +0200 (Wed, 18 Oct 2006) | 1 line
            # Changed paths:
            #   A /scripts/sframework (from /sframework:74)
            #   R /scripts/sframework/branches (from /sframework/branches:75)
            #   R /scripts/sframework/tags (from /sframework/tags:75)
            #   R /scripts/sframework/trunk (from /sframework/trunk:75)
            #   D /sframework
            if from_file_id == file_id:
                # Returning None to tell the program back to not process
                # it.
                return None
        else:
            from_commit_id = None
            from_file_id = file_id

        self.__move_path_to_deletes_cache(path)
        # Remove the old references
        dirpath = path.rstrip("/") + "/"
        for cpath in self.file_cache.keys():
            if cpath.startswith(dirpath):
                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)
        )
        self.file_cache[path] = (new_file_id, parent_id)

        # Register the action in the copies table in order to
        # be able to know which file replaced this file
        dbfilecopy = DBFileCopy(None, new_file_id)
        dbfilecopy.from_id = from_file_id
        dbfilecopy.action_id = dbaction.id
        dbfilecopy.from_commit = from_commit_id
        self.__add_new_copy(dbfilecopy)

        return file_id
Example #3
0
    def __action_copy(self, path, prefix, 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

        file_id, parent_id = self.__get_file_for_path(old_path,
                                            from_commit_id, True)

        parent_path = os.path.dirname(path)
        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
        from_file_id = self.__get_file_for_path(old_path, from_commit_id,
                                                True)[0]

        if not parent_path or parent_path == prefix.strip('/'):
            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.file_cache[path] = (file_id, parent_id)

        dbfilecopy = DBFileCopy(None, file_id)
        dbfilecopy.from_id = from_file_id
        dbfilecopy.action_id = dbaction.id
        dbfilecopy.from_commit = from_commit_id
        self.__add_new_copy(dbfilecopy)

        # Save also file_path
        self.__add_file_path(log.id, file_id, path)

        return file_id
Example #4
0
    def __action_rename(self, path, prefix, 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
        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('/'):
            new_parent_id = -1
        else:
            new_parent_id = self.__get_file_for_path(new_parent_path,
                                                     log.id)[0]
        if new_parent_id != parent_id:
            # It's not a simple rename, but a move operation
            # we have to write down the new link
            parent_id = new_parent_id
            dblink = DBFileLink(None, parent_id, file_id)
            dblink.commit_id = log.id
            self.cursor.execute(statement(DBFileLink.__insert__,
                                 self.db.place_holder),
                                (dblink.id, dblink.parent, dblink.child,
                                 dblink.commit_id))
            self.moves_cache[path] = old_path

        self.file_cache[path] = (file_id, parent_id)

        # Move/rename is a special case of copy.  # There's not a
        # new file_id
        dbfilecopy.from_id = file_id
        dbfilecopy.new_file_name = new_file_name
        self.__add_new_copy(dbfilecopy)

        # Save also file_path
        self.__add_file_path(log.id, file_id, path)

        return file_id