Mercurial > hg
annotate hgext/graphlog.py @ 16186:af3e67354beb
graphlog: apply file filters --patch/--stat output
When passing --patch/--stat, file filters have to be applied to generate the
correct diff or stat output:
- Without --follow, the static match object can be reused
- With --follow, the files displayed at revision X are the ancestors of
selected files at parent revision. To do this, we reproduce the ancestry
calculations done by --follow, lazily.
test-glog.t changes show that --patch output is not satisfying because renames
are reported as copies. This can probably be fixed by:
- Without --follow: compute files to display, look for renames sources and
extend the matcher to include them.
- With --follow: detect .path() transitions between parent/child filectx,
filter them using the linked changectx .removed() field and extend fcache
with them.
author | Patrick Mezard <patrick@mezard.eu> |
---|---|
date | Sun, 26 Feb 2012 17:12:15 +0100 |
parents | 6863caf01daa |
children | 16ec050490fc |
rev | line source |
---|---|
4344 | 1 # ASCII graph log extension for Mercurial |
2 # | |
3 # Copyright 2007 Joel Rosdahl <joel@rosdahl.net> | |
4516
96d8a56d4ef9
Removed trailing whitespace and tabs from python files
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4509
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8210
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
8228
eee2319c5895
add blank line after copyright notices and after header
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
7 |
8934
9dda4c73fc3b
extensions: change descriptions for extensions providing a few commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8932
diff
changeset
|
8 '''command to view revision graphs from a shell |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
9 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
10 This extension adds a --graph option to the incoming, outgoing and log |
9259
19a4b8fd5c48
graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9198
diff
changeset
|
11 commands. When this options is given, an ASCII representation of the |
19a4b8fd5c48
graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9198
diff
changeset
|
12 revision graph is also shown. |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
13 ''' |
4344 | 14 |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14311
diff
changeset
|
15 from mercurial.cmdutil import 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 | 17 from mercurial.i18n import _ |
6212 | 18 from mercurial.node import nullrev |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14311
diff
changeset
|
19 from mercurial import cmdutil, commands, extensions, scmutil |
16180
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
20 from mercurial import hg, util, graphmod, templatekw |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
21 |
14311
9bbac962f4dd
graphlog: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents:
14139
diff
changeset
|
22 cmdtable = {} |
9bbac962f4dd
graphlog: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents:
14139
diff
changeset
|
23 command = cmdutil.command(cmdtable) |
9bbac962f4dd
graphlog: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents:
14139
diff
changeset
|
24 |
8840
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8839
diff
changeset
|
25 ASCIIDATA = 'ASC' |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8839
diff
changeset
|
26 |
14130
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
27 def asciiedges(type, char, lines, seen, rev, parents): |
8840
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8839
diff
changeset
|
28 """adds edge info to changelog DAG walk suitable for ascii()""" |
9369
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
29 if rev not in seen: |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
30 seen.append(rev) |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
31 nodeidx = seen.index(rev) |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
32 |
9369
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
33 knownparents = [] |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
34 newparents = [] |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
35 for parent in parents: |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
36 if parent in seen: |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
37 knownparents.append(parent) |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
38 else: |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
39 newparents.append(parent) |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
40 |
9369
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
41 ncols = len(seen) |
14130
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
42 nextseen = seen[:] |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
43 nextseen[nodeidx:nodeidx + 1] = newparents |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
44 edges = [(nodeidx, nextseen.index(p)) for p in knownparents] |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
45 |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
46 while len(newparents) > 2: |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
47 # ascii() only knows how to add or remove a single column between two |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
48 # calls. Nodes with more than two parents break this constraint so we |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
49 # introduce intermediate expansion lines to grow the active node list |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
50 # slowly. |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
51 edges.append((nodeidx, nodeidx)) |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
52 edges.append((nodeidx, nodeidx + 1)) |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
53 nmorecols = 1 |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
54 yield (type, char, lines, (nodeidx, edges, ncols, nmorecols)) |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
55 char = '\\' |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
56 lines = [] |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
57 nodeidx += 1 |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
58 ncols += 1 |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
59 edges = [] |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
60 del newparents[0] |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
61 |
9369
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
62 if len(newparents) > 0: |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
63 edges.append((nodeidx, nodeidx)) |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
64 if len(newparents) > 1: |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
65 edges.append((nodeidx, nodeidx + 1)) |
14130
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
66 nmorecols = len(nextseen) - ncols |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
67 seen[:] = nextseen |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
68 yield (type, char, lines, (nodeidx, edges, ncols, nmorecols)) |
5938
9ed100559851
graphlog: add filelog revision grapher
Steve Borho <steve@borho.org>
parents:
4735
diff
changeset
|
69 |
4344 | 70 def fix_long_right_edges(edges): |
71 for (i, (start, end)) in enumerate(edges): | |
72 if end > start: | |
73 edges[i] = (start, end + 1) | |
74 | |
7326
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
75 def get_nodeline_edges_tail( |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
76 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
|
77 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
|
78 # 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
|
79 if n_columns_diff == -1: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
80 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
|
81 tail = ["|", " "] * (start - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
82 tail.extend(["/", " "] * (n_columns - start)) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
83 return tail |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
84 else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
85 return ["\\", " "] * (n_columns - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
86 else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
87 return ["|", " "] * (n_columns - node_index - 1) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
88 |
4344 | 89 def draw_edges(edges, nodeline, interline): |
90 for (start, end) in edges: | |
91 if start == end + 1: | |
92 interline[2 * end + 1] = "/" | |
93 elif start == end - 1: | |
94 interline[2 * start + 1] = "\\" | |
95 elif start == end: | |
96 interline[2 * start] = "|" | |
97 else: | |
15032
eb87fbc6d702
graphlog: attempt to fix index overrun (issue2912)
Matt Mackall <mpm@selenic.com>
parents:
14416
diff
changeset
|
98 if 2 * end >= len(nodeline): |
eb87fbc6d702
graphlog: attempt to fix index overrun (issue2912)
Matt Mackall <mpm@selenic.com>
parents:
14416
diff
changeset
|
99 continue |
4344 | 100 nodeline[2 * end] = "+" |
101 if start > end: | |
9198
061eeb602354
coding style: use a space after comma
Martin Geisler <mg@lazybytes.net>
parents:
9180
diff
changeset
|
102 (start, end) = (end, start) |
4344 | 103 for i in range(2 * start + 1, 2 * end): |
104 if nodeline[i] != "+": | |
105 nodeline[i] = "-" | |
106 | |
107 def get_padding_line(ni, n_columns, edges): | |
108 line = [] | |
109 line.extend(["|", " "] * ni) | |
110 if (ni, ni - 1) in edges or (ni, ni) in edges: | |
111 # (ni, ni - 1) (ni, ni) | |
112 # | | | | | | | | | |
113 # +---o | | o---+ | |
114 # | | c | | c | | | |
115 # | |/ / | |/ / | |
116 # | | | | | | | |
117 c = "|" | |
118 else: | |
119 c = " " | |
120 line.extend([c, " "]) | |
121 line.extend(["|", " "] * (n_columns - ni - 1)) | |
122 return line | |
123 | |
9631
1c34fca5d785
graphlog: hide internal state of ascii() from users
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
9371
diff
changeset
|
124 def asciistate(): |
1c34fca5d785
graphlog: hide internal state of ascii() from users
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
9371
diff
changeset
|
125 """returns the initial value for the "state" argument to ascii()""" |
1c34fca5d785
graphlog: hide internal state of ascii() from users
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
9371
diff
changeset
|
126 return [0, 0] |
1c34fca5d785
graphlog: hide internal state of ascii() from users
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
9371
diff
changeset
|
127 |
1c34fca5d785
graphlog: hide internal state of ascii() from users
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
9371
diff
changeset
|
128 def ascii(ui, state, type, char, text, coldata): |
8839
bbfa21b6f18a
graphlog: rename grapher to asciiedges
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8838
diff
changeset
|
129 """prints an ASCII graph of the DAG |
4344 | 130 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
131 takes the following arguments (one call per node in the graph): |
4344 | 132 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
133 - ui to write to |
9631
1c34fca5d785
graphlog: hide internal state of ascii() from users
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
9371
diff
changeset
|
134 - Somewhere to keep the needed state in (init to asciistate()) |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
135 - Column of the current node in the set of ongoing edges. |
8840
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8839
diff
changeset
|
136 - Type indicator of node data == ASCIIDATA. |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8839
diff
changeset
|
137 - Payload: (char, lines): |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8839
diff
changeset
|
138 - Character to use as node's symbol. |
d9acbe7b0049
graphmod/graphlog: make dag walks carry data as type, payload
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8839
diff
changeset
|
139 - List of lines to display as the node's text. |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
140 - 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
|
141 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
|
142 - 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
|
143 - 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
|
144 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
|
145 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
|
146 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
|
147 """ |
4344 | 148 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
149 idx, edges, ncols, coldiff = coldata |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
150 assert -2 < coldiff < 2 |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
151 if coldiff == -1: |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
152 # Transform |
4344 | 153 # |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
154 # | | | | | | |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
155 # o | | into o---+ |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
156 # |X / |/ / |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
157 # | | | | |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
158 fix_long_right_edges(edges) |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
159 |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
160 # add_padding_line says whether to rewrite |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
161 # |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
162 # | | | | | | | | |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
163 # | o---+ into | o---+ |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
164 # | / / | | | # <--- padding line |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
165 # o | | | / / |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
166 # o | | |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
167 add_padding_line = (len(text) > 2 and coldiff == -1 and |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
168 [x for (x, y) in edges if x + 1 < y]) |
4344 | 169 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
170 # fix_nodeline_tail says whether to rewrite |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
171 # |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
172 # | | o | | | | o | | |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
173 # | | |/ / | | |/ / |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
174 # | o | | into | o / / # <--- fixed nodeline tail |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
175 # | |/ / | |/ / |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
176 # o | | o | | |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
177 fix_nodeline_tail = len(text) <= 2 and not add_padding_line |
4344 | 178 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
179 # nodeline is the line containing the node character (typically o) |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
180 nodeline = ["|", " "] * idx |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
181 nodeline.extend([char, " "]) |
4344 | 182 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
183 nodeline.extend( |
9631
1c34fca5d785
graphlog: hide internal state of ascii() from users
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
9371
diff
changeset
|
184 get_nodeline_edges_tail(idx, state[1], ncols, coldiff, |
1c34fca5d785
graphlog: hide internal state of ascii() from users
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
9371
diff
changeset
|
185 state[0], fix_nodeline_tail)) |
4344 | 186 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
187 # shift_interline is the line containing the non-vertical |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
188 # edges between this entry and the next |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
189 shift_interline = ["|", " "] * idx |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
190 if coldiff == -1: |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
191 n_spaces = 1 |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
192 edge_ch = "/" |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
193 elif coldiff == 0: |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
194 n_spaces = 2 |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
195 edge_ch = "|" |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
196 else: |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
197 n_spaces = 3 |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
198 edge_ch = "\\" |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
199 shift_interline.extend(n_spaces * [" "]) |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
200 shift_interline.extend([edge_ch, " "] * (ncols - idx - 1)) |
4344 | 201 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
202 # draw edges from the current node to its parents |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
203 draw_edges(edges, nodeline, shift_interline) |
4344 | 204 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
205 # lines is the list of all graph lines to print |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
206 lines = [nodeline] |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
207 if add_padding_line: |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
208 lines.append(get_padding_line(idx, ncols, edges)) |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
209 lines.append(shift_interline) |
4344 | 210 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
211 # make sure that there are as many graph lines as there are |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
212 # log strings |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
213 while len(text) < len(lines): |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
214 text.append("") |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
215 if len(lines) < len(text): |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
216 extra_interline = ["|", " "] * (ncols + coldiff) |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
217 while len(lines) < len(text): |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
218 lines.append(extra_interline) |
4344 | 219 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
220 # print lines |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
221 indentation_level = max(ncols, ncols + coldiff) |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
222 for (line, logstr) in zip(lines, text): |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
223 ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr) |
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
224 ui.write(ln.rstrip() + '\n') |
4344 | 225 |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
226 # ... and start over |
9631
1c34fca5d785
graphlog: hide internal state of ascii() from users
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
9371
diff
changeset
|
227 state[0] = coldiff |
1c34fca5d785
graphlog: hide internal state of ascii() from users
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
9371
diff
changeset
|
228 state[1] = idx |
4344 | 229 |
7326
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
230 def get_revs(repo, rev_opt): |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
231 if rev_opt: |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14311
diff
changeset
|
232 revs = scmutil.revrange(repo, rev_opt) |
11448
25430ff23cfa
glog: fix crash on empty revision range
Eric Eisner <ede@mit.edu>
parents:
11321
diff
changeset
|
233 if len(revs) == 0: |
25430ff23cfa
glog: fix crash on empty revision range
Eric Eisner <ede@mit.edu>
parents:
11321
diff
changeset
|
234 return (nullrev, nullrev) |
7326
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
235 return (max(revs), min(revs)) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
236 else: |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
237 return (len(repo) - 1, 0) |
ba7ab8c4a577
graphlog: move functions around, eliminate helper function
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7325
diff
changeset
|
238 |
14086
2d7cb340a53f
graphlog: log -G --follow file does not work, forbid it
Patrick Mezard <pmezard@gmail.com>
parents:
14085
diff
changeset
|
239 def check_unsupported_flags(pats, opts): |
16180
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
240 for op in ["newest_first"]: |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
241 if op in opts and opts[op]: |
14043
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
14042
diff
changeset
|
242 raise util.Abort(_("-G/--graph option is incompatible with --%s") |
10097
ffa6f2eb934e
glog: fix "incompatible option" error message.
Greg Ward <greg-hg@gerg.ca>
parents:
10084
diff
changeset
|
243 % op.replace("_", "-")) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
244 |
16186
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
245 def makefilematcher(repo, pats, followfirst): |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
246 # When displaying a revision with --patch --follow FILE, we have |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
247 # to know which file of the revision must be diffed. With |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
248 # --follow, we want the names of the ancestors of FILE in the |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
249 # revision, stored in "fcache". "fcache" is populated by |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
250 # reproducing the graph traversal already done by --follow revset |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
251 # and relating linkrevs to file names (which is not "correct" but |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
252 # good enough). |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
253 fcache = {} |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
254 fcacheready = [False] |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
255 pctx = repo['.'] |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
256 wctx = repo[None] |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
257 |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
258 def populate(): |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
259 for fn in pats: |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
260 for i in ((pctx[fn],), pctx[fn].ancestors(followfirst=followfirst)): |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
261 for c in i: |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
262 fcache.setdefault(c.linkrev(), set()).add(c.path()) |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
263 |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
264 def filematcher(rev): |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
265 if not fcacheready[0]: |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
266 # Lazy initialization |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
267 fcacheready[0] = True |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
268 populate() |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
269 return scmutil.match(wctx, fcache.get(rev, []), default='path') |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
270 |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
271 return filematcher |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
272 |
16160
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
273 def revset(repo, pats, opts): |
16186
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
274 """Return (expr, filematcher) where expr is a revset string built |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
275 of revisions, log options and file patterns. If --stat or --patch |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
276 are not passed filematcher is None. Otherwise it a a callable |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
277 taking a revision number and returning a match objects filtering |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
278 the files to be detailed when displaying the revision. |
14043
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
14042
diff
changeset
|
279 """ |
14085
4852753dae36
graphlog: unify log -G revset translation
Patrick Mezard <pmezard@gmail.com>
parents:
14084
diff
changeset
|
280 opt2revset = { |
16174
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
281 'follow': ('follow()', None), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
282 'follow_first': ('_followfirst()', None), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
283 'no_merges': ('not merge()', None), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
284 'only_merges': ('merge()', None), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
285 'date': ('date(%(val)r)', None), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
286 'branch': ('branch(%(val)r)', ' or '), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
287 '_patslog': ('filelog(%(val)r)', ' or '), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
288 '_patsfollow': ('follow(%(val)r)', ' or '), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
289 '_patsfollowfirst': ('_followfirst(%(val)r)', ' or '), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
290 'keyword': ('keyword(%(val)r)', ' or '), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
291 'prune': ('not (%(val)r or ancestors(%(val)r))', ' and '), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
292 'user': ('user(%(val)r)', ' or '), |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
293 'rev': ('%(val)s', ' or '), |
14085
4852753dae36
graphlog: unify log -G revset translation
Patrick Mezard <pmezard@gmail.com>
parents:
14084
diff
changeset
|
294 } |
16157
4a828d3bc04a
graphlog: --branch and --only-branch are the same
Patrick Mezard <patrick@mezard.eu>
parents:
16150
diff
changeset
|
295 |
16159
ec33539b61f6
graphlog: paths arguments must be or'ed
Patrick Mezard <patrick@mezard.eu>
parents:
16158
diff
changeset
|
296 opts = dict(opts) |
16157
4a828d3bc04a
graphlog: --branch and --only-branch are the same
Patrick Mezard <patrick@mezard.eu>
parents:
16150
diff
changeset
|
297 # branch and only_branch are really aliases and must be handled at |
4a828d3bc04a
graphlog: --branch and --only-branch are the same
Patrick Mezard <patrick@mezard.eu>
parents:
16150
diff
changeset
|
298 # the same time |
4a828d3bc04a
graphlog: --branch and --only-branch are the same
Patrick Mezard <patrick@mezard.eu>
parents:
16150
diff
changeset
|
299 if 'branch' in opts and 'only_branch' in opts: |
4a828d3bc04a
graphlog: --branch and --only-branch are the same
Patrick Mezard <patrick@mezard.eu>
parents:
16150
diff
changeset
|
300 opts['branch'] = opts['branch'] + opts.pop('only_branch') |
16160
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
301 |
16174
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
302 follow = opts.get('follow') or opts.get('follow_first') |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
303 followfirst = opts.get('follow_first') |
16173
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
304 if 'follow' in opts: |
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
305 del opts['follow'] |
16174
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
306 if 'follow_first' in opts: |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
307 del opts['follow_first'] |
16171
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
308 # pats/include/exclude are passed to match.match() directly in |
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
309 # _matchfile() revset but walkchangerevs() builds its matcher with |
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
310 # scmutil.match(). The difference is input pats are globbed on |
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16161
diff
changeset
|
311 # platforms without shell expansion (windows). |
16173
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
312 pctx = repo[None] |
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
313 match, pats = scmutil.matchandpats(pctx, pats, opts) |
16160
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
314 slowpath = match.anypats() or (match.files() and opts.get('removed')) |
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
315 if not slowpath: |
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
316 for f in match.files(): |
16173
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
317 if follow and f not in pctx: |
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
318 raise util.Abort(_('cannot follow file not in parent ' |
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
319 'revision: "%s"') % f) |
16160
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
320 filelog = repo.file(f) |
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
321 if not len(filelog): |
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
322 # A zero count may be a directory or deleted file, so |
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
323 # try to find matching entries on the slow path. |
16173
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
324 if follow: |
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
325 raise util.Abort( |
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
326 _('cannot follow nonexistent file: "%s"') % f) |
16160
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
327 slowpath = True |
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
328 if slowpath: |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
329 # See cmdutil.walkchangerevs() slow path. |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
330 # |
16173
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
331 if follow: |
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
332 raise util.Abort(_('can only follow copies/renames for explicit ' |
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
333 'filenames')) |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
334 # pats/include/exclude cannot be represented as separate |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
335 # revset expressions as their filtering logic applies at file |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
336 # level. For instance "-I a -X a" matches a revision touching |
16181
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16180
diff
changeset
|
337 # "a" and "b" while "file(a) and not file(b)" does |
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16180
diff
changeset
|
338 # not. Besides, filesets are evaluated against the working |
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16180
diff
changeset
|
339 # directory. |
1fd352aa08fc
graphlog: evaluate FILE/-I/-X filesets on the working dir
Patrick Mezard <patrick@mezard.eu>
parents:
16180
diff
changeset
|
340 matchargs = ['r:'] |
16161
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
341 for p in pats: |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
342 matchargs.append('p:' + p) |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
343 for p in opts.get('include', []): |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
344 matchargs.append('i:' + p) |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
345 for p in opts.get('exclude', []): |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
346 matchargs.append('x:' + p) |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
347 matchargs = ','.join(('%r' % p) for p in matchargs) |
5a627b49b4d9
graphlog: paths/-I/-X handling requires a new revset
Patrick Mezard <patrick@mezard.eu>
parents:
16160
diff
changeset
|
348 opts['rev'] = opts.get('rev', []) + ['_matchfiles(%s)' % matchargs] |
16160
1bfc7ba8b404
graphlog: imitate log slowpath when inputs are explicit files
Patrick Mezard <patrick@mezard.eu>
parents:
16159
diff
changeset
|
349 else: |
16173
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
350 if follow: |
16174
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
351 if followfirst: |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
352 if pats: |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
353 opts['_patsfollowfirst'] = list(pats) |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
354 else: |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
355 opts['follow_first'] = True |
16173
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
356 else: |
16174
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
357 if pats: |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
358 opts['_patsfollow'] = list(pats) |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
359 else: |
0a73c4bd9f47
graphlog: implement --follow-first
Patrick Mezard <patrick@mezard.eu>
parents:
16173
diff
changeset
|
360 opts['follow'] = True |
16173
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
361 else: |
9178d284b880
graphlog: implement --follow with file arguments
Patrick Mezard <patrick@mezard.eu>
parents:
16171
diff
changeset
|
362 opts['_patslog'] = list(pats) |
16157
4a828d3bc04a
graphlog: --branch and --only-branch are the same
Patrick Mezard <patrick@mezard.eu>
parents:
16150
diff
changeset
|
363 |
16186
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
364 filematcher = None |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
365 if opts.get('patch') or opts.get('stat'): |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
366 if follow: |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
367 filematcher = makefilematcher(repo, pats, followfirst) |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
368 else: |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
369 filematcher = lambda rev: match |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
370 |
14043
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
14042
diff
changeset
|
371 revset = [] |
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
14042
diff
changeset
|
372 for op, val in opts.iteritems(): |
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
14042
diff
changeset
|
373 if not val: |
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
14042
diff
changeset
|
374 continue |
14085
4852753dae36
graphlog: unify log -G revset translation
Patrick Mezard <pmezard@gmail.com>
parents:
14084
diff
changeset
|
375 if op not in opt2revset: |
4852753dae36
graphlog: unify log -G revset translation
Patrick Mezard <pmezard@gmail.com>
parents:
14084
diff
changeset
|
376 continue |
16147
5607d829bf17
graphlog: explicitely join multivalue parameters
Patrick Mezard <patrick@mezard.eu>
parents:
15032
diff
changeset
|
377 revop, andor = opt2revset[op] |
16158
e04cc21b01b2
graphlog: rewrite --rev like all other options
Patrick Mezard <patrick@mezard.eu>
parents:
16157
diff
changeset
|
378 if '%(val)' not in revop: |
e04cc21b01b2
graphlog: rewrite --rev like all other options
Patrick Mezard <patrick@mezard.eu>
parents:
16157
diff
changeset
|
379 revset.append(revop) |
14085
4852753dae36
graphlog: unify log -G revset translation
Patrick Mezard <pmezard@gmail.com>
parents:
14084
diff
changeset
|
380 else: |
16147
5607d829bf17
graphlog: explicitely join multivalue parameters
Patrick Mezard <patrick@mezard.eu>
parents:
15032
diff
changeset
|
381 if not isinstance(val, list): |
5607d829bf17
graphlog: explicitely join multivalue parameters
Patrick Mezard <patrick@mezard.eu>
parents:
15032
diff
changeset
|
382 expr = revop % {'val': val} |
5607d829bf17
graphlog: explicitely join multivalue parameters
Patrick Mezard <patrick@mezard.eu>
parents:
15032
diff
changeset
|
383 else: |
5607d829bf17
graphlog: explicitely join multivalue parameters
Patrick Mezard <patrick@mezard.eu>
parents:
15032
diff
changeset
|
384 expr = '(' + andor.join((revop % {'val': v}) for v in val) + ')' |
16158
e04cc21b01b2
graphlog: rewrite --rev like all other options
Patrick Mezard <patrick@mezard.eu>
parents:
16157
diff
changeset
|
385 revset.append(expr) |
14043
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
14042
diff
changeset
|
386 |
16158
e04cc21b01b2
graphlog: rewrite --rev like all other options
Patrick Mezard <patrick@mezard.eu>
parents:
16157
diff
changeset
|
387 if revset: |
e04cc21b01b2
graphlog: rewrite --rev like all other options
Patrick Mezard <patrick@mezard.eu>
parents:
16157
diff
changeset
|
388 revset = '(' + ' and '.join(revset) + ')' |
14132
7d3bd0640262
graphlog: take the union of --rev specs instead of the intersection
Patrick Mezard <pmezard@gmail.com>
parents:
14130
diff
changeset
|
389 else: |
7d3bd0640262
graphlog: take the union of --rev specs instead of the intersection
Patrick Mezard <pmezard@gmail.com>
parents:
14130
diff
changeset
|
390 revset = 'all()' |
16186
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
391 return revset, filematcher |
14043
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
14042
diff
changeset
|
392 |
16186
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
393 def generate(ui, dag, displayer, showparents, edgefn, getrenamed=None, |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
394 filematcher=None): |
9631
1c34fca5d785
graphlog: hide internal state of ascii() from users
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
9371
diff
changeset
|
395 seen, state = [], asciistate() |
9369
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
396 for rev, type, ctx, parents in dag: |
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
397 char = ctx.node() in showparents and '@' or 'o' |
16180
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
398 copies = None |
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
399 if getrenamed and ctx.rev(): |
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
400 copies = [] |
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
401 for fn in ctx.files(): |
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
402 rename = getrenamed(fn, ctx.rev()) |
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
403 if rename: |
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
404 copies.append((fn, rename[0])) |
16186
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
405 revmatchfn = None |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
406 if filematcher is not None: |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
407 revmatchfn = filematcher(ctx.rev()) |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
408 displayer.show(ctx, copies=copies, matchfn=revmatchfn) |
9369
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
409 lines = displayer.hunk.pop(rev).split('\n')[:-1] |
12579
aa1faedeac5a
graphlog: style with header and footer (issue2395)
Mads Kiilerich <mads@kiilerich.com>
parents:
11776
diff
changeset
|
410 displayer.flush(rev) |
14130
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
411 edges = edgefn(type, char, lines, seen, rev, parents) |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
412 for type, char, lines, coldata in edges: |
5e4ec4119485
graphlog: display nodes with more than 2 predecessors
Patrick Mezard <pmezard@gmail.com>
parents:
14086
diff
changeset
|
413 ascii(ui, state, type, char, lines, coldata) |
12579
aa1faedeac5a
graphlog: style with header and footer (issue2395)
Mads Kiilerich <mads@kiilerich.com>
parents:
11776
diff
changeset
|
414 displayer.close() |
9369
20140c249e63
graphlog: move common code into function again, change function types
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9368
diff
changeset
|
415 |
14311
9bbac962f4dd
graphlog: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents:
14139
diff
changeset
|
416 @command('glog', |
9bbac962f4dd
graphlog: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents:
14139
diff
changeset
|
417 [('l', 'limit', '', |
9bbac962f4dd
graphlog: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents:
14139
diff
changeset
|
418 _('limit number of changes displayed'), _('NUM')), |
9bbac962f4dd
graphlog: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents:
14139
diff
changeset
|
419 ('p', 'patch', False, _('show patch')), |
9bbac962f4dd
graphlog: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents:
14139
diff
changeset
|
420 ('r', 'rev', [], _('show the specified revision or range'), _('REV')), |
9bbac962f4dd
graphlog: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents:
14139
diff
changeset
|
421 ] + templateopts, |
9bbac962f4dd
graphlog: use cmdutil.command decorator
Adrian Buehlmann <adrian@cadifra.com>
parents:
14139
diff
changeset
|
422 _('hg glog [OPTION]... [FILE]')) |
14043
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
14042
diff
changeset
|
423 def graphlog(ui, repo, *pats, **opts): |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
424 """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
|
425 |
9259
19a4b8fd5c48
graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9198
diff
changeset
|
426 Print a revision history alongside a revision graph drawn with |
19a4b8fd5c48
graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9198
diff
changeset
|
427 ASCII characters. |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
428 |
9259
19a4b8fd5c48
graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9198
diff
changeset
|
429 Nodes printed as an @ character are parents of the working |
19a4b8fd5c48
graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9198
diff
changeset
|
430 directory. |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
431 """ |
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
432 |
14086
2d7cb340a53f
graphlog: log -G --follow file does not work, forbid it
Patrick Mezard <pmezard@gmail.com>
parents:
14085
diff
changeset
|
433 check_unsupported_flags(pats, opts) |
7370
7bc62ebe7693
graphlog: refactor common grapher code
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7369
diff
changeset
|
434 |
16186
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
435 expr, filematcher = revset(repo, pats, opts) |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
436 revs = sorted(scmutil.revrange(repo, [expr]), reverse=1) |
14133
28085b82f801
graphlog: always sort revisions topologically
Patrick Mezard <pmezard@gmail.com>
parents:
14132
diff
changeset
|
437 limit = cmdutil.loglimit(opts) |
28085b82f801
graphlog: always sort revisions topologically
Patrick Mezard <pmezard@gmail.com>
parents:
14132
diff
changeset
|
438 if limit is not None: |
28085b82f801
graphlog: always sort revisions topologically
Patrick Mezard <pmezard@gmail.com>
parents:
14132
diff
changeset
|
439 revs = revs[:limit] |
14043
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
14042
diff
changeset
|
440 revdag = graphmod.dagwalker(repo, revs) |
7325
f9985108d4e4
graphlog: split the actual DAG grapher out into a separate method
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7324
diff
changeset
|
441 |
16180
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
442 getrenamed = None |
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
443 if opts.get('copies'): |
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
444 endrev = None |
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
445 if opts.get('rev'): |
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
446 endrev = max(scmutil.revrange(repo, opts.get('rev'))) + 1 |
46a96cc830c2
graphlog: implement --copies
Patrick Mezard <patrick@mezard.eu>
parents:
16174
diff
changeset
|
447 getrenamed = templatekw.getrenamedfn(repo, endrev=endrev) |
9368
8a4773bcbaec
graphlog: extract some setup code out of common functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9259
diff
changeset
|
448 displayer = show_changeset(ui, repo, opts, buffered=True) |
8a4773bcbaec
graphlog: extract some setup code out of common functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9259
diff
changeset
|
449 showparents = [ctx.node() for ctx in repo[None].parents()] |
16186
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
450 generate(ui, revdag, displayer, showparents, asciiedges, getrenamed, |
af3e67354beb
graphlog: apply file filters --patch/--stat output
Patrick Mezard <patrick@mezard.eu>
parents:
16184
diff
changeset
|
451 filematcher) |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
452 |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
453 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
|
454 limit = cmdutil.loglimit(opts) |
8837
d8e3a98018cb
graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8836
diff
changeset
|
455 nodes.reverse() |
10111
27457d31ae3f
cmdutil: replace sys.maxint with None as default value in loglimit
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10097
diff
changeset
|
456 if limit is not None: |
8837
d8e3a98018cb
graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8836
diff
changeset
|
457 nodes = nodes[:limit] |
d8e3a98018cb
graphmod/graphlog: extract nodelistwalk
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
8836
diff
changeset
|
458 return graphmod.nodes(repo, nodes) |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
459 |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
460 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
|
461 """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
|
462 |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
463 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
|
464 ASCII characters. |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
465 |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
466 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
|
467 directory. |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
468 """ |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
469 |
14086
2d7cb340a53f
graphlog: log -G --follow file does not work, forbid it
Patrick Mezard <pmezard@gmail.com>
parents:
14085
diff
changeset
|
470 check_unsupported_flags([], opts) |
12735
8888e56ac417
outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12730
diff
changeset
|
471 o = hg._outgoing(ui, repo, dest, opts) |
8888e56ac417
outgoing: unify common graphlog.outgoing and hg.outgoing code
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12730
diff
changeset
|
472 if o is None: |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
473 return |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
474 |
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
475 revdag = graphrevs(repo, o, opts) |
9368
8a4773bcbaec
graphlog: extract some setup code out of common functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9259
diff
changeset
|
476 displayer = show_changeset(ui, repo, opts, buffered=True) |
8a4773bcbaec
graphlog: extract some setup code out of common functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9259
diff
changeset
|
477 showparents = [ctx.node() for ctx in repo[None].parents()] |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
478 generate(ui, revdag, displayer, showparents, asciiedges) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
479 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
480 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
|
481 """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
|
482 |
9259
19a4b8fd5c48
graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9198
diff
changeset
|
483 Print the incoming changesets alongside a revision graph drawn with |
19a4b8fd5c48
graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9198
diff
changeset
|
484 ASCII characters. |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
485 |
9259
19a4b8fd5c48
graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9198
diff
changeset
|
486 Nodes printed as an @ character are parents of the working |
19a4b8fd5c48
graphlog: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9198
diff
changeset
|
487 directory. |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
488 """ |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12579
diff
changeset
|
489 def subreporecurse(): |
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12579
diff
changeset
|
490 return 1 |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
491 |
14086
2d7cb340a53f
graphlog: log -G --follow file does not work, forbid it
Patrick Mezard <pmezard@gmail.com>
parents:
14085
diff
changeset
|
492 check_unsupported_flags([], opts) |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12579
diff
changeset
|
493 def display(other, chlist, displayer): |
7716
4ad12930a459
graphlog: extract large parts of repeated code from incoming/outgoing
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7715
diff
changeset
|
494 revdag = graphrevs(other, chlist, opts) |
9368
8a4773bcbaec
graphlog: extract some setup code out of common functions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9259
diff
changeset
|
495 showparents = [ctx.node() for ctx in repo[None].parents()] |
9371
571a7acb4544
graphlog: simplify ascii drawing to process one cset at a time
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9370
diff
changeset
|
496 generate(ui, revdag, displayer, showparents, asciiedges) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
497 |
12730
33e1fd2aeb3c
incoming: unify code for incoming and graphlog.incoming
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
12579
diff
changeset
|
498 hg._incoming(display, subreporecurse, ui, repo, source, opts, buffered=True) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
499 |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
500 def uisetup(ui): |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
501 '''Initialize the extension.''' |
14416
253bda94372e
graphlog: remove unused arg from _wrapcmd
Idan Kamara <idankk86@gmail.com>
parents:
14319
diff
changeset
|
502 _wrapcmd('log', commands.table, graphlog) |
253bda94372e
graphlog: remove unused arg from _wrapcmd
Idan Kamara <idankk86@gmail.com>
parents:
14319
diff
changeset
|
503 _wrapcmd('incoming', commands.table, gincoming) |
253bda94372e
graphlog: remove unused arg from _wrapcmd
Idan Kamara <idankk86@gmail.com>
parents:
14319
diff
changeset
|
504 _wrapcmd('outgoing', commands.table, goutgoing) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
505 |
14416
253bda94372e
graphlog: remove unused arg from _wrapcmd
Idan Kamara <idankk86@gmail.com>
parents:
14319
diff
changeset
|
506 def _wrapcmd(cmd, table, wrapfn): |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
507 '''wrap the command''' |
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
508 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
|
509 if kwargs['graph']: |
14043
1c1e1232abdc
graphlog: make use of graphmod's revset support
Alexander Solovyov <alexander@solovyov.net>
parents:
14042
diff
changeset
|
510 return wrapfn(*args, **kwargs) |
7426
df0962f6c54e
Graphlog extension adds a --graph option to log/in/out
Alpar Juttner <alpar@cs.elte.hu>
parents:
7383
diff
changeset
|
511 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
|
512 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
|
513 entry[1].append(('G', 'graph', None, _("show the revision DAG"))) |