##// END OF EJS Templates
graphlog: move common code into function again, change function types
Dirkjan Ochtman -
r9369:20140c24 default
parent child Browse files
Show More
@@ -22,44 +22,31 b' from mercurial import hg, url, util, gra'
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)
41 nodeidx = seen.index(node)
42
30
43 knownparents = []
31 knownparents = []
44 newparents = []
32 newparents = []
45 for parent in parents:
33 for parent in parents:
46 if parent in seen:
34 if parent in seen:
47 knownparents.append(parent)
35 knownparents.append(parent)
48 else:
36 else:
49 newparents.append(parent)
37 newparents.append(parent)
50
38
51 ncols = len(seen)
39 ncols = len(seen)
52 nextseen = seen[:]
40 seen[nodeidx:nodeidx + 1] = newparents
53 nextseen[nodeidx:nodeidx + 1] = newparents
41 edges = [(nodeidx, seen.index(p)) for p in knownparents]
54 edges = [(nodeidx, nextseen.index(p)) for p in knownparents]
55
42
56 if len(newparents) > 0:
43 if len(newparents) > 0:
57 edges.append((nodeidx, nodeidx))
44 edges.append((nodeidx, nodeidx))
58 if len(newparents) > 1:
45 if len(newparents) > 1:
59 edges.append((nodeidx, nodeidx + 1))
46 edges.append((nodeidx, nodeidx + 1))
60 nmorecols = len(nextseen) - ncols
47
61 seen = nextseen
48 nmorecols = len(seen) - ncols
62 yield (nodeidx, type, data, edges, ncols, nmorecols)
49 return nodeidx, 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):
@@ -231,6 +218,15 b' def check_unsupported_flags(opts):'
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
@@ -257,8 +253,8 b' def graphlog(ui, repo, path=None, **opts'
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)
@@ -294,8 +290,8 b' def goutgoing(ui, repo, dest=None, **opt'
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
@@ -345,8 +341,8 b' def gincoming(ui, repo, source="default"'
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'):
General Comments 0
You need to be logged in to leave comments. Login now