comparison hgext/graphlog.py @ 9369:20140c249e63

graphlog: move common code into function again, change function types
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Thu, 20 Aug 2009 08:35:35 +0200
parents 8a4773bcbaec
children b360addfbe0e
comparison
equal deleted inserted replaced
9368:8a4773bcbaec 9369:20140c249e63
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, graphmod 21 from mercurial import hg, url, util, graphmod
22 22
23 ASCIIDATA = 'ASC' 23 ASCIIDATA = 'ASC'
24 24
25 def asciiformat(revdag, displayer, parents): 25 def asciiedges(seen, rev, parents):
26 """formats a changelog DAG walk for ASCII output"""
27 for (id, type, ctx, parentids) in revdag:
28 if type != graphmod.CHANGESET:
29 continue
30 displayer.show(ctx)
31 lines = displayer.hunk.pop(ctx.rev()).split('\n')[:-1]
32 char = ctx.node() in parents and '@' or 'o'
33 yield (id, ASCIIDATA, (char, lines), parentids)
34
35 def asciiedges(nodes):
36 """adds edge info to changelog DAG walk suitable for ascii()""" 26 """adds edge info to changelog DAG walk suitable for ascii()"""
37 seen = [] 27 if rev not in seen:
38 for node, type, data, parents in nodes: 28 seen.append(rev)
39 if node not in seen: 29 nodeidx = seen.index(rev)
40 seen.append(node) 30
41 nodeidx = seen.index(node) 31 knownparents = []
42 32 newparents = []
43 knownparents = [] 33 for parent in parents:
44 newparents = [] 34 if parent in seen:
45 for parent in parents: 35 knownparents.append(parent)
46 if parent in seen: 36 else:
47 knownparents.append(parent) 37 newparents.append(parent)
48 else: 38
49 newparents.append(parent) 39 ncols = len(seen)
50 40 seen[nodeidx:nodeidx + 1] = newparents
51 ncols = len(seen) 41 edges = [(nodeidx, seen.index(p)) for p in knownparents]
52 nextseen = seen[:] 42
53 nextseen[nodeidx:nodeidx + 1] = newparents 43 if len(newparents) > 0:
54 edges = [(nodeidx, nextseen.index(p)) for p in knownparents] 44 edges.append((nodeidx, nodeidx))
55 45 if len(newparents) > 1:
56 if len(newparents) > 0: 46 edges.append((nodeidx, nodeidx + 1))
57 edges.append((nodeidx, nodeidx)) 47
58 if len(newparents) > 1: 48 nmorecols = len(seen) - ncols
59 edges.append((nodeidx, nodeidx + 1)) 49 return nodeidx, edges, ncols, nmorecols
60 nmorecols = len(nextseen) - ncols
61 seen = nextseen
62 yield (nodeidx, type, data, edges, ncols, nmorecols)
63 50
64 def fix_long_right_edges(edges): 51 def fix_long_right_edges(edges):
65 for (i, (start, end)) in enumerate(edges): 52 for (i, (start, end)) in enumerate(edges):
66 if end > start: 53 if end > start:
67 edges[i] = (start, end + 1) 54 edges[i] = (start, end + 1)
229 "only_merges", "user", "only_branch", "prune", "newest_first", 216 "only_merges", "user", "only_branch", "prune", "newest_first",
230 "no_merges", "include", "exclude"]: 217 "no_merges", "include", "exclude"]:
231 if op in opts and opts[op]: 218 if op in opts and opts[op]:
232 raise util.Abort(_("--graph option is incompatible with --%s") % op) 219 raise util.Abort(_("--graph option is incompatible with --%s") % op)
233 220
221 def generate(dag, displayer, showparents, edgefn):
222 seen = []
223 for rev, type, ctx, parents in dag:
224 char = ctx.node() in showparents and '@' or 'o'
225 displayer.show(ctx)
226 lines = displayer.hunk.pop(rev).split('\n')[:-1]
227 cols = edgefn(seen, rev, parents)
228 yield cols[0], type, (char, lines), cols[1], cols[2], cols[3]
229
234 def graphlog(ui, repo, path=None, **opts): 230 def graphlog(ui, repo, path=None, **opts):
235 """show revision history alongside an ASCII revision graph 231 """show revision history alongside an ASCII revision graph
236 232
237 Print a revision history alongside a revision graph drawn with 233 Print a revision history alongside a revision graph drawn with
238 ASCII characters. 234 ASCII characters.
255 else: 251 else:
256 revdag = graphmod.revisions(repo, start, stop) 252 revdag = graphmod.revisions(repo, start, stop)
257 253
258 displayer = show_changeset(ui, repo, opts, buffered=True) 254 displayer = show_changeset(ui, repo, opts, buffered=True)
259 showparents = [ctx.node() for ctx in repo[None].parents()] 255 showparents = [ctx.node() for ctx in repo[None].parents()]
260 fmtdag = asciiformat(revdag, displayer, showparents) 256 gen = generate(revdag, displayer, showparents, asciiedges)
261 ascii(ui, asciiedges(fmtdag)) 257 ascii(ui, gen)
262 258
263 def graphrevs(repo, nodes, opts): 259 def graphrevs(repo, nodes, opts):
264 limit = cmdutil.loglimit(opts) 260 limit = cmdutil.loglimit(opts)
265 nodes.reverse() 261 nodes.reverse()
266 if limit < sys.maxint: 262 if limit < sys.maxint:
292 288
293 o = repo.changelog.nodesbetween(o, revs)[0] 289 o = repo.changelog.nodesbetween(o, revs)[0]
294 revdag = graphrevs(repo, o, opts) 290 revdag = graphrevs(repo, o, opts)
295 displayer = show_changeset(ui, repo, opts, buffered=True) 291 displayer = show_changeset(ui, repo, opts, buffered=True)
296 showparents = [ctx.node() for ctx in repo[None].parents()] 292 showparents = [ctx.node() for ctx in repo[None].parents()]
297 fmtdag = asciiformat(revdag, displayer, showparents) 293 gen = generate(revdag, displayer, showparents, asciiedges)
298 ascii(ui, asciiedges(fmtdag)) 294 ascii(ui, gen)
299 295
300 def gincoming(ui, repo, source="default", **opts): 296 def gincoming(ui, repo, source="default", **opts):
301 """show the incoming changesets alongside an ASCII revision graph 297 """show the incoming changesets alongside an ASCII revision graph
302 298
303 Print the incoming changesets alongside a revision graph drawn with 299 Print the incoming changesets alongside a revision graph drawn with
343 339
344 chlist = other.changelog.nodesbetween(incoming, revs)[0] 340 chlist = other.changelog.nodesbetween(incoming, revs)[0]
345 revdag = graphrevs(other, chlist, opts) 341 revdag = graphrevs(other, chlist, opts)
346 displayer = show_changeset(ui, other, opts, buffered=True) 342 displayer = show_changeset(ui, other, opts, buffered=True)
347 showparents = [ctx.node() for ctx in repo[None].parents()] 343 showparents = [ctx.node() for ctx in repo[None].parents()]
348 fmtdag = asciiformat(revdag, displayer, showparents) 344 gen = generate(revdag, displayer, showparents, asciiedges)
349 ascii(ui, asciiedges(fmtdag)) 345 ascii(ui, gen)
350 346
351 finally: 347 finally:
352 if hasattr(other, 'close'): 348 if hasattr(other, 'close'):
353 other.close() 349 other.close()
354 if cleanup: 350 if cleanup: