annotate hgext/graphlog.py @ 7995:b8e5d9487504

pager: word-wrap help texts at 70 characters
author Martin Geisler <mg@daimi.au.dk>
date Sat, 04 Apr 2009 23:18:13 +0200
parents 553aa0cbeab6
children bbc24c0753a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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 from mercurial.cmdutil import revrange, show_changeset
7873
4a4c7f6a5912 cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7763
diff changeset
16 from mercurial.commands import templateopts
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
17 from mercurial.i18n import _
6212
e75aab656f46 Remove unused imports
Joel Rosdahl <joel@rosdahl.net>
parents: 6192
diff changeset
18 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
19 from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions
7873
4a4c7f6a5912 cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7763
diff changeset
20 from mercurial import hg, url, util
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
21
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
22 def revisions(repo, start, stop):
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
23 """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
24
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
25 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
26 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
27 """
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
28 assert start >= stop
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
29 cur = start
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
30 while cur >= stop:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
31 ctx = repo[cur]
7379
ef22cb8896d6 graphlog: fix python2.3 incompatibility (used genexp, sorted())
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7374
diff changeset
32 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
33 parents.sort()
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
34 yield (ctx, parents)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
35 cur -= 1
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
36
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
37 def filerevs(repo, path, start, stop):
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
38 """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
39
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
40 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
41 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
42 equal to start).
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
43 """
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
44 assert start >= stop
6750
fb42030d79d6 add __len__ and __iter__ methods to repo and revlog
Matt Mackall <mpm@selenic.com>
parents: 6666
diff changeset
45 filerev = len(repo.file(path)) - 1
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
46 while filerev >= 0:
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
47 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
48 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
49 parents.sort()
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
50 if fctx.rev() <= start:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
51 yield (fctx, parents)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
52 if fctx.rev() <= stop:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
53 break
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
54 filerev -= 1
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
55
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
56 def grapher(nodes):
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
57 """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
58
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
59 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
60 - 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
61 and max length 2,
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
62 - 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
63 - 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
64 """
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
65 seen = []
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
66 for node, parents, char, lines in nodes:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
67 if node not in seen:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
68 seen.append(node)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
69 nodeidx = seen.index(node)
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
70
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
71 knownparents = []
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
72 newparents = []
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
73 for parent in parents:
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
74 if parent in seen:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
75 knownparents.append(parent)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
76 else:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
77 newparents.append(parent)
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
78
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
79 ncols = len(seen)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
80 nextseen = seen[:]
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
81 nextseen[nodeidx:nodeidx + 1] = newparents
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
82 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
83
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
84 if len(newparents) > 0:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
85 edges.append((nodeidx, nodeidx))
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
86 if len(newparents) > 1:
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
87 edges.append((nodeidx, nodeidx + 1))
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
88 nmorecols = len(nextseen) - ncols
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
89 seen = nextseen
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
90 yield (char, lines, nodeidx, edges, ncols, nmorecols)
5938
9ed100559851 graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents: 4735
diff changeset
91
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
92 def fix_long_right_edges(edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
93 for (i, (start, end)) in enumerate(edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
94 if end > start:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
95 edges[i] = (start, end + 1)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
96
7326
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
97 def get_nodeline_edges_tail(
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
98 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
99 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
100 # 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
101 if n_columns_diff == -1:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
102 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
103 tail = ["|", " "] * (start - node_index - 1)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
104 tail.extend(["/", " "] * (n_columns - start))
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
105 return tail
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
106 else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
107 return ["\\", " "] * (n_columns - node_index - 1)
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
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
111 def draw_edges(edges, nodeline, interline):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
112 for (start, end) in edges:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
113 if start == end + 1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
114 interline[2 * end + 1] = "/"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
115 elif start == end - 1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
116 interline[2 * start + 1] = "\\"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
117 elif start == end:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
118 interline[2 * start] = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
119 else:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
120 nodeline[2 * end] = "+"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
121 if start > end:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
122 (start, end) = (end,start)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
123 for i in range(2 * start + 1, 2 * end):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
124 if nodeline[i] != "+":
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
125 nodeline[i] = "-"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
126
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
127 def get_padding_line(ni, n_columns, edges):
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
128 line = []
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
129 line.extend(["|", " "] * ni)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
130 if (ni, ni - 1) in edges or (ni, ni) in edges:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
131 # (ni, ni - 1) (ni, ni)
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 # +---o | | o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
134 # | | c | | c | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
135 # | |/ / | |/ /
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 c = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
138 else:
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 line.extend([c, " "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
141 line.extend(["|", " "] * (n_columns - ni - 1))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
142 return line
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
143
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
144 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
145 """prints an ASCII graph of the DAG returned by the grapher
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
146
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
147 grapher is a generator that emits tuples with the following elements:
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 - 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
150 - 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
151 - 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
152 - 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
153 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
154 - 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
155 - 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
156 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
157 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
158 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
159 """
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
160 prev_n_columns_diff = 0
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
161 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
162 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
163
7356
eee5b7b9c5d2 graphlog: add assertion for allowed n_column_diff range
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7355
diff changeset
164 assert -2 < n_columns_diff < 2
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
165 if n_columns_diff == -1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
166 # Transform
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
167 #
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
168 # | | | | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
169 # o | | into o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
170 # |X / |/ /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
171 # | | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
172 fix_long_right_edges(edges)
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 # add_padding_line says whether to rewrite
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 # | | | | | | | |
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
177 # | o---+ into | o---+
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
178 # | / / | | | # <--- padding line
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
179 # o | | | / /
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
180 # o | |
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
181 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
182 n_columns_diff == -1 and
ff7253a0d1da Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4583
diff changeset
183 [x for (x, y) in edges if x + 1 < y])
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
184
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
185 # fix_nodeline_tail says whether to rewrite
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 # | | o | | | | o | |
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 | | into | o / / # <--- fixed nodeline tail
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 | | o | |
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
192 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
193
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
194 # nodeline is the line containing the node character (typically o)
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
195 nodeline = ["|", " "] * node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
196 nodeline.extend([node_ch, " "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
197
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
198 nodeline.extend(
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
199 get_nodeline_edges_tail(
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
200 node_index, prev_node_index, n_columns, n_columns_diff,
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
201 prev_n_columns_diff, fix_nodeline_tail))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
202
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
203 # 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
204 # edges between this entry and the next
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
205 shift_interline = ["|", " "] * node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
206 if n_columns_diff == -1:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
207 n_spaces = 1
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
208 edge_ch = "/"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
209 elif n_columns_diff == 0:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
210 n_spaces = 2
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
211 edge_ch = "|"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
212 else:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
213 n_spaces = 3
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
214 edge_ch = "\\"
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
215 shift_interline.extend(n_spaces * [" "])
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
216 shift_interline.extend([edge_ch, " "] * (n_columns - node_index - 1))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
217
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
218 # draw edges from the current node to its parents
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
219 draw_edges(edges, nodeline, shift_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
220
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
221 # lines is the list of all graph lines to print
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
222 lines = [nodeline]
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
223 if add_padding_line:
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
224 lines.append(get_padding_line(node_index, n_columns, edges))
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
225 lines.append(shift_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
226
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
227 # 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
228 # log strings
7324
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
229 while len(node_lines) < len(lines):
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
230 node_lines.append("")
3a2cbf68e2f1 graphlog: rename some vars prior to refactoring
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7323
diff changeset
231 if len(lines) < len(node_lines):
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
232 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
233 while len(lines) < len(node_lines):
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
234 lines.append(extra_interline)
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
235
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
236 # print lines
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
237 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
238 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
239 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
240 ui.write(ln.rstrip() + '\n')
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
241
7323
1c9f7aa7c8a5 graphlog: make some comment lines more like others in punctuation
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7280
diff changeset
242 # ... and start over
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
243 prev_node_index = node_index
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
244 prev_n_columns_diff = n_columns_diff
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
245
7326
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
246 def get_revs(repo, rev_opt):
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
247 if rev_opt:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
248 revs = revrange(repo, rev_opt)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
249 return (max(revs), min(revs))
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
250 else:
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
251 return (len(repo) - 1, 0)
ba7ab8c4a577 graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7325
diff changeset
252
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
253 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
254 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
255 "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
256 "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
257 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
258 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
259
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
260 def graphlog(ui, repo, path=None, **opts):
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
261 """show revision history alongside an ASCII revision graph
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
262
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
263 Print a revision history alongside a revision graph drawn with
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
264 ASCII characters.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
265
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
266 Nodes printed as an @ character are parents of the working
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
267 directory.
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
268 """
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
269
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
270 check_unsupported_flags(opts)
7715
fd3266287b40 graphlog: reuse cmdutil.loglimit() instead of redefining
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7713
diff changeset
271 limit = cmdutil.loglimit(opts)
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
272 start, stop = get_revs(repo, opts["rev"])
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
273 stop = max(stop, start - limit + 1)
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
274 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
275 return
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
276
7325
f9985108d4e4 graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7324
diff changeset
277 if path:
7713
b8c4ba0fd7c4 graphlog: import util module rather than selected functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7435
diff changeset
278 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
279 if path: # could be reset in canonpath
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
280 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
281 else:
7370
7bc62ebe7693 graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 7369
diff changeset
282 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
283
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
284 graphdag = graphabledag(ui, repo, revdag, opts)
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
285 ascii(ui, grapher(graphdag))
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
286
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
287 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
288 nodes.reverse()
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
289 include = util.set(nodes)
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
290 limit = cmdutil.loglimit(opts)
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
291 count = 0
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
292 for node in nodes:
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
293 if count >= limit:
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
294 break
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
295 ctx = repo[node]
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
296 parents = [p.rev() for p in ctx.parents() if p.node() in include]
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
297 parents.sort()
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
298 yield (ctx, parents)
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
299 count += 1
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
300
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
301 def graphabledag(ui, repo, revdag, opts):
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
302 showparents = [ctx.node() for ctx in repo[None].parents()]
7371
6ad2b914acbd graphlog: use built-in log output buffering
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7370
diff changeset
303 displayer = show_changeset(ui, repo, opts, buffered=True)
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
304 for (ctx, parents) in revdag:
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
305 displayer.show(ctx)
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
306 lines = displayer.hunk.pop(ctx.rev()).split('\n')[:-1]
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
307 char = ctx.node() in showparents and '@' or 'o'
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
308 yield (ctx.rev(), parents, char, lines)
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
309
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
310 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
311 """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
312
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
313 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
314 ASCII characters.
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
315
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
316 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
317 directory.
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
318 """
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
319
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
320 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
321 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
322 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
323 opts.get('rev'))
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
324 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
325 if revs:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
326 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
327 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
328 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
329 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
330 if not o:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
331 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
332 return
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
333
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
334 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
335 revdag = graphrevs(repo, o, opts)
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
336 graphdag = graphabledag(ui, repo, revdag, opts)
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
337 ascii(ui, grapher(graphdag))
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
338
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
339 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
340 """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
341
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
342 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
343 ASCII characters.
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
344
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
345 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
346 directory.
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
347 """
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 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
350 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
351 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
352
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
353 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
354 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
355 if revs:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
356 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
357 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
358 if not incoming:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
359 try:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
360 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
361 except:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
362 pass
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
363 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
364 return
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
365
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
366 cleanup = None
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
367 try:
7716
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
368
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
369 fname = opts["bundle"]
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
370 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
371 # 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
372 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
373 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
374 else:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
375 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
376 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
377 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
378 # keep written bundle?
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
379 if opts["bundle"]:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
380 cleanup = None
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
381 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
382 # 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
383 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
384
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
385 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
386 revdag = graphrevs(other, chlist, opts)
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
387 graphdag = graphabledag(ui, repo, revdag, opts)
4ad12930a459 graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7715
diff changeset
388 ascii(ui, grapher(graphdag))
7426
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
389
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
390 finally:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
391 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
392 other.close()
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
393 if cleanup:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
394 os.unlink(cleanup)
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
395
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
396 def uisetup(ui):
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
397 '''Initialize the extension.'''
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
398 _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
399 _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
400 _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
401
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
402 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
403 '''wrap the command'''
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
404 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
405 if kwargs['graph']:
df0962f6c54e Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents: 7383
diff changeset
406 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
407 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
408 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
409 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
410
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
411 cmdtable = {
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
412 "glog":
4730
eadfaa9ec487 Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
413 (graphlog,
eadfaa9ec487 Updated command tables in commands.py and hgext extensions.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
414 [('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
415 ('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
416 ('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
417 ] + templateopts,
5942
b75105de8573 glog shows at most one file: correct synopsis
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5940
diff changeset
418 _('hg glog [OPTION]... [FILE]')),
4344
345ed833854d Add graphlog extension
Joel Rosdahl <joel@rosdahl.net>
parents:
diff changeset
419 }