hgext/graphlog.py
author Dirkjan Ochtman <dirkjan@ochtman.nl>
Thu, 20 Aug 2009 08:35:35 +0200
changeset 9369 20140c249e63
parent 9368 8a4773bcbaec
child 9370 b360addfbe0e
permissions -rw-r--r--
graphlog: move common code into function again, change function types
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
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8210
diff changeset
     5
# This software may be used and distributed according to the terms of the
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8210
diff changeset
     6
# GNU General Public License version 2, incorporated herein by reference.
8228
eee2319c5895 add blank line after copyright notices and after header
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     7
8934
9dda4c73fc3b extensions: change descriptions for extensions providing a few commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8932
diff changeset
     8
'''command to view revision graphs from a shell
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
     9
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
    10
This extension adds a --graph option to the incoming, outgoing and log
9259
19a4b8fd5c48 graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9198
diff changeset
    11
commands. When this options is given, an ASCII representation of the
19a4b8fd5c48 graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9198
diff changeset
    12
revision graph is also shown.
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
    13
'''
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    14
8837
d8e3a98018cb graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8836
diff changeset
    15
import os, sys
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    16
from mercurial.cmdutil import revrange, show_changeset
7873
4a4c7f6a5912 cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7763
diff changeset
    17
from mercurial.commands import templateopts
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    18
from mercurial.i18n import _
6212
e75aab656f46 Remove unused imports
Joel Rosdahl <joel@rosdahl.net>
parents: 6192
diff changeset
    19
from mercurial.node import nullrev
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
    20
from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions
8836
11ff34956ee7 graphmod/graphlog: move log walks to graphmod
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8667
diff changeset
    21
from mercurial import hg, url, util, graphmod
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    22
8840
d9acbe7b0049 graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8839
diff changeset
    23
ASCIIDATA = 'ASC'
d9acbe7b0049 graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8839
diff changeset
    24
9369
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    25
def asciiedges(seen, rev, parents):
8840
d9acbe7b0049 graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8839
diff changeset
    26
    """adds edge info to changelog DAG walk suitable for ascii()"""
9369
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    27
    if rev not in seen:
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    28
        seen.append(rev)
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    29
    nodeidx = seen.index(rev)
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    30
9369
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    31
    knownparents = []
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    32
    newparents = []
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    33
    for parent in parents:
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    34
        if parent in seen:
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    35
            knownparents.append(parent)
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    36
        else:
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    37
            newparents.append(parent)
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    38
9369
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    39
    ncols = len(seen)
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    40
    seen[nodeidx:nodeidx + 1] = newparents
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    41
    edges = [(nodeidx, seen.index(p)) for p in knownparents]
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    42
9369
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    43
    if len(newparents) > 0:
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    44
        edges.append((nodeidx, nodeidx))
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    45
    if len(newparents) > 1:
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    46
        edges.append((nodeidx, nodeidx + 1))
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    47
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    48
    nmorecols = len(seen) - ncols
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
    49
    return nodeidx, edges, ncols, nmorecols
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    50
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    51
def fix_long_right_edges(edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    52
    for (i, (start, end)) in enumerate(edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    53
        if end > start:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    54
            edges[i] = (start, end + 1)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    55
7326
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    56
def get_nodeline_edges_tail(
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    57
        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
    58
    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
    59
        # 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
    60
        if n_columns_diff == -1:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    61
            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
    62
            tail = ["|", " "] * (start - node_index - 1)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    63
            tail.extend(["/", " "] * (n_columns - start))
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    64
            return tail
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    65
        else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    66
            return ["\\", " "] * (n_columns - node_index - 1)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    67
    else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    68
        return ["|", " "] * (n_columns - node_index - 1)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    69
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    70
def draw_edges(edges, nodeline, interline):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    71
    for (start, end) in edges:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    72
        if start == end + 1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    73
            interline[2 * end + 1] = "/"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    74
        elif start == end - 1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    75
            interline[2 * start + 1] = "\\"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    76
        elif start == end:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    77
            interline[2 * start] = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    78
        else:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    79
            nodeline[2 * end] = "+"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    80
            if start > end:
9198
061eeb602354 coding style: use a space after comma
Martin Geisler <mg@lazybytes.net>
parents: 9180
diff changeset
    81
                (start, end) = (end, start)
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    82
            for i in range(2 * start + 1, 2 * end):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    83
                if nodeline[i] != "+":
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    84
                    nodeline[i] = "-"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    85
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    86
def get_padding_line(ni, n_columns, edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    87
    line = []
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    88
    line.extend(["|", " "] * ni)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    89
    if (ni, ni - 1) in edges or (ni, ni) in edges:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    90
        # (ni, ni - 1)      (ni, ni)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    91
        # | | | |           | | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    92
        # +---o |           | o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    93
        # | | c |           | c | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    94
        # | |/ /            | |/ /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    95
        # | | |             | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    96
        c = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    97
    else:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    98
        c = " "
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    99
    line.extend([c, " "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   100
    line.extend(["|", " "] * (n_columns - ni - 1))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   101
    return line
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   102
8839
bbfa21b6f18a graphlog: rename grapher to asciiedges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8838
diff changeset
   103
def ascii(ui, dag):
bbfa21b6f18a graphlog: rename grapher to asciiedges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8838
diff changeset
   104
    """prints an ASCII graph of the DAG
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   105
8839
bbfa21b6f18a graphlog: rename grapher to asciiedges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8838
diff changeset
   106
    dag is a generator that emits tuples with the following elements:
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   107
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   108
      - Column of the current node in the set of ongoing edges.
8840
d9acbe7b0049 graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8839
diff changeset
   109
      - Type indicator of node data == ASCIIDATA.
d9acbe7b0049 graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8839
diff changeset
   110
      - Payload: (char, lines):
d9acbe7b0049 graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8839
diff changeset
   111
        - Character to use as node's symbol.
d9acbe7b0049 graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8839
diff changeset
   112
        - List of lines to display as the node's text.
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   113
      - 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
   114
        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
   115
      - 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
   116
      - 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
   117
        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
   118
        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
   119
        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
   120
    """
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   121
    prev_n_columns_diff = 0
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   122
    prev_node_index = 0
8840
d9acbe7b0049 graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8839
diff changeset
   123
    for (node_index, type, (node_ch, node_lines), edges, n_columns, n_columns_diff) in dag:
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   124
7356
eee5b7b9c5d2 graphlog: add assertion for allowed n_column_diff range
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7355
diff changeset
   125
        assert -2 < n_columns_diff < 2
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   126
        if n_columns_diff == -1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   127
            # Transform
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   128
            #
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   129
            #     | | |        | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   130
            #     o | |  into  o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   131
            #     |X /         |/ /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   132
            #     | |          | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   133
            fix_long_right_edges(edges)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   134
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   135
        # add_padding_line says whether to rewrite
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   136
        #
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   137
        #     | | | |        | | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   138
        #     | o---+  into  | o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   139
        #     |  / /         |   | |  # <--- padding line
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   140
        #     o | |          |  / /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   141
        #                    o | |
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   142
        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
   143
                            n_columns_diff == -1 and
ff7253a0d1da Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4583
diff changeset
   144
                            [x for (x, y) in edges if x + 1 < y])
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   145
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   146
        # fix_nodeline_tail says whether to rewrite
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   147
        #
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   148
        #     | | o | |        | | o | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   149
        #     | | |/ /         | | |/ /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   150
        #     | o | |    into  | o / /   # <--- fixed nodeline tail
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   151
        #     | |/ /           | |/ /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   152
        #     o | |            o | |
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   153
        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
   154
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   155
        # nodeline is the line containing the node character (typically o)
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   156
        nodeline = ["|", " "] * node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   157
        nodeline.extend([node_ch, " "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   158
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   159
        nodeline.extend(
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   160
            get_nodeline_edges_tail(
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   161
                node_index, prev_node_index, n_columns, n_columns_diff,
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   162
                prev_n_columns_diff, fix_nodeline_tail))
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
        # 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
   165
        # edges between this entry and the next
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   166
        shift_interline = ["|", " "] * node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   167
        if n_columns_diff == -1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   168
            n_spaces = 1
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   169
            edge_ch = "/"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   170
        elif n_columns_diff == 0:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   171
            n_spaces = 2
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   172
            edge_ch = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   173
        else:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   174
            n_spaces = 3
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   175
            edge_ch = "\\"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   176
        shift_interline.extend(n_spaces * [" "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   177
        shift_interline.extend([edge_ch, " "] * (n_columns - node_index - 1))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   178
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   179
        # draw edges from the current node to its parents
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   180
        draw_edges(edges, nodeline, shift_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   181
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   182
        # lines is the list of all graph lines to print
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   183
        lines = [nodeline]
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   184
        if add_padding_line:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   185
            lines.append(get_padding_line(node_index, n_columns, edges))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   186
        lines.append(shift_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   187
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   188
        # 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
   189
        # log strings
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   190
        while len(node_lines) < len(lines):
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   191
            node_lines.append("")
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   192
        if len(lines) < len(node_lines):
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   193
            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
   194
            while len(lines) < len(node_lines):
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   195
                lines.append(extra_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   196
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   197
        # print lines
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   198
        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
   199
        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
   200
            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
   201
            ui.write(ln.rstrip() + '\n')
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   202
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   203
        # ... and start over
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   204
        prev_node_index = node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   205
        prev_n_columns_diff = n_columns_diff
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   206
7326
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   207
def get_revs(repo, rev_opt):
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   208
    if rev_opt:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   209
        revs = revrange(repo, rev_opt)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   210
        return (max(revs), min(revs))
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   211
    else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   212
        return (len(repo) - 1, 0)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   213
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   214
def check_unsupported_flags(opts):
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   215
    for op in ["follow", "follow_first", "date", "copies", "keyword", "remove",
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   216
               "only_merges", "user", "only_branch", "prune", "newest_first",
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   217
               "no_merges", "include", "exclude"]:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   218
        if op in opts and opts[op]:
7713
b8c4ba0fd7c4 graphlog: import util module rather than selected functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7435
diff changeset
   219
            raise util.Abort(_("--graph option is incompatible with --%s") % op)
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   220
9369
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   221
def generate(dag, displayer, showparents, edgefn):
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   222
    seen = []
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   223
    for rev, type, ctx, parents in dag:
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   224
        char = ctx.node() in showparents and '@' or 'o'
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   225
        displayer.show(ctx)
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   226
        lines = displayer.hunk.pop(rev).split('\n')[:-1]
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   227
        cols = edgefn(seen, rev, parents)
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   228
        yield cols[0], type, (char, lines), cols[1], cols[2], cols[3]
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   229
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   230
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
   231
    """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
   232
9259
19a4b8fd5c48 graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9198
diff changeset
   233
    Print a revision history alongside a revision graph drawn with
19a4b8fd5c48 graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9198
diff changeset
   234
    ASCII characters.
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   235
9259
19a4b8fd5c48 graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9198
diff changeset
   236
    Nodes printed as an @ character are parents of the working
19a4b8fd5c48 graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9198
diff changeset
   237
    directory.
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   238
    """
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   239
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   240
    check_unsupported_flags(opts)
7715
fd3266287b40 graphlog: reuse cmdutil.loglimit() instead of redefining
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7713
diff changeset
   241
    limit = cmdutil.loglimit(opts)
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   242
    start, stop = get_revs(repo, opts["rev"])
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   243
    stop = max(stop, start - limit + 1)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   244
    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
   245
        return
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   246
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   247
    if path:
7713
b8c4ba0fd7c4 graphlog: import util module rather than selected functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7435
diff changeset
   248
        path = util.canonpath(repo.root, os.getcwd(), path)
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   249
    if path: # could be reset in canonpath
8836
11ff34956ee7 graphmod/graphlog: move log walks to graphmod
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8667
diff changeset
   250
        revdag = graphmod.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
   251
    else:
8836
11ff34956ee7 graphmod/graphlog: move log walks to graphmod
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8667
diff changeset
   252
        revdag = graphmod.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
   253
9368
8a4773bcbaec graphlog: extract some setup code out of common functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9259
diff changeset
   254
    displayer = show_changeset(ui, repo, opts, buffered=True)
8a4773bcbaec graphlog: extract some setup code out of common functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9259
diff changeset
   255
    showparents = [ctx.node() for ctx in repo[None].parents()]
9369
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   256
    gen = generate(revdag, displayer, showparents, asciiedges)
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   257
    ascii(ui, gen)
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   258
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   259
def graphrevs(repo, nodes, opts):
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   260
    limit = cmdutil.loglimit(opts)
8837
d8e3a98018cb graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8836
diff changeset
   261
    nodes.reverse()
d8e3a98018cb graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8836
diff changeset
   262
    if limit < sys.maxint:
d8e3a98018cb graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8836
diff changeset
   263
        nodes = nodes[:limit]
d8e3a98018cb graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 8836
diff changeset
   264
    return graphmod.nodes(repo, nodes)
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   265
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   266
def goutgoing(ui, repo, dest=None, **opts):
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   267
    """show the outgoing changesets alongside an ASCII revision graph
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   268
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   269
    Print the outgoing changesets alongside a revision graph drawn with
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   270
    ASCII characters.
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   271
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   272
    Nodes printed as an @ character are parents of the working
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   273
    directory.
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   274
    """
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   275
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   276
    check_unsupported_flags(opts)
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   277
    dest, revs, checkout = hg.parseurl(
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   278
        ui.expandpath(dest or 'default-push', dest or 'default'),
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   279
        opts.get('rev'))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   280
    if revs:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   281
        revs = [repo.lookup(rev) for rev in revs]
8188
f3abe032fc89 add cmdutil.remoteui
Matt Mackall <mpm@selenic.com>
parents: 8150
diff changeset
   282
    other = hg.repository(cmdutil.remoteui(ui, opts), dest)
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   283
    ui.status(_('comparing with %s\n') % url.hidepassword(dest))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   284
    o = repo.findoutgoing(other, force=opts.get('force'))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   285
    if not o:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   286
        ui.status(_("no changes found\n"))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   287
        return
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   288
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   289
    o = repo.changelog.nodesbetween(o, revs)[0]
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   290
    revdag = graphrevs(repo, o, opts)
9368
8a4773bcbaec graphlog: extract some setup code out of common functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9259
diff changeset
   291
    displayer = show_changeset(ui, repo, opts, buffered=True)
8a4773bcbaec graphlog: extract some setup code out of common functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9259
diff changeset
   292
    showparents = [ctx.node() for ctx in repo[None].parents()]
9369
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   293
    gen = generate(revdag, displayer, showparents, asciiedges)
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   294
    ascii(ui, gen)
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   295
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   296
def gincoming(ui, repo, source="default", **opts):
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   297
    """show the incoming changesets alongside an ASCII revision graph
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   298
9259
19a4b8fd5c48 graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9198
diff changeset
   299
    Print the incoming changesets alongside a revision graph drawn with
19a4b8fd5c48 graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9198
diff changeset
   300
    ASCII characters.
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   301
9259
19a4b8fd5c48 graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9198
diff changeset
   302
    Nodes printed as an @ character are parents of the working
19a4b8fd5c48 graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9198
diff changeset
   303
    directory.
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   304
    """
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   305
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   306
    check_unsupported_flags(opts)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   307
    source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
8188
f3abe032fc89 add cmdutil.remoteui
Matt Mackall <mpm@selenic.com>
parents: 8150
diff changeset
   308
    other = hg.repository(cmdutil.remoteui(repo, opts), source)
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   309
    ui.status(_('comparing with %s\n') % url.hidepassword(source))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   310
    if revs:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   311
        revs = [other.lookup(rev) for rev in revs]
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   312
    incoming = repo.findincoming(other, heads=revs, force=opts["force"])
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   313
    if not incoming:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   314
        try:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   315
            os.unlink(opts["bundle"])
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   316
        except:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   317
            pass
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   318
        ui.status(_("no changes found\n"))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   319
        return
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   320
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   321
    cleanup = None
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   322
    try:
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   323
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   324
        fname = opts["bundle"]
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   325
        if fname or not other.local():
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   326
            # create a bundle (uncompressed if other repo is not local)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   327
            if revs is None:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   328
                cg = other.changegroup(incoming, "incoming")
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   329
            else:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   330
                cg = other.changegroupsubset(incoming, revs, 'incoming')
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   331
            bundletype = other.local() and "HG10BZ" or "HG10UN"
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   332
            fname = cleanup = changegroup.writebundle(cg, fname, bundletype)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   333
            # keep written bundle?
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   334
            if opts["bundle"]:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   335
                cleanup = None
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   336
            if not other.local():
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   337
                # use the created uncompressed bundlerepo
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   338
                other = bundlerepo.bundlerepository(ui, repo.root, fname)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   339
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   340
        chlist = other.changelog.nodesbetween(incoming, revs)[0]
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
   341
        revdag = graphrevs(other, chlist, opts)
9368
8a4773bcbaec graphlog: extract some setup code out of common functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9259
diff changeset
   342
        displayer = show_changeset(ui, other, opts, buffered=True)
8a4773bcbaec graphlog: extract some setup code out of common functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9259
diff changeset
   343
        showparents = [ctx.node() for ctx in repo[None].parents()]
9369
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   344
        gen = generate(revdag, displayer, showparents, asciiedges)
20140c249e63 graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9368
diff changeset
   345
        ascii(ui, gen)
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   346
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   347
    finally:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   348
        if hasattr(other, 'close'):
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   349
            other.close()
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   350
        if cleanup:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   351
            os.unlink(cleanup)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   352
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   353
def uisetup(ui):
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   354
    '''Initialize the extension.'''
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   355
    _wrapcmd(ui, 'log', commands.table, graphlog)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   356
    _wrapcmd(ui, 'incoming', commands.table, gincoming)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   357
    _wrapcmd(ui, 'outgoing', commands.table, goutgoing)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   358
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   359
def _wrapcmd(ui, cmd, table, wrapfn):
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   360
    '''wrap the command'''
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   361
    def graph(orig, *args, **kwargs):
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   362
        if kwargs['graph']:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   363
            return wrapfn(*args, **kwargs)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   364
        return orig(*args, **kwargs)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   365
    entry = extensions.wrapcommand(table, cmd, graph)
7763
cdc913e7fc5f log-like commands now use -G for --graph, -g for --git
Jim Correia <jim.correia@pobox.com>
parents: 7716
diff changeset
   366
    entry[1].append(('G', 'graph', None, _("show the revision DAG")))
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   367
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   368
cmdtable = {
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   369
    "glog":
4730
eadfaa9ec487 Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
   370
        (graphlog,
eadfaa9ec487 Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
   371
         [('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
   372
          ('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
   373
          ('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
   374
         ] + templateopts,
5942
b75105de8573 glog shows at most one file: correct synopsis
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5940
diff changeset
   375
         _('hg glog [OPTION]... [FILE]')),
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   376
}