Mercurial > hg
changeset 7326:ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Makes it easier to read all of the code.
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Fri, 07 Nov 2008 11:44:37 +0100 |
parents | f9985108d4e4 |
children | a1758089ee35 |
files | hgext/graphlog.py |
diffstat | 1 files changed, 38 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/graphlog.py Fri Nov 07 10:37:20 2008 +0100 +++ b/hgext/graphlog.py Fri Nov 07 11:44:37 2008 +0100 @@ -15,6 +15,9 @@ from mercurial.util import Abort, canonpath from mercurial import util +def get_rev_parents(repo, rev): + return [x for x in repo.changelog.parentrevs(rev) if x != nullrev] + def revision_grapher(repo, start_rev, stop_rev): """incremental revision grapher @@ -120,14 +123,25 @@ revs = next_revs filerev -= 1 -def get_rev_parents(repo, rev): - return [x for x in repo.changelog.parentrevs(rev) if x != nullrev] - def fix_long_right_edges(edges): for (i, (start, end)) in enumerate(edges): if end > start: edges[i] = (start, end + 1) +def get_nodeline_edges_tail( + node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail): + if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0: + # Still going in the same non-vertical direction. + if n_columns_diff == -1: + start = max(node_index + 1, p_node_index) + tail = ["|", " "] * (start - node_index - 1) + tail.extend(["/", " "] * (n_columns - start)) + return tail + else: + return ["\\", " "] * (n_columns - node_index - 1) + else: + return ["|", " "] * (n_columns - node_index - 1) + def draw_edges(edges, nodeline, interline): for (start, end) in edges: if start == end + 1: @@ -144,24 +158,6 @@ if nodeline[i] != "+": nodeline[i] = "-" -def format_line(line, level, logstr): - text = "%-*s %s" % (2 * level, "".join(line), logstr) - return "%s\n" % text.rstrip() - -def get_nodeline_edges_tail( - node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail): - if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0: - # Still going in the same non-vertical direction. - if n_columns_diff == -1: - start = max(node_index + 1, p_node_index) - tail = ["|", " "] * (start - node_index - 1) - tail.extend(["/", " "] * (n_columns - start)) - return tail - else: - return ["\\", " "] * (n_columns - node_index - 1) - else: - return ["|", " "] * (n_columns - node_index - 1) - def get_padding_line(ni, n_columns, edges): line = [] line.extend(["|", " "] * ni) @@ -179,25 +175,6 @@ line.extend(["|", " "] * (n_columns - ni - 1)) return line -def get_limit(limit_opt): - if limit_opt: - try: - limit = int(limit_opt) - except ValueError: - raise Abort(_("limit must be a positive integer")) - if limit <= 0: - raise Abort(_("limit must be positive")) - else: - limit = sys.maxint - return limit - -def get_revs(repo, rev_opt): - if rev_opt: - revs = revrange(repo, rev_opt) - return (max(revs), min(revs)) - else: - return (len(repo) - 1, 0) - def ascii(ui, grapher): """prints an ASCII graph of the DAG returned by the grapher @@ -293,12 +270,32 @@ # print lines indentation_level = max(n_columns, n_columns + n_columns_diff) for (line, logstr) in zip(lines, node_lines): - ui.write(format_line(line, indentation_level, logstr)) + ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr) + ui.write(ln.rstrip() + '\n') # ... and start over prev_node_index = node_index prev_n_columns_diff = n_columns_diff +def get_limit(limit_opt): + if limit_opt: + try: + limit = int(limit_opt) + except ValueError: + raise Abort(_("limit must be a positive integer")) + if limit <= 0: + raise Abort(_("limit must be positive")) + else: + limit = sys.maxint + return limit + +def get_revs(repo, rev_opt): + if rev_opt: + revs = revrange(repo, rev_opt) + return (max(revs), min(revs)) + else: + return (len(repo) - 1, 0) + def graphlog(ui, repo, path=None, **opts): """show revision history alongside an ASCII revision graph