##// END OF EJS Templates
graphmod/webcommands: use generic DAG walks...
Peter Arrenbrecht -
r8842:acd03a6e default
parent child Browse files
Show More
@@ -29,7 +29,6 b' def revisions(repo, start, stop):'
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
33 cur = start
32 cur = start
34 while cur >= stop:
33 while cur >= stop:
35 ctx = repo[cur]
34 ctx = repo[cur]
@@ -41,10 +40,8 b' def filerevs(repo, path, start, stop):'
41 """file cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples
40 """file cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples
42
41
43 This generator function walks through the revision history of a single
42 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
43 file from revision start down to revision stop.
45 equal to start).
46 """
44 """
47 assert start >= stop
48 filerev = len(repo.file(path)) - 1
45 filerev = len(repo.file(path)) - 1
49 while filerev >= 0:
46 while filerev >= 0:
50 fctx = repo.filectx(path, fileid=filerev)
47 fctx = repo.filectx(path, fileid=filerev)
@@ -68,32 +65,24 b' def nodes(repo, nodes):'
68 parents = [p.rev() for p in ctx.parents() if p.node() in include]
65 parents = [p.rev() for p in ctx.parents() if p.node() in include]
69 yield (ctx.rev(), CHANGESET, ctx, sorted(parents))
66 yield (ctx.rev(), CHANGESET, ctx, sorted(parents))
70
67
71 def graph(repo, start_rev, stop_rev):
68 def colored(dag):
72 """incremental revision grapher
69 """annotates a DAG with colored edge information
70
71 For each DAG node this function emits tuples::
73
72
74 This generator function walks through the revision history from
73 (id, type, data, (col, color), [(col, nextcol, color)])
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
77 following elements:
78
74
79 - Context of the current node
75 with the following new elements:
76
80 - Tuple (col, color) with column and color index for the current node
77 - 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
78 - A list of tuples indicating the edges between the current node and its
82 the current node and its parents.
79 parents.
83 """
80 """
84
85 if start_rev == nullrev and not stop_rev:
86 return
87
88 assert start_rev >= stop_rev
89 assert stop_rev >= 0
90 cur = start_rev
91 seen = []
81 seen = []
92 cl = repo.changelog
93 colors = {}
82 colors = {}
94 newcolor = 1
83 newcolor = 1
84 for (cur, type, data, parents) in dag:
95
85
96 while cur >= stop_rev:
97 # Compute seen and next
86 # Compute seen and next
98 if cur not in seen:
87 if cur not in seen:
99 seen.append(cur) # new head
88 seen.append(cur) # new head
@@ -104,8 +93,7 b' def graph(repo, start_rev, stop_rev):'
104 color = colors.pop(cur)
93 color = colors.pop(cur)
105 next = seen[:]
94 next = seen[:]
106
95
107 # Add parents to next_revs
96 # Add parents to next
108 parents = [x for x in cl.parentrevs(cur) if x != nullrev]
109 addparents = [p for p in parents if p not in next]
97 addparents = [p for p in parents if p not in next]
110 next[col:col + 1] = addparents
98 next[col:col + 1] = addparents
111
99
@@ -122,11 +110,10 b' def graph(repo, start_rev, stop_rev):'
122 for ecol, eid in enumerate(seen):
110 for ecol, eid in enumerate(seen):
123 if eid in next:
111 if eid in next:
124 edges.append((ecol, next.index(eid), colors[eid]))
112 edges.append((ecol, next.index(eid), colors[eid]))
125 elif eid == id:
113 elif eid == cur:
126 for p in parents:
114 for p in parents:
127 edges.append((ecol, next.index(p), colors[p]))
115 edges.append((ecol, next.index(p), colors[p]))
128
116
129 # Yield and move on
117 # Yield and move on
130 yield (repo[cur], (col, color), edges)
118 yield (cur, type, data, (col, color), edges)
131 seen = next
119 seen = next
132 cur -= 1
@@ -668,10 +668,13 b' def graph(web, req, tmpl):'
668 count = len(web.repo)
668 count = len(web.repo)
669 changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx)
669 changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx)
670
670
671 tree = list(graphmod.graph(web.repo, rev, downrev))
671 dag = graphmod.revisions(web.repo, rev, downrev)
672 tree = list(graphmod.colored(dag))
672 canvasheight = (len(tree) + 1) * bg_height - 27;
673 canvasheight = (len(tree) + 1) * bg_height - 27;
673 data = []
674 data = []
674 for (ctx, vtx, edges) in tree:
675 for (id, type, ctx, vtx, edges) in tree:
676 if type != graphmod.CHANGESET:
677 continue
675 node = short(ctx.node())
678 node = short(ctx.node())
676 age = templatefilters.age(ctx.date())
679 age = templatefilters.age(ctx.date())
677 desc = templatefilters.firstline(ctx.description())
680 desc = templatefilters.firstline(ctx.description())
General Comments 0
You need to be logged in to leave comments. Login now