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