hgext/graphlog.py
author Dirkjan Ochtman <dirkjan@ochtman.nl>
Thu, 27 Nov 2008 16:07:17 +0100
changeset 7435 5e13df32fb74
parent 7426 df0962f6c54e
child 7713 b8c4ba0fd7c4
permissions -rw-r--r--
bundlerepo doesn't really have a dirstate, throw AttributeError if requested
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.
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
     7
'''show revision graphs in terminal windows
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
     8
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
     9
This extension adds a --graph option to the incoming, outgoing and log
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
    10
commands. When this options is given, an ascii representation of the
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
    11
revision graph is also shown.
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
    12
'''
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    13
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    14
import os
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    15
import sys
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    16
from mercurial.cmdutil import revrange, show_changeset
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
    17
from mercurial.commands import templateopts, logopts, remoteopts
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
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    20
from mercurial.util import Abort, canonpath
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
    21
from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
    22
from mercurial import hg, ui, url
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    23
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    24
def revisions(repo, start, stop):
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    25
    """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
    26
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    27
    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
    28
    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
    29
    """
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    30
    assert start >= stop
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    31
    cur = start
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    32
    while cur >= stop:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    33
        ctx = repo[cur]
7379
ef22cb8896d6 graphlog: fix python2.3 incompatibility (used genexp, sorted())
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7374
diff changeset
    34
        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
    35
        parents.sort()
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    36
        yield (ctx, parents)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    37
        cur -= 1
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    38
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    39
def filerevs(repo, path, start, stop):
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    40
    """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
    41
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    42
    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
    43
    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
    44
    equal to start).
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    45
    """
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    46
    assert start >= stop
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6666
diff changeset
    47
    filerev = len(repo.file(path)) - 1
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    48
    while filerev >= 0:
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    49
        fctx = repo.filectx(path, fileid=filerev)
7383
b501c7f3c2ad graphlog: fix regression with filelogs introduced by 7bc62ebe7693
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7379
diff changeset
    50
        parents = [f.linkrev() for f in fctx.parents() if f.path() == path]
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    51
        parents.sort()
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    52
        if fctx.rev() <= start:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    53
            yield (fctx, parents)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    54
        if fctx.rev() <= stop:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    55
            break
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    56
        filerev -= 1
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    57
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    58
def grapher(nodes):
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    59
    """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
    60
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    61
    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
    62
     - 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
    63
       and max length 2,
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    64
     - 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
    65
     - 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
    66
    """
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    67
    seen = []
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    68
    for node, parents, char, lines in nodes:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    69
        if node not in seen:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    70
            seen.append(node)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    71
        nodeidx = seen.index(node)
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    72
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    73
        knownparents = []
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    74
        newparents = []
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    75
        for parent in parents:
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    76
            if parent in seen:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    77
                knownparents.append(parent)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    78
            else:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    79
                newparents.append(parent)
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    80
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    81
        ncols = len(seen)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    82
        nextseen = seen[:]
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    83
        nextseen[nodeidx:nodeidx + 1] = newparents
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    84
        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
    85
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    86
        if len(newparents) > 0:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    87
            edges.append((nodeidx, nodeidx))
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    88
        if len(newparents) > 1:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    89
            edges.append((nodeidx, nodeidx + 1))
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    90
        nmorecols = len(nextseen) - ncols
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    91
        seen = nextseen
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
    92
        yield (char, lines, nodeidx, edges, ncols, nmorecols)
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
    93
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    94
def fix_long_right_edges(edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    95
    for (i, (start, end)) in enumerate(edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    96
        if end > start:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    97
            edges[i] = (start, end + 1)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
    98
7326
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
    99
def get_nodeline_edges_tail(
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   100
        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
   101
    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
   102
        # 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
   103
        if n_columns_diff == -1:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   104
            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
   105
            tail = ["|", " "] * (start - node_index - 1)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   106
            tail.extend(["/", " "] * (n_columns - start))
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   107
            return tail
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   108
        else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   109
            return ["\\", " "] * (n_columns - node_index - 1)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   110
    else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   111
        return ["|", " "] * (n_columns - node_index - 1)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   112
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   113
def draw_edges(edges, nodeline, interline):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   114
    for (start, end) in edges:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   115
        if start == end + 1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   116
            interline[2 * end + 1] = "/"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   117
        elif start == end - 1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   118
            interline[2 * start + 1] = "\\"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   119
        elif start == end:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   120
            interline[2 * start] = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   121
        else:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   122
            nodeline[2 * end] = "+"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   123
            if start > end:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   124
                (start, end) = (end,start)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   125
            for i in range(2 * start + 1, 2 * end):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   126
                if nodeline[i] != "+":
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   127
                    nodeline[i] = "-"
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
def get_padding_line(ni, n_columns, edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   130
    line = []
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   131
    line.extend(["|", " "] * ni)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   132
    if (ni, ni - 1) in edges or (ni, ni) in edges:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   133
        # (ni, ni - 1)      (ni, ni)
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
        # +---o |           | o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   136
        # | | c |           | c | |
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
        # | | |             | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   139
        c = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   140
    else:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   141
        c = " "
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   142
    line.extend([c, " "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   143
    line.extend(["|", " "] * (n_columns - ni - 1))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   144
    return line
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   145
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   146
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
   147
    """prints an ASCII graph of the DAG returned by the grapher
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   148
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   149
    grapher is a generator that emits tuples with the following elements:
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   150
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   151
      - 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
   152
      - 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
   153
      - 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
   154
      - 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
   155
        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
   156
      - 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
   157
      - 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
   158
        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
   159
        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
   160
        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
   161
    """
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   162
    prev_n_columns_diff = 0
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   163
    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
   164
    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
   165
7356
eee5b7b9c5d2 graphlog: add assertion for allowed n_column_diff range
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7355
diff changeset
   166
        assert -2 < n_columns_diff < 2
4344
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
            # Transform
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   169
            #
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
            #     o | |  into  o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   172
            #     |X /         |/ /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   173
            #     | |          | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   174
            fix_long_right_edges(edges)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   175
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   176
        # add_padding_line says whether to rewrite
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   177
        #
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   178
        #     | | | |        | | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   179
        #     | o---+  into  | o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   180
        #     |  / /         |   | |  # <--- padding line
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   181
        #     o | |          |  / /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   182
        #                    o | |
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   183
        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
   184
                            n_columns_diff == -1 and
ff7253a0d1da Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4583
diff changeset
   185
                            [x for (x, y) in edges if x + 1 < y])
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   186
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   187
        # fix_nodeline_tail says whether to rewrite
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   188
        #
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   189
        #     | | o | |        | | o | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   190
        #     | | |/ /         | | |/ /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   191
        #     | o | |    into  | o / /   # <--- fixed nodeline tail
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
        #     o | |            o | |
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   194
        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
   195
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   196
        # nodeline is the line containing the node character (typically o)
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   197
        nodeline = ["|", " "] * node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   198
        nodeline.extend([node_ch, " "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   199
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   200
        nodeline.extend(
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   201
            get_nodeline_edges_tail(
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   202
                node_index, prev_node_index, n_columns, n_columns_diff,
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   203
                prev_n_columns_diff, fix_nodeline_tail))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   204
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   205
        # 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
   206
        # edges between this entry and the next
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   207
        shift_interline = ["|", " "] * node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   208
        if n_columns_diff == -1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   209
            n_spaces = 1
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   210
            edge_ch = "/"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   211
        elif n_columns_diff == 0:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   212
            n_spaces = 2
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   213
            edge_ch = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   214
        else:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   215
            n_spaces = 3
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   216
            edge_ch = "\\"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   217
        shift_interline.extend(n_spaces * [" "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   218
        shift_interline.extend([edge_ch, " "] * (n_columns - node_index - 1))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   219
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   220
        # draw edges from the current node to its parents
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   221
        draw_edges(edges, nodeline, shift_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   222
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   223
        # lines is the list of all graph lines to print
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   224
        lines = [nodeline]
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   225
        if add_padding_line:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   226
            lines.append(get_padding_line(node_index, n_columns, edges))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   227
        lines.append(shift_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   228
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   229
        # 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
   230
        # log strings
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   231
        while len(node_lines) < len(lines):
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   232
            node_lines.append("")
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
   233
        if len(lines) < len(node_lines):
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   234
            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
   235
            while len(lines) < len(node_lines):
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   236
                lines.append(extra_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   237
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   238
        # print lines
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   239
        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
   240
        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
   241
            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
   242
            ui.write(ln.rstrip() + '\n')
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   243
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
   244
        # ... and start over
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   245
        prev_node_index = node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   246
        prev_n_columns_diff = n_columns_diff
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   247
7326
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   248
def get_limit(limit_opt):
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   249
    if limit_opt:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   250
        try:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   251
            limit = int(limit_opt)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   252
        except ValueError:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   253
            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
   254
        if limit <= 0:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   255
            raise Abort(_("limit must be positive"))
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   256
    else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   257
        limit = sys.maxint
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   258
    return limit
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   259
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   260
def get_revs(repo, rev_opt):
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   261
    if rev_opt:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   262
        revs = revrange(repo, rev_opt)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   263
        return (max(revs), min(revs))
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   264
    else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   265
        return (len(repo) - 1, 0)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
   266
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   267
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
   268
    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
   269
               "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
   270
               "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
   271
        if op in opts and opts[op]:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   272
            raise Abort(_("--graph option is incompatible with --%s") % op)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   273
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   274
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   275
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
   276
    """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
   277
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   278
    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
   279
    ASCII characters.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   280
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   281
    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
   282
    directory.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   283
    """
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   284
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   285
    check_unsupported_flags(opts)
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   286
    limit = get_limit(opts["limit"])
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   287
    start, stop = get_revs(repo, opts["rev"])
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   288
    stop = max(stop, start - limit + 1)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   289
    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
   290
        return
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   291
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   292
    if path:
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   293
        path = canonpath(repo.root, os.getcwd(), path)
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   294
    if path: # could be reset in canonpath
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   295
        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
   296
    else:
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   297
        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
   298
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
   299
    repo_parents = repo.dirstate.parents()
7371
6ad2b914acbd graphlog: use built-in log output buffering
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7370
diff changeset
   300
    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
   301
    def graphabledag():
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   302
        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
   303
            # 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
   304
            # the graph.
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   305
            displayer.show(ctx)
7371
6ad2b914acbd graphlog: use built-in log output buffering
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7370
diff changeset
   306
            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
   307
            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
   308
            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
   309
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
   310
    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
   311
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   312
def outgoing_revs(ui, repo, dest, opts):
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   313
    """cset DAG generator yielding (node, [parents]) tuples
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   314
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   315
    This generator function walks through the revisions not found
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   316
    in the destination
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   317
    """
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   318
    limit = cmdutil.loglimit(opts)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   319
    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
   320
        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
   321
        opts.get('rev'))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   322
    cmdutil.setremoteconfig(ui, opts)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   323
    if revs:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   324
        revs = [repo.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
   325
    other = hg.repository(ui, dest)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   326
    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
   327
    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
   328
    if not o:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   329
        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
   330
        return
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   331
    o = repo.changelog.nodesbetween(o, revs)[0]
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   332
    o.reverse()
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   333
    revdict = {}
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   334
    for n in o:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   335
        revdict[repo.changectx(n).rev()]=True
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   336
    count = 0
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   337
    for n in o:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   338
        if count >= limit:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   339
            break
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   340
        ctx = repo.changectx(n)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   341
        parents = [p.rev() for p in ctx.parents() if p.rev() in revdict]
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   342
        parents.sort()
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   343
        yield (ctx, parents)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   344
        count += 1
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   345
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   346
def goutgoing(ui, repo, dest=None, **opts):
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   347
    """show the outgoing 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
   348
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   349
    Print the outgoing changesets alongside a revision graph drawn with
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   350
    ASCII characters.
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   351
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   352
    Nodes printed as an @ character are parents of the working
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   353
    directory.
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   354
    """
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   355
    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
   356
    revdag = outgoing_revs(ui, repo, dest, opts)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   357
    repo_parents = repo.dirstate.parents()
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   358
    displayer = show_changeset(ui, repo, opts, buffered=True)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   359
    def graphabledag():
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   360
        for (ctx, parents) in revdag:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   361
            # log_strings is the list of all log strings to draw alongside
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   362
            # the graph.
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   363
            displayer.show(ctx)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   364
            lines = displayer.hunk.pop(ctx.rev()).split("\n")[:-1]
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   365
            char = ctx.node() in repo_parents and '@' or 'o'
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   366
            yield (ctx.rev(), parents, char, lines)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   367
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   368
    ascii(ui, grapher(graphabledag()))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   369
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   370
def incoming_revs(other, chlist, opts):
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   371
    """cset DAG generator yielding (node, [parents]) tuples
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   372
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   373
    This generator function walks through the revisions of the destination
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   374
    not found in repo
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   375
    """
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   376
    limit = cmdutil.loglimit(opts)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   377
    chlist.reverse()
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   378
    revdict = {}
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   379
    for n in chlist:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   380
        revdict[other.changectx(n).rev()]=True
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   381
    count = 0
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   382
    for n in chlist:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   383
        if count >= limit:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   384
            break
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   385
        ctx = other.changectx(n)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   386
        parents = [p.rev() for p in ctx.parents() if p.rev() in revdict]
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   387
        parents.sort()
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   388
        yield (ctx, parents)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   389
        count += 1
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   390
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   391
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
   392
    """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
   393
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   394
    Print the incoming changesets alongside a revision graph drawn with
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   395
    ASCII characters.
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   396
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   397
    Nodes printed as an @ character are parents of the working
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   398
    directory.
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   399
    """
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   400
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   401
    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
   402
    source, revs, checkout = hg.parseurl(ui.expandpath(source), opts.get('rev'))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   403
    cmdutil.setremoteconfig(ui, opts)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   404
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   405
    other = hg.repository(ui, source)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   406
    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
   407
    if revs:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   408
        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
   409
    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
   410
    if not incoming:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   411
        try:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   412
            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
   413
        except:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   414
            pass
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   415
        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
   416
        return
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   417
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   418
    cleanup = None
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   419
    try:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   420
        fname = opts["bundle"]
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   421
        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
   422
            # 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
   423
            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
   424
                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
   425
            else:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   426
                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
   427
            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
   428
            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
   429
            # keep written bundle?
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   430
            if opts["bundle"]:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   431
                cleanup = None
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   432
            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
   433
                # 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
   434
                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
   435
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   436
        chlist = other.changelog.nodesbetween(incoming, revs)[0]
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   437
        revdag = incoming_revs(other, chlist, opts)
7435
5e13df32fb74 bundlerepo doesn't really have a dirstate, throw AttributeError if requested
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7426
diff changeset
   438
        other_parents = []
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   439
        displayer = show_changeset(ui, other, opts, buffered=True)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   440
        def graphabledag():
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   441
            for (ctx, parents) in revdag:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   442
                # log_strings is the list of all log strings to draw alongside
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   443
                # the graph.
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   444
                displayer.show(ctx)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   445
                lines = displayer.hunk.pop(ctx.rev()).split("\n")[:-1]
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   446
                char = ctx.node() in other_parents and '@' or 'o'
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   447
                yield (ctx.rev(), parents, char, lines)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   448
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   449
        ascii(ui, grapher(graphabledag()))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   450
    finally:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   451
        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
   452
            other.close()
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   453
        if cleanup:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   454
            os.unlink(cleanup)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   455
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   456
def uisetup(ui):
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   457
    '''Initialize the extension.'''
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   458
    _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
   459
    _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
   460
    _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
   461
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   462
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
   463
    '''wrap the command'''
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   464
    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
   465
        if kwargs['graph']:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   466
            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
   467
        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
   468
    entry = extensions.wrapcommand(table, cmd, graph)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   469
    entry[1].append(('g', 'graph', None, _("show the revision DAG")))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
   470
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   471
cmdtable = {
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   472
    "glog":
4730
eadfaa9ec487 Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
   473
        (graphlog,
eadfaa9ec487 Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
   474
         [('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
   475
          ('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
   476
          ('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
   477
         ] + templateopts,
5942
b75105de8573 glog shows at most one file: correct synopsis
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5940
diff changeset
   478
         _('hg glog [OPTION]... [FILE]')),
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
   479
}