Show More
@@ -1,119 +1,119 b'' | |||
|
1 | 1 | # Revision graph generator for Mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2008 Dirkjan Ochtman <dirkjan@ochtman.nl> |
|
4 | 4 | # Copyright 2007 Joel Rosdahl <joel@rosdahl.net> |
|
5 | 5 | # |
|
6 | 6 | # This software may be used and distributed according to the terms of the |
|
7 | 7 | # GNU General Public License version 2, incorporated herein by reference. |
|
8 | 8 | |
|
9 | 9 | """supports walking the history as DAGs suitable for graphical output |
|
10 | 10 | |
|
11 | 11 | The most basic format we use is that of:: |
|
12 | 12 | |
|
13 | 13 | (id, type, data, [parentids]) |
|
14 | 14 | |
|
15 | 15 | The node and parent ids are arbitrary integers which identify a node in the |
|
16 | 16 | context of the graph returned. Type is a constant specifying the node type. |
|
17 | 17 | Data depends on type. |
|
18 | 18 | """ |
|
19 | 19 | |
|
20 | 20 | from mercurial.node import nullrev |
|
21 | 21 | |
|
22 | 22 | CHANGESET = 'C' |
|
23 | 23 | |
|
24 | 24 | def revisions(repo, start, stop): |
|
25 | 25 | """cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples |
|
26 | 26 | |
|
27 | 27 | This generator function walks through the revision history from revision |
|
28 | 28 | start to revision stop (which must be less than or equal to start). It |
|
29 | 29 | returns a tuple for each node. The node and parent ids are arbitrary |
|
30 | 30 | integers which identify a node in the context of the graph returned. |
|
31 | 31 | """ |
|
32 | 32 | cur = start |
|
33 | 33 | while cur >= stop: |
|
34 | 34 | ctx = repo[cur] |
|
35 | 35 | parents = [p.rev() for p in ctx.parents() if p.rev() != nullrev] |
|
36 | 36 | yield (cur, CHANGESET, ctx, sorted(parents)) |
|
37 | 37 | cur -= 1 |
|
38 | 38 | |
|
39 | 39 | def filerevs(repo, path, start, stop): |
|
40 | 40 | """file cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples |
|
41 | 41 | |
|
42 | 42 | This generator function walks through the revision history of a single |
|
43 | 43 | file from revision start down to revision stop. |
|
44 | 44 | """ |
|
45 | 45 | filerev = len(repo.file(path)) - 1 |
|
46 | 46 | while filerev >= 0: |
|
47 | 47 | fctx = repo.filectx(path, fileid=filerev) |
|
48 | 48 | parents = [f.linkrev() for f in fctx.parents() if f.path() == path] |
|
49 | 49 | rev = fctx.rev() |
|
50 | 50 | if rev <= start: |
|
51 | yield (rev, CHANGESET, fctx, sorted(parents)) | |
|
51 | yield (rev, CHANGESET, fctx.changectx(), sorted(parents)) | |
|
52 | 52 | if rev <= stop: |
|
53 | 53 | break |
|
54 | 54 | filerev -= 1 |
|
55 | 55 | |
|
56 | 56 | def nodes(repo, nodes): |
|
57 | 57 | """cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples |
|
58 | 58 | |
|
59 | 59 | This generator function walks the given nodes. It only returns parents |
|
60 | 60 | that are in nodes, too. |
|
61 | 61 | """ |
|
62 | 62 | include = set(nodes) |
|
63 | 63 | for node in nodes: |
|
64 | 64 | ctx = repo[node] |
|
65 | 65 | parents = [p.rev() for p in ctx.parents() if p.node() in include] |
|
66 | 66 | yield (ctx.rev(), CHANGESET, ctx, sorted(parents)) |
|
67 | 67 | |
|
68 | 68 | def colored(dag): |
|
69 | 69 | """annotates a DAG with colored edge information |
|
70 | 70 | |
|
71 | 71 | For each DAG node this function emits tuples:: |
|
72 | 72 | |
|
73 | 73 | (id, type, data, (col, color), [(col, nextcol, color)]) |
|
74 | 74 | |
|
75 | 75 | with the following new elements: |
|
76 | 76 | |
|
77 | 77 | - Tuple (col, color) with column and color index for the current node |
|
78 | 78 | - A list of tuples indicating the edges between the current node and its |
|
79 | 79 | parents. |
|
80 | 80 | """ |
|
81 | 81 | seen = [] |
|
82 | 82 | colors = {} |
|
83 | 83 | newcolor = 1 |
|
84 | 84 | for (cur, type, data, parents) in dag: |
|
85 | 85 | |
|
86 | 86 | # Compute seen and next |
|
87 | 87 | if cur not in seen: |
|
88 | 88 | seen.append(cur) # new head |
|
89 | 89 | colors[cur] = newcolor |
|
90 | 90 | newcolor += 1 |
|
91 | 91 | |
|
92 | 92 | col = seen.index(cur) |
|
93 | 93 | color = colors.pop(cur) |
|
94 | 94 | next = seen[:] |
|
95 | 95 | |
|
96 | 96 | # Add parents to next |
|
97 | 97 | addparents = [p for p in parents if p not in next] |
|
98 | 98 | next[col:col + 1] = addparents |
|
99 | 99 | |
|
100 | 100 | # Set colors for the parents |
|
101 | 101 | for i, p in enumerate(addparents): |
|
102 | 102 | if not i: |
|
103 | 103 | colors[p] = color |
|
104 | 104 | else: |
|
105 | 105 | colors[p] = newcolor |
|
106 | 106 | newcolor += 1 |
|
107 | 107 | |
|
108 | 108 | # Add edges to the graph |
|
109 | 109 | edges = [] |
|
110 | 110 | for ecol, eid in enumerate(seen): |
|
111 | 111 | if eid in next: |
|
112 | 112 | edges.append((ecol, next.index(eid), colors[eid])) |
|
113 | 113 | elif eid == cur: |
|
114 | 114 | for p in parents: |
|
115 | 115 | edges.append((ecol, next.index(p), colors[p])) |
|
116 | 116 | |
|
117 | 117 | # Yield and move on |
|
118 | 118 | yield (cur, type, data, (col, color), edges) |
|
119 | 119 | seen = next |
General Comments 0
You need to be logged in to leave comments.
Login now