hgext/graphlog.py
changeset 17163 4c5d7124661a
parent 17162 868c256cb51b
child 17164 8299a9ad48dd
equal deleted inserted replaced
17162:868c256cb51b 17163:4c5d7124661a
    64         edges.append((nodeidx, nodeidx + 1))
    64         edges.append((nodeidx, nodeidx + 1))
    65     nmorecols = len(nextseen) - ncols
    65     nmorecols = len(nextseen) - ncols
    66     seen[:] = nextseen
    66     seen[:] = nextseen
    67     yield (type, char, lines, (nodeidx, edges, ncols, nmorecols))
    67     yield (type, char, lines, (nodeidx, edges, ncols, nmorecols))
    68 
    68 
    69 def fix_long_right_edges(edges):
    69 def _fixlongrightedges(edges):
    70     for (i, (start, end)) in enumerate(edges):
    70     for (i, (start, end)) in enumerate(edges):
    71         if end > start:
    71         if end > start:
    72             edges[i] = (start, end + 1)
    72             edges[i] = (start, end + 1)
    73 
    73 
    74 def get_nodeline_edges_tail(
    74 def _getnodelineedgestail(
    75         node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail):
    75         node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail):
    76     if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0:
    76     if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0:
    77         # Still going in the same non-vertical direction.
    77         # Still going in the same non-vertical direction.
    78         if n_columns_diff == -1:
    78         if n_columns_diff == -1:
    79             start = max(node_index + 1, p_node_index)
    79             start = max(node_index + 1, p_node_index)
    83         else:
    83         else:
    84             return ["\\", " "] * (n_columns - node_index - 1)
    84             return ["\\", " "] * (n_columns - node_index - 1)
    85     else:
    85     else:
    86         return ["|", " "] * (n_columns - node_index - 1)
    86         return ["|", " "] * (n_columns - node_index - 1)
    87 
    87 
    88 def draw_edges(edges, nodeline, interline):
    88 def _drawedges(edges, nodeline, interline):
    89     for (start, end) in edges:
    89     for (start, end) in edges:
    90         if start == end + 1:
    90         if start == end + 1:
    91             interline[2 * end + 1] = "/"
    91             interline[2 * end + 1] = "/"
    92         elif start == end - 1:
    92         elif start == end - 1:
    93             interline[2 * start + 1] = "\\"
    93             interline[2 * start + 1] = "\\"
   101                 (start, end) = (end, start)
   101                 (start, end) = (end, start)
   102             for i in range(2 * start + 1, 2 * end):
   102             for i in range(2 * start + 1, 2 * end):
   103                 if nodeline[i] != "+":
   103                 if nodeline[i] != "+":
   104                     nodeline[i] = "-"
   104                     nodeline[i] = "-"
   105 
   105 
   106 def get_padding_line(ni, n_columns, edges):
   106 def _getpaddingline(ni, n_columns, edges):
   107     line = []
   107     line = []
   108     line.extend(["|", " "] * ni)
   108     line.extend(["|", " "] * ni)
   109     if (ni, ni - 1) in edges or (ni, ni) in edges:
   109     if (ni, ni - 1) in edges or (ni, ni) in edges:
   110         # (ni, ni - 1)      (ni, ni)
   110         # (ni, ni - 1)      (ni, ni)
   111         # | | | |           | | | |
   111         # | | | |           | | | |
   152         #
   152         #
   153         #     | | |        | | |
   153         #     | | |        | | |
   154         #     o | |  into  o---+
   154         #     o | |  into  o---+
   155         #     |X /         |/ /
   155         #     |X /         |/ /
   156         #     | |          | |
   156         #     | |          | |
   157         fix_long_right_edges(edges)
   157         _fixlongrightedges(edges)
   158 
   158 
   159     # add_padding_line says whether to rewrite
   159     # add_padding_line says whether to rewrite
   160     #
   160     #
   161     #     | | | |        | | | |
   161     #     | | | |        | | | |
   162     #     | o---+  into  | o---+
   162     #     | o---+  into  | o---+
   178     # nodeline is the line containing the node character (typically o)
   178     # nodeline is the line containing the node character (typically o)
   179     nodeline = ["|", " "] * idx
   179     nodeline = ["|", " "] * idx
   180     nodeline.extend([char, " "])
   180     nodeline.extend([char, " "])
   181 
   181 
   182     nodeline.extend(
   182     nodeline.extend(
   183         get_nodeline_edges_tail(idx, state[1], ncols, coldiff,
   183         _getnodelineedgestail(idx, state[1], ncols, coldiff,
   184                                 state[0], fix_nodeline_tail))
   184                               state[0], fix_nodeline_tail))
   185 
   185 
   186     # shift_interline is the line containing the non-vertical
   186     # shift_interline is the line containing the non-vertical
   187     # edges between this entry and the next
   187     # edges between this entry and the next
   188     shift_interline = ["|", " "] * idx
   188     shift_interline = ["|", " "] * idx
   189     if coldiff == -1:
   189     if coldiff == -1:
   197         edge_ch = "\\"
   197         edge_ch = "\\"
   198     shift_interline.extend(n_spaces * [" "])
   198     shift_interline.extend(n_spaces * [" "])
   199     shift_interline.extend([edge_ch, " "] * (ncols - idx - 1))
   199     shift_interline.extend([edge_ch, " "] * (ncols - idx - 1))
   200 
   200 
   201     # draw edges from the current node to its parents
   201     # draw edges from the current node to its parents
   202     draw_edges(edges, nodeline, shift_interline)
   202     _drawedges(edges, nodeline, shift_interline)
   203 
   203 
   204     # lines is the list of all graph lines to print
   204     # lines is the list of all graph lines to print
   205     lines = [nodeline]
   205     lines = [nodeline]
   206     if add_padding_line:
   206     if add_padding_line:
   207         lines.append(get_padding_line(idx, ncols, edges))
   207         lines.append(_getpaddingline(idx, ncols, edges))
   208     lines.append(shift_interline)
   208     lines.append(shift_interline)
   209 
   209 
   210     # make sure that there are as many graph lines as there are
   210     # make sure that there are as many graph lines as there are
   211     # log strings
   211     # log strings
   212     while len(text) < len(lines):
   212     while len(text) < len(lines):
   224 
   224 
   225     # ... and start over
   225     # ... and start over
   226     state[0] = coldiff
   226     state[0] = coldiff
   227     state[1] = idx
   227     state[1] = idx
   228 
   228 
   229 def check_unsupported_flags(pats, opts):
   229 def _checkunsupportedflags(pats, opts):
   230     for op in ["newest_first"]:
   230     for op in ["newest_first"]:
   231         if op in opts and opts[op]:
   231         if op in opts and opts[op]:
   232             raise util.Abort(_("-G/--graph option is incompatible with --%s")
   232             raise util.Abort(_("-G/--graph option is incompatible with --%s")
   233                              % op.replace("_", "-"))
   233                              % op.replace("_", "-"))
   234 
   234 
   536 
   536 
   537     Nodes printed as an @ character are parents of the working
   537     Nodes printed as an @ character are parents of the working
   538     directory.
   538     directory.
   539     """
   539     """
   540 
   540 
   541     check_unsupported_flags([], opts)
   541     _checkunsupportedflags([], opts)
   542     o = hg._outgoing(ui, repo, dest, opts)
   542     o = hg._outgoing(ui, repo, dest, opts)
   543     if o is None:
   543     if o is None:
   544         return
   544         return
   545 
   545 
   546     revdag = graphrevs(repo, o, opts)
   546     revdag = graphrevs(repo, o, opts)
   558     directory.
   558     directory.
   559     """
   559     """
   560     def subreporecurse():
   560     def subreporecurse():
   561         return 1
   561         return 1
   562 
   562 
   563     check_unsupported_flags([], opts)
   563     _checkunsupportedflags([], opts)
   564     def display(other, chlist, displayer):
   564     def display(other, chlist, displayer):
   565         revdag = graphrevs(other, chlist, opts)
   565         revdag = graphrevs(other, chlist, opts)
   566         showparents = [ctx.node() for ctx in repo[None].parents()]
   566         showparents = [ctx.node() for ctx in repo[None].parents()]
   567         generate(ui, revdag, displayer, showparents, asciiedges)
   567         generate(ui, revdag, displayer, showparents, asciiedges)
   568 
   568