comparison hgext/graphlog.py @ 8836:11ff34956ee7

graphmod/graphlog: move log walks to graphmod
author Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
date Fri, 19 Jun 2009 13:14:01 +0200
parents 594507755800
children d8e3a98018cb
comparison
equal deleted inserted replaced
8835:ec5483efc31f 8836:11ff34956ee7
16 from mercurial.cmdutil import revrange, show_changeset 16 from mercurial.cmdutil import revrange, show_changeset
17 from mercurial.commands import templateopts 17 from mercurial.commands import templateopts
18 from mercurial.i18n import _ 18 from mercurial.i18n import _
19 from mercurial.node import nullrev 19 from mercurial.node import nullrev
20 from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions 20 from mercurial import bundlerepo, changegroup, cmdutil, commands, extensions
21 from mercurial import hg, url, util 21 from mercurial import hg, url, util, graphmod
22
23 def revisions(repo, start, stop):
24 """cset DAG generator yielding (rev, node, [parents]) tuples
25
26 This generator function walks through the revision history from revision
27 start to revision stop (which must be less than or equal to start).
28 """
29 assert start >= stop
30 cur = start
31 while cur >= stop:
32 ctx = repo[cur]
33 parents = [p.rev() for p in ctx.parents() if p.rev() != nullrev]
34 parents.sort()
35 yield (ctx, parents)
36 cur -= 1
37
38 def filerevs(repo, path, start, stop):
39 """file cset DAG generator yielding (rev, node, [parents]) tuples
40
41 This generator function walks through the revision history of a single
42 file from revision start to revision stop (which must be less than or
43 equal to start).
44 """
45 assert start >= stop
46 filerev = len(repo.file(path)) - 1
47 while filerev >= 0:
48 fctx = repo.filectx(path, fileid=filerev)
49 parents = [f.linkrev() for f in fctx.parents() if f.path() == path]
50 parents.sort()
51 if fctx.rev() <= start:
52 yield (fctx, parents)
53 if fctx.rev() <= stop:
54 break
55 filerev -= 1
56 22
57 def grapher(nodes): 23 def grapher(nodes):
58 """grapher for asciigraph on a list of nodes and their parents 24 """grapher for asciigraph on a list of nodes and their parents
59 25
60 nodes must generate tuples (node, parents, char, lines) where 26 nodes must generate tuples (node, parents, char, lines) where
276 return 242 return
277 243
278 if path: 244 if path:
279 path = util.canonpath(repo.root, os.getcwd(), path) 245 path = util.canonpath(repo.root, os.getcwd(), path)
280 if path: # could be reset in canonpath 246 if path: # could be reset in canonpath
281 revdag = filerevs(repo, path, start, stop) 247 revdag = graphmod.filerevs(repo, path, start, stop)
282 else: 248 else:
283 revdag = revisions(repo, start, stop) 249 revdag = graphmod.revisions(repo, start, stop)
284 250
285 graphdag = graphabledag(ui, repo, revdag, opts) 251 graphdag = graphabledag(ui, repo, revdag, opts)
286 ascii(ui, grapher(graphdag)) 252 ascii(ui, grapher(graphdag))
287 253
288 def graphrevs(repo, nodes, opts): 254 def graphrevs(repo, nodes, opts):