示例#1
0
 def _get_lines(self, node):
     n = 0
     if node:
         n = node.n
     if n not in self.lines:
         util._undo_to(n)
         self.lines[n] = util.vim().current.buffer[:]
     return self.lines[n]
示例#2
0
文件: node.py 项目: djjcast/vim-mundo
 def _get_lines(self,node):
     n = 0
     if node:
         n = node.n
     if n not in self.lines:
         util._undo_to(n)
         self.lines[n] = util.vim().current.buffer[:]
     return self.lines[n]
示例#3
0
def generate(verbose, num_header_lines, first_visible_line, last_visible_line, inline_graph, nodesData):
    """
    Generate an array of the graph, and text describing the node of the graph.
    """
    seen, state = [], [0, 0]
    result = []
    current = nodesData.current()

    nodes, nmap = nodesData.make_nodes()

    max_saved_num = 0
    current_save = 0
    for node in nodes:
        node.children = [n for n in nodes if n.parent == node]
        if node.saved > max_saved_num:
            max_saved_num = node.saved
            current_save = node.n

    def walk_nodes(nodes):
        for node in nodes:
            if node.parent:
                yield (node, [node.parent])
            else:
                yield (node, [])

    dag = sorted(nodes, key=lambda n: int(n.n), reverse=True)
    dag = walk_nodes(dag)

    line_number = num_header_lines
    for idx, part in list(enumerate(dag)):
        node, parents = part
        if node.time:
            age_label = age(int(node.time))
        else:
            age_label = 'Original'
        line = '[%s] %s' % (node.n, age_label)
        if node.n == current:
            if node.saved:
                char = '$'
            else:
                char = '@'
        elif node.saved:
            if node.n == current_save:
                char = 'S'
            else:
                char = 's'
        else:
            char = 'o'
        show_inine_diff = inline_graph and line_number >= first_visible_line and line_number <= last_visible_line
        preview_diff = nodesData.preview_diff(node.parent, node, False, show_inine_diff)
        line = '[%s] %-10s %s' % (node.n, age_label, preview_diff)
        new_lines = ascii(state, 'C', char, [line], asciiedges(seen, node, parents), verbose)
        line_number += len(new_lines)
        result.extend(new_lines)
    util._undo_to(current)
    return result
示例#4
0
def generate(verbose, num_header_lines, first_visible_line, last_visible_line,
             inline_graph, nodesData):
    """
    Generate an array of the graph, and text describing the node of the graph.
    """
    seen, state = [], [0, 0]
    result = []
    current = nodesData.current()

    nodes, nmap = nodesData.make_nodes()

    for node in nodes:
        node.children = [n for n in nodes if n.parent == node]

    def walk_nodes(nodes):
        for node in nodes:
            if node.parent:
                yield (node, [node.parent])
            else:
                yield (node, [])

    dag = sorted(nodes, key=lambda n: int(n.n), reverse=True)
    dag = walk_nodes(dag)

    line_number = num_header_lines
    for idx, part in list(enumerate(dag)):
        node, parents = part
        if node.time:
            age_label = age(int(node.time))
        else:
            age_label = 'Original'
        line = '[%s] %s' % (node.n, age_label)
        if node.n == current:
            char = '@'
        elif node.saved:
            char = 'w'
        else:
            char = 'o'
        show_inine_diff = inline_graph and line_number >= first_visible_line and line_number <= last_visible_line
        preview_diff = nodesData.preview_diff(node.parent, node, False,
                                              show_inine_diff)
        line = '[%s] %-10s %s' % (node.n, age_label, preview_diff)
        new_lines = ascii(state, 'C', char, [line],
                          asciiedges(seen, node, parents), verbose)
        line_number += len(new_lines)
        result.extend(new_lines)
    util._undo_to(current)
    return result
示例#5
0
    def change_preview_diff(self, before, after):
        self._check_version_location()
        key = "%s-%s-cpd" % (before.n, after.n)
        if key in self.diffs:
            return self.diffs[key]

        util._goto_window_for_buffer(util.vim().eval('g:mundo_target_n'))
        before_lines = self._get_lines(before)
        after_lines = self._get_lines(after)

        before_name = str(before.n or 'Original')
        before_time = before.time and self._fmt_time(before.time) or ''
        after_name = str(after.n or 'Original')
        after_time = after.time and self._fmt_time(after.time) or ''

        util._undo_to(self.current())

        self.diffs[key] = list(
            difflib.unified_diff(before_lines, after_lines, before_name,
                                 after_name, before_time, after_time))
        return self.diffs[key]
示例#6
0
文件: node.py 项目: djjcast/vim-mundo
    def change_preview_diff(self,before,after):
        self._check_version_location()
        key = "%s-%s-cpd"%(before.n,after.n)
        if key in self.diffs:
            return self.diffs[key]

        util._goto_window_for_buffer(util.vim().eval('g:mundo_target_n'))
        before_lines = self._get_lines(before)
        after_lines = self._get_lines(after)

        before_name = str(before.n or 'Original')
        before_time = before.time and self._fmt_time(before.time) or ''
        after_name = str(after.n or 'Original')
        after_time = after.time and self._fmt_time(after.time) or ''

        util._undo_to(self.current())

        self.diffs[key] = list(difflib.unified_diff(before_lines, after_lines,
                                         before_name, after_name,
                                         before_time, after_time))
        return self.diffs[key]