--- a/mercurial/graphmod.py Sat May 16 07:12:12 2009 +0200
+++ b/mercurial/graphmod.py Fri Jun 19 13:22:32 2009 +0200
@@ -6,25 +6,39 @@
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2, incorporated herein by reference.
-from node import nullrev
+"""supports walking the history as DAGs suitable for graphical output
+
+The most basic format we use is that of::
+
+ (id, type, data, [parentids])
+
+The node and parent ids are arbitrary integers which identify a node in the
+context of the graph returned. Type is a constant specifying the node type.
+Data depends on type.
+"""
+
+from mercurial.node import nullrev
+
+CHANGESET = 'C'
def revisions(repo, start, stop):
- """cset DAG generator yielding (rev, node, [parents]) tuples
+ """cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples
This generator function walks through the revision history from revision
- start to revision stop (which must be less than or equal to start).
+ start to revision stop (which must be less than or equal to start). It
+ returns a tuple for each node. The node and parent ids are arbitrary
+ integers which identify a node in the context of the graph returned.
"""
assert start >= stop
cur = start
while cur >= stop:
ctx = repo[cur]
parents = [p.rev() for p in ctx.parents() if p.rev() != nullrev]
- parents.sort()
- yield (ctx, parents)
+ yield (cur, CHANGESET, ctx, sorted(parents))
cur -= 1
def filerevs(repo, path, start, stop):
- """file cset DAG generator yielding (rev, node, [parents]) tuples
+ """file cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples
This generator function walks through the revision history of a single
file from revision start to revision stop (which must be less than or
@@ -35,20 +49,24 @@
while filerev >= 0:
fctx = repo.filectx(path, fileid=filerev)
parents = [f.linkrev() for f in fctx.parents() if f.path() == path]
- parents.sort()
- if fctx.rev() <= start:
- yield (fctx, parents)
- if fctx.rev() <= stop:
+ rev = fctx.rev()
+ if rev <= start:
+ yield (rev, CHANGESET, fctx, sorted(parents))
+ if rev <= stop:
break
filerev -= 1
def nodes(repo, nodes):
+ """cset DAG generator yielding (id, CHANGESET, ctx, [parentids]) tuples
+
+ This generator function walks the given nodes. It only returns parents
+ that are in nodes, too.
+ """
include = set(nodes)
for node in nodes:
ctx = repo[node]
parents = [p.rev() for p in ctx.parents() if p.node() in include]
- parents.sort()
- yield (ctx, parents)
+ yield (ctx.rev(), CHANGESET, ctx, sorted(parents))
def graph(repo, start_rev, stop_rev):
"""incremental revision grapher