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 from node import nullrev |
9 """supports walking the history as DAGs suitable for graphical output |
|
10 |
|
11 The most basic format we use is that of:: |
|
12 |
|
13 (id, type, data, [parentids]) |
|
14 |
|
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. |
|
17 Data depends on type. |
|
18 """ |
|
19 |
|
20 from mercurial.node import nullrev |
|
21 |
|
22 CHANGESET = 'C' |
10 |
23 |
11 def revisions(repo, start, stop): |
24 def revisions(repo, start, stop): |
12 """cset DAG generator yielding (rev, node, [parents]) tuples |
25 """cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples |
13 |
26 |
14 This generator function walks through the revision history from revision |
27 This generator function walks through the revision history from revision |
15 start to revision stop (which must be less than or equal to start). |
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 |
|
30 integers which identify a node in the context of the graph returned. |
16 """ |
31 """ |
17 assert start >= stop |
32 assert start >= stop |
18 cur = start |
33 cur = start |
19 while cur >= stop: |
34 while cur >= stop: |
20 ctx = repo[cur] |
35 ctx = repo[cur] |
21 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] |
22 parents.sort() |
37 yield (cur, CHANGESET, ctx, sorted(parents)) |
23 yield (ctx, parents) |
|
24 cur -= 1 |
38 cur -= 1 |
25 |
39 |
26 def filerevs(repo, path, start, stop): |
40 def filerevs(repo, path, start, stop): |
27 """file cset DAG generator yielding (rev, node, [parents]) tuples |
41 """file cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples |
28 |
42 |
29 This generator function walks through the revision history of a single |
43 This generator function walks through the revision history of a single |
30 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 |
31 equal to start). |
45 equal to start). |
32 """ |
46 """ |
33 assert start >= stop |
47 assert start >= stop |
34 filerev = len(repo.file(path)) - 1 |
48 filerev = len(repo.file(path)) - 1 |
35 while filerev >= 0: |
49 while filerev >= 0: |
36 fctx = repo.filectx(path, fileid=filerev) |
50 fctx = repo.filectx(path, fileid=filerev) |
37 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] |
38 parents.sort() |
52 rev = fctx.rev() |
39 if fctx.rev() <= start: |
53 if rev <= start: |
40 yield (fctx, parents) |
54 yield (rev, CHANGESET, fctx, sorted(parents)) |
41 if fctx.rev() <= stop: |
55 if rev <= stop: |
42 break |
56 break |
43 filerev -= 1 |
57 filerev -= 1 |
44 |
58 |
45 def nodes(repo, nodes): |
59 def nodes(repo, nodes): |
|
60 """cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples |
|
61 |
|
62 This generator function walks the given nodes. It only returns parents |
|
63 that are in nodes, too. |
|
64 """ |
46 include = set(nodes) |
65 include = set(nodes) |
47 for node in nodes: |
66 for node in nodes: |
48 ctx = repo[node] |
67 ctx = repo[node] |
49 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] |
50 parents.sort() |
69 yield (ctx.rev(), CHANGESET, ctx, sorted(parents)) |
51 yield (ctx, parents) |
|
52 |
70 |
53 def graph(repo, start_rev, stop_rev): |
71 def graph(repo, start_rev, stop_rev): |
54 """incremental revision grapher |
72 """incremental revision grapher |
55 |
73 |
56 This generator function walks through the revision history from |
74 This generator function walks through the revision history from |