hgext/graphlog.py
author Dirkjan Ochtman <dirkjan@ochtman.nl>
Sat, 15 Nov 2008 12:27:40 +0100
changeset 7379 ef22cb8896d6
parent 7374 ccec5ae82282
child 7383 b501c7f3c2ad
permissions -rw-r--r--
graphlog: fix python2.3 incompatibility (used genexp, sorted())
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
     1
# ASCII graph log extension for Mercurial
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
     2
#
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
     3
# Copyright 2007 Joel Rosdahl <joel@rosdahl.net>
4516
96d8a56d4ef9 Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4509
diff changeset
     4
#
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
     6
# the GNU General Public License, incorporated herein by reference.
6666
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6212
diff changeset
     7
'''show revision graphs in terminal windows'''
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
     8
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
     9
import os
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    10
import sys
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    11
from mercurial.cmdutil import revrange, show_changeset
6192
cd65a67aff31 Introduce templateopts and logopts to reduce duplicate option definitions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5968
diff changeset
    12
from mercurial.commands import templateopts
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    13
from mercurial.i18n import _
6212
e75aab656f46 Remove unused imports
Joel Rosdahl <joel@rosdahl.net>
parents: 6192
diff changeset
    14
from mercurial.node import nullrev
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    15
from mercurial.util import Abort, canonpath
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    16
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    17
def revisions(repo, start, stop):
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    18
    """cset DAG generator yielding (rev, node, [parents]) tuples
7374
ccec5ae82282 graphlog: kill whitespace from earlier refactoring
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7371
diff changeset
    19
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    20
    This generator function walks through the revision history from revision
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    21
    start to revision stop (which must be less than or equal to start).
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    22
    """
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    23
    assert start >= stop
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    24
    cur = start
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    25
    while cur >= stop:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    26
        ctx = repo[cur]
7379
ef22cb8896d6 graphlog: fix python2.3 incompatibility (used genexp, sorted())
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7374
diff changeset
    27
        parents = [p.rev() for p in ctx.parents() if p.rev() != nullrev]
ef22cb8896d6 graphlog: fix python2.3 incompatibility (used genexp, sorted())
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7374
diff changeset
    28
        parents.sort()
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    29
        yield (ctx, parents)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    30
        cur -= 1
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    31
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    32
def filerevs(repo, path, start, stop):
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    33
    """file cset DAG generator yielding (rev, node, [parents]) tuples
7374
ccec5ae82282 graphlog: kill whitespace from earlier refactoring
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7371
diff changeset
    34
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    35
    This generator function walks through the revision history of a single
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    36
    file from revision start to revision stop (which must be less than or
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    37
    equal to start).
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    38
    """
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    39
    assert start >= stop
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6666
diff changeset
    40
    filerev = len(repo.file(path)) - 1
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    41
    while filerev >= 0:
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    42
        fctx = repo.filectx(path, fileid=filerev)
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    43
        parents = [f.filerev() for f in fctx.parents() if f.path() == path]
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    44
        parents.sort()
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    45
        if fctx.rev() <= start:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    46
            yield (fctx, parents)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    47
        if fctx.rev() <= stop:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    48
            break
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    49
        filerev -= 1
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    50
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    51
def grapher(nodes):
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    52
    """grapher for asciigraph on a list of nodes and their parents
7374
ccec5ae82282 graphlog: kill whitespace from earlier refactoring
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7371
diff changeset
    53
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    54
    nodes must generate tuples (node, parents, char, lines) where
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    55
     - parents must generate the parents of node, in sorted order,
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    56
       and max length 2,
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    57
     - char is the char to print as the node symbol, and
7374
ccec5ae82282 graphlog: kill whitespace from earlier refactoring
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7371
diff changeset
    58
     - lines are the lines to display next to the node.
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    59
    """
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    60
    seen = []
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    61
    for node, parents, char, lines in nodes:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    62
        if node not in seen:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    63
            seen.append(node)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    64
        nodeidx = seen.index(node)
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    65
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    66
        knownparents = []
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    67
        newparents = []
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    68
        for parent in parents:
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    69
            if parent in seen:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    70
                knownparents.append(parent)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    71
            else:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    72
                newparents.append(parent)
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    73
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    74
        ncols = len(seen)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    75
        nextseen = seen[:]
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    76
        nextseen[nodeidx:nodeidx + 1] = newparents
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    77
        edges = [(nodeidx, nextseen.index(p)) for p in knownparents]
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    78
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    79
        if len(newparents) > 0:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    80
            edges.append((nodeidx, nodeidx))
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    81
        if len(newparents) > 1:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    82
            edges.append((nodeidx, nodeidx + 1))
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    83
        nmorecols = len(nextseen) - ncols
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    84
        seen = nextseen
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    85
        yield (char, lines, nodeidx, edges, ncols, nmorecols)
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    86
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    87
def fix_long_right_edges(edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    88
    for (i, (start, end)) in enumerate(edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    89
        if end > start:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    90
            edges[i] = (start, end + 1)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    91
7326
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    92
def get_nodeline_edges_tail(
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    93
        node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail):
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    94
    if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    95
        # Still going in the same non-vertical direction.
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    96
        if n_columns_diff == -1:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    97
            start = max(node_index + 1, p_node_index)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    98
            tail = ["|", " "] * (start - node_index - 1)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    99
            tail.extend(["/", " "] * (n_columns - start))
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   100
            return tail
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   101
        else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   102
            return ["\\", " "] * (n_columns - node_index - 1)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   103
    else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   104
        return ["|", " "] * (n_columns - node_index - 1)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   105
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   106
def draw_edges(edges, nodeline, interline):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   107
    for (start, end) in edges:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   108
        if start == end + 1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   109
            interline[2 * end + 1] = "/"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   110
        elif start == end - 1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   111
            interline[2 * start + 1] = "\\"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   112
        elif start == end:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   113
            interline[2 * start] = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   114
        else:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   115
            nodeline[2 * end] = "+"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   116
            if start > end:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   117
                (start, end) = (end,start)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   118
            for i in range(2 * start + 1, 2 * end):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   119
                if nodeline[i] != "+":
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   120
                    nodeline[i] = "-"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   121
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   122
def get_padding_line(ni, n_columns, edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   123
    line = []
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   124
    line.extend(["|", " "] * ni)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   125
    if (ni, ni - 1) in edges or (ni, ni) in edges:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   126
        # (ni, ni - 1)      (ni, ni)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   127
        # | | | |           | | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   128
        # +---o |           | o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   129
        # | | c |           | c | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   130
        # | |/ /            | |/ /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   131
        # | | |             | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   132
        c = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   133
    else:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   134
        c = " "
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   135
    line.extend([c, " "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   136
    line.extend(["|", " "] * (n_columns - ni - 1))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   137
    return line
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   138
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   139
def ascii(ui, grapher):
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   140
    """prints an ASCII graph of the DAG returned by the grapher
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   141
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   142
    grapher is a generator that emits tuples with the following elements:
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   143
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   144
      - Character to use as node's symbol.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   145
      - List of lines to display as the node's text.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   146
      - Column of the current node in the set of ongoing edges.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   147
      - Edges; a list of (col, next_col) indicating the edges between
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   148
        the current node and its parents.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   149
      - Number of columns (ongoing edges) in the current revision.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   150
      - The difference between the number of columns (ongoing edges)
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   151
        in the next revision and the number of columns (ongoing edges)
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   152
        in the current revision. That is: -1 means one column removed;
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   153
        0 means no columns added or removed; 1 means one column added.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   154
    """
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   155
    prev_n_columns_diff = 0
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   156
    prev_node_index = 0
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   157
    for (node_ch, node_lines, node_index, edges, n_columns, n_columns_diff) in grapher:
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   158
7356
eee5b7b9c5d2 graphlog: add assertion for allowed n_column_diff range
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7355
diff changeset
   159
        assert -2 < n_columns_diff < 2
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   160
        if n_columns_diff == -1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   161
            # Transform
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   162
            #
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   163
            #     | | |        | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   164
            #     o | |  into  o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   165
            #     |X /         |/ /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   166
            #     | |          | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   167
            fix_long_right_edges(edges)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   168
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   169
        # add_padding_line says whether to rewrite
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   170
        #
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   171
        #     | | | |        | | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   172
        #     | o---+  into  | o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   173
        #     |  / /         |   | |  # <--- padding line
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   174
        #     o | |          |  / /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   175
        #                    o | |
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   176
        add_padding_line = (len(node_lines) > 2 and
4633
ff7253a0d1da Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4583
diff changeset
   177
                            n_columns_diff == -1 and
ff7253a0d1da Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4583
diff changeset
   178
                            [x for (x, y) in edges if x + 1 < y])
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   179
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   180
        # fix_nodeline_tail says whether to rewrite
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   181
        #
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   182
        #     | | o | |        | | o | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   183
        #     | | |/ /         | | |/ /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   184
        #     | o | |    into  | o / /   # <--- fixed nodeline tail
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   185
        #     | |/ /           | |/ /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   186
        #     o | |            o | |
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   187
        fix_nodeline_tail = len(node_lines) <= 2 and not add_padding_line
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   188
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   189
        # nodeline is the line containing the node character (typically o)
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   190
        nodeline = ["|", " "] * node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   191
        nodeline.extend([node_ch, " "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   192
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   193
        nodeline.extend(
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   194
            get_nodeline_edges_tail(
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   195
                node_index, prev_node_index, n_columns, n_columns_diff,
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   196
                prev_n_columns_diff, fix_nodeline_tail))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   197
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   198
        # shift_interline is the line containing the non-vertical
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   199
        # edges between this entry and the next
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   200
        shift_interline = ["|", " "] * node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   201
        if n_columns_diff == -1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   202
            n_spaces = 1
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   203
            edge_ch = "/"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   204
        elif n_columns_diff == 0:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   205
            n_spaces = 2
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   206
            edge_ch = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   207
        else:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   208
            n_spaces = 3
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   209
            edge_ch = "\\"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   210
        shift_interline.extend(n_spaces * [" "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   211
        shift_interline.extend([edge_ch, " "] * (n_columns - node_index - 1))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   212
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   213
        # draw edges from the current node to its parents
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   214
        draw_edges(edges, nodeline, shift_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   215
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   216
        # lines is the list of all graph lines to print
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   217
        lines = [nodeline]
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   218
        if add_padding_line:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   219
            lines.append(get_padding_line(node_index, n_columns, edges))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   220
        lines.append(shift_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   221
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   222
        # make sure that there are as many graph lines as there are
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   223
        # log strings
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   224
        while len(node_lines) < len(lines):
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   225
            node_lines.append("")
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   226
        if len(lines) < len(node_lines):
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   227
            extra_interline = ["|", " "] * (n_columns + n_columns_diff)
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   228
            while len(lines) < len(node_lines):
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   229
                lines.append(extra_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   230
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   231
        # print lines
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   232
        indentation_level = max(n_columns, n_columns + n_columns_diff)
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   233
        for (line, logstr) in zip(lines, node_lines):
7326
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   234
            ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   235
            ui.write(ln.rstrip() + '\n')
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   236
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   237
        # ... and start over
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   238
        prev_node_index = node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   239
        prev_n_columns_diff = n_columns_diff
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   240
7326
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   241
def get_limit(limit_opt):
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   242
    if limit_opt:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   243
        try:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   244
            limit = int(limit_opt)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   245
        except ValueError:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   246
            raise Abort(_("limit must be a positive integer"))
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   247
        if limit <= 0:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   248
            raise Abort(_("limit must be positive"))
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   249
    else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   250
        limit = sys.maxint
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   251
    return limit
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   252
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   253
def get_revs(repo, rev_opt):
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   254
    if rev_opt:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   255
        revs = revrange(repo, rev_opt)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   256
        return (max(revs), min(revs))
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   257
    else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   258
        return (len(repo) - 1, 0)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   259
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   260
def graphlog(ui, repo, path=None, **opts):
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   261
    """show revision history alongside an ASCII revision graph
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   262
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   263
    Print a revision history alongside a revision graph drawn with
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   264
    ASCII characters.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   265
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   266
    Nodes printed as an @ character are parents of the working
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   267
    directory.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   268
    """
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   269
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   270
    limit = get_limit(opts["limit"])
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   271
    start, stop = get_revs(repo, opts["rev"])
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   272
    stop = max(stop, start - limit + 1)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   273
    if start == nullrev:
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   274
        return
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   275
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   276
    if path:
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   277
        path = canonpath(repo.root, os.getcwd(), path)
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   278
    if path: # could be reset in canonpath
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   279
        revdag = filerevs(repo, path, start, stop)
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   280
    else:
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   281
        revdag = revisions(repo, start, stop)
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   282
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   283
    repo_parents = repo.dirstate.parents()
7371
6ad2b914acbd graphlog: use built-in log output buffering
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7370
diff changeset
   284
    displayer = show_changeset(ui, repo, opts, buffered=True)
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   285
    def graphabledag():
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   286
        for (ctx, parents) in revdag:
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   287
            # log_strings is the list of all log strings to draw alongside
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   288
            # the graph.
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   289
            displayer.show(ctx)
7371
6ad2b914acbd graphlog: use built-in log output buffering
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7370
diff changeset
   290
            lines = displayer.hunk.pop(ctx.rev()).split("\n")[:-1]
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   291
            char = ctx.node() in repo_parents and '@' or 'o'
7371
6ad2b914acbd graphlog: use built-in log output buffering
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7370
diff changeset
   292
            yield (ctx.rev(), parents, char, lines)
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   293
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   294
    ascii(ui, grapher(graphabledag()))
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   295
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   296
cmdtable = {
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   297
    "glog":
4730
eadfaa9ec487 Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
   298
        (graphlog,
eadfaa9ec487 Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
   299
         [('l', 'limit', '', _('limit number of changes displayed')),
eadfaa9ec487 Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
   300
          ('p', 'patch', False, _('show patch')),
eadfaa9ec487 Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
   301
          ('r', 'rev', [], _('show the specified revision or range')),
6192
cd65a67aff31 Introduce templateopts and logopts to reduce duplicate option definitions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5968
diff changeset
   302
         ] + templateopts,
5942
b75105de8573 glog shows at most one file: correct synopsis
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5940
diff changeset
   303
         _('hg glog [OPTION]... [FILE]')),
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   304
}