示例#1
0
    def __init__(self, path, kind):
        self._validate_path(path)  # can throw exception if path is invalid
        self.path = safe_str(path.rstrip('/'))  # we store paths as str
        if path == '' and kind != NodeKind.DIR:
            raise NodeError("Only DirNode and its subclasses may be "
                            "initialized with empty path")
        self.kind = kind

        if self.is_root() and not self.is_dir():
            raise NodeError("Root node cannot be FILE kind")
示例#2
0
 def annotate(self):
     """
     Returns a list of three element tuples with lineno, commit and line
     """
     if self.commit is None:
         raise NodeError('Unable to get commit for this FileNode')
     pre_load = ["author", "date", "message"]
     return self.commit.get_file_annotate(self.path, pre_load=pre_load)
示例#3
0
    def __init__(self, path, nodes=(), commit=None):
        """
        Only one of ``nodes`` and ``commit`` may be given. Passing both
        would raise ``NodeError`` exception.

        :param path: relative path to the node
        :param nodes: content may be passed to constructor
        :param commit: if given, will use it to lazily fetch content
        """
        if nodes and commit:
            raise NodeError("Cannot use both nodes and commit")
        super(DirNode, self).__init__(path, NodeKind.DIR)
        self.commit = commit
        self._nodes = nodes
示例#4
0
    def __init__(self, path, content=None, commit=None, mode=None):
        """
        Only one of ``content`` and ``commit`` may be given. Passing both
        would raise ``NodeError`` exception.

        :param path: relative path to the node
        :param content: content may be passed to constructor
        :param commit: if given, will use it to lazily fetch content
        :param mode: ST_MODE (i.e. 0100644)
        """
        if content and commit:
            raise NodeError("Cannot use both content and commit")
        super(FileNode, self).__init__(path, kind=NodeKind.FILE)
        self.commit = commit
        self._content = content
        self._mode = mode or FILEMODE_DEFAULT
示例#5
0
 def _get_file_node(self, commit_id, f_path):
     if commit_id not in ['', None, 'None', '0' * 12, '0' * 40]:
         commit = c.rhodecode_repo.get_commit(commit_id=commit_id)
         try:
             node = commit.get_node(f_path)
             if node.is_dir():
                 raise NodeError('%s path is a %s not a file' %
                                 (node, type(node)))
         except NodeDoesNotExistError:
             commit = EmptyCommit(commit_id=commit_id,
                                  idx=commit.idx,
                                  repo=commit.repository,
                                  alias=commit.repository.alias,
                                  message=commit.message,
                                  author=commit.author,
                                  date=commit.date)
             node = FileNode(f_path, '', commit=commit)
     else:
         commit = EmptyCommit(repo=c.rhodecode_repo,
                              alias=c.rhodecode_repo.alias)
         node = FileNode(f_path, '', commit=commit)
     return node
示例#6
0
 def last_commit(self):
     if self.commit:
         pre_load = ["author", "date", "message"]
         return self.commit.get_file_commit(self.path, pre_load=pre_load)
     raise NodeError("Cannot retrieve last commit of the file without "
                     "related commit attribute")
示例#7
0
 def _validate_path(self, path):
     if path.startswith('/'):
         raise NodeError(
             "Cannot initialize Node objects with slash at "
             "the beginning as only relative paths are supported. "
             "Got %s" % (path, ))
示例#8
0
    def diff_2way(self, repo_name, f_path):
        diff1 = request.GET.get('diff1', '')
        diff2 = request.GET.get('diff2', '')
        try:
            if diff1 not in ['', None, 'None', '0' * 12, '0' * 40]:
                c.changeset_1 = c.rhodecode_repo.get_changeset(diff1)
                try:
                    node1 = c.changeset_1.get_node(f_path)
                    if node1.is_dir():
                        raise NodeError('%s path is a %s not a file' %
                                        (node1, type(node1)))
                except NodeDoesNotExistError:
                    c.changeset_1 = EmptyChangeset(
                        cs=diff1,
                        revision=c.changeset_1.revision,
                        repo=c.rhodecode_repo)
                    node1 = FileNode(f_path, '', changeset=c.changeset_1)
            else:
                c.changeset_1 = EmptyChangeset(repo=c.rhodecode_repo)
                node1 = FileNode(f_path, '', changeset=c.changeset_1)

            if diff2 not in ['', None, 'None', '0' * 12, '0' * 40]:
                c.changeset_2 = c.rhodecode_repo.get_changeset(diff2)
                try:
                    node2 = c.changeset_2.get_node(f_path)
                    if node2.is_dir():
                        raise NodeError('%s path is a %s not a file' %
                                        (node2, type(node2)))
                except NodeDoesNotExistError:
                    c.changeset_2 = EmptyChangeset(
                        cs=diff2,
                        revision=c.changeset_2.revision,
                        repo=c.rhodecode_repo)
                    node2 = FileNode(f_path, '', changeset=c.changeset_2)
            else:
                c.changeset_2 = EmptyChangeset(repo=c.rhodecode_repo)
                node2 = FileNode(f_path, '', changeset=c.changeset_2)
        except (RepositoryError, NodeError):
            log.error(traceback.format_exc())
            return redirect(
                url('files_home', repo_name=c.repo_name, f_path=f_path))
        if node2.is_binary:
            node2_content = 'binary file'
        else:
            node2_content = node2.content

        if node1.is_binary:
            node1_content = 'binary file'
        else:
            node1_content = node1.content

        html_escape_table = {
            "&": "\u0026",
            '"': "\u0022",
            "'": "\u0027",
            ">": "\u003e",
            "<": "\u003c",
            '\\': "\u005c",
            '\n': '\\n'
        }

        c.orig1 = h.html_escape((node1_content), html_escape_table)
        c.orig2 = h.html_escape((node2_content), html_escape_table)
        c.node1 = node1
        c.node2 = node2
        c.cs1 = c.changeset_1
        c.cs2 = c.changeset_2

        return render('files/diff_2way.html')