##// END OF EJS Templates
log: add a "graphwidth" template variable...
Danny Hooper -
r33860:6f6c8788 default
parent child Browse files
Show More
@@ -2652,14 +2652,18 b' def displaygraph(ui, repo, dag, displaye'
2652 revmatchfn = None
2652 revmatchfn = None
2653 if filematcher is not None:
2653 if filematcher is not None:
2654 revmatchfn = filematcher(ctx.rev())
2654 revmatchfn = filematcher(ctx.rev())
2655 displayer.show(ctx, copies=copies, matchfn=revmatchfn)
2655 edges = edgefn(type, char, state, rev, parents)
2656 firstedge = next(edges)
2657 width = firstedge[2]
2658 displayer.show(ctx, copies=copies, matchfn=revmatchfn,
2659 _graphwidth=width)
2656 lines = displayer.hunk.pop(rev).split('\n')
2660 lines = displayer.hunk.pop(rev).split('\n')
2657 if not lines[-1]:
2661 if not lines[-1]:
2658 del lines[-1]
2662 del lines[-1]
2659 displayer.flush(ctx)
2663 displayer.flush(ctx)
2660 edges = edgefn(type, char, lines, state, rev, parents)
2664 for type, char, width, coldata in itertools.chain([firstedge], edges):
2661 for type, char, lines, coldata in edges:
2662 graphmod.ascii(ui, state, type, char, lines, coldata)
2665 graphmod.ascii(ui, state, type, char, lines, coldata)
2666 lines = []
2663 displayer.close()
2667 displayer.close()
2664
2668
2665 def graphlog(ui, repo, pats, opts):
2669 def graphlog(ui, repo, pats, opts):
@@ -172,7 +172,7 b' def colored(dag, repo):'
172 yield (cur, type, data, (col, color), edges)
172 yield (cur, type, data, (col, color), edges)
173 seen = next
173 seen = next
174
174
175 def asciiedges(type, char, lines, state, rev, parents):
175 def asciiedges(type, char, state, rev, parents):
176 """adds edge info to changelog DAG walk suitable for ascii()"""
176 """adds edge info to changelog DAG walk suitable for ascii()"""
177 seen = state['seen']
177 seen = state['seen']
178 if rev not in seen:
178 if rev not in seen:
@@ -192,6 +192,7 b' def asciiedges(type, char, lines, state,'
192 state['edges'][parent] = state['styles'].get(ptype, '|')
192 state['edges'][parent] = state['styles'].get(ptype, '|')
193
193
194 ncols = len(seen)
194 ncols = len(seen)
195 width = 1 + ncols * 2
195 nextseen = seen[:]
196 nextseen = seen[:]
196 nextseen[nodeidx:nodeidx + 1] = newparents
197 nextseen[nodeidx:nodeidx + 1] = newparents
197 edges = [(nodeidx, nextseen.index(p)) for p in knownparents]
198 edges = [(nodeidx, nextseen.index(p)) for p in knownparents]
@@ -205,9 +206,9 b' def asciiedges(type, char, lines, state,'
205 edges.append((nodeidx, nodeidx))
206 edges.append((nodeidx, nodeidx))
206 edges.append((nodeidx, nodeidx + 1))
207 edges.append((nodeidx, nodeidx + 1))
207 nmorecols = 1
208 nmorecols = 1
208 yield (type, char, lines, (nodeidx, edges, ncols, nmorecols))
209 width += 2
210 yield (type, char, width, (nodeidx, edges, ncols, nmorecols))
209 char = '\\'
211 char = '\\'
210 lines = []
211 nodeidx += 1
212 nodeidx += 1
212 ncols += 1
213 ncols += 1
213 edges = []
214 edges = []
@@ -218,9 +219,11 b' def asciiedges(type, char, lines, state,'
218 if len(newparents) > 1:
219 if len(newparents) > 1:
219 edges.append((nodeidx, nodeidx + 1))
220 edges.append((nodeidx, nodeidx + 1))
220 nmorecols = len(nextseen) - ncols
221 nmorecols = len(nextseen) - ncols
222 if nmorecols > 0:
223 width += 2
221 # remove current node from edge characters, no longer needed
224 # remove current node from edge characters, no longer needed
222 state['edges'].pop(rev, None)
225 state['edges'].pop(rev, None)
223 yield (type, char, lines, (nodeidx, edges, ncols, nmorecols))
226 yield (type, char, width, (nodeidx, edges, ncols, nmorecols))
224
227
225 def _fixlongrightedges(edges):
228 def _fixlongrightedges(edges):
226 for (i, (start, end)) in enumerate(edges):
229 for (i, (start, end)) in enumerate(edges):
@@ -469,6 +469,13 b' def showgraphnode(repo, ctx, **args):'
469 else:
469 else:
470 return 'o'
470 return 'o'
471
471
472 @templatekeyword('graphwidth')
473 def showgraphwidth(repo, ctx, templ, **args):
474 """Integer. The width of the graph drawn by 'log --graph' or zero."""
475 # The value args['graphwidth'] will be this function, so we use an internal
476 # name to pass the value through props into this function.
477 return args.get('_graphwidth', 0)
478
472 @templatekeyword('index')
479 @templatekeyword('index')
473 def showindex(**args):
480 def showindex(**args):
474 """Integer. The current iteration of the loop. (0 indexed)"""
481 """Integer. The current iteration of the loop. (0 indexed)"""
@@ -4319,3 +4319,155 b' Test that template function in extension'
4319 custom
4319 custom
4320
4320
4321 $ cd ..
4321 $ cd ..
4322
4323 Test 'graphwidth' in 'hg log' on various topologies. The key here is that the
4324 printed graphwidths 3, 5, 7, etc. should all line up in their respective
4325 columns. We don't care about other aspects of the graph rendering here.
4326
4327 $ hg init graphwidth
4328 $ cd graphwidth
4329
4330 $ wrappabletext="a a a a a a a a a a a a"
4331
4332 $ printf "first\n" > file
4333 $ hg add file
4334 $ hg commit -m "$wrappabletext"
4335
4336 $ printf "first\nsecond\n" > file
4337 $ hg commit -m "$wrappabletext"
4338
4339 $ hg checkout 0
4340 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
4341 $ printf "third\nfirst\n" > file
4342 $ hg commit -m "$wrappabletext"
4343 created new head
4344
4345 $ hg merge
4346 merging file
4347 0 files updated, 1 files merged, 0 files removed, 0 files unresolved
4348 (branch merge, don't forget to commit)
4349
4350 $ hg log --graph -T "{graphwidth}"
4351 @ 3
4352 |
4353 | @ 5
4354 |/
4355 o 3
4356
4357 $ hg commit -m "$wrappabletext"
4358
4359 $ hg log --graph -T "{graphwidth}"
4360 @ 5
4361 |\
4362 | o 5
4363 | |
4364 o | 5
4365 |/
4366 o 3
4367
4368
4369 $ hg checkout 0
4370 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
4371 $ printf "third\nfirst\nsecond\n" > file
4372 $ hg commit -m "$wrappabletext"
4373 created new head
4374
4375 $ hg log --graph -T "{graphwidth}"
4376 @ 3
4377 |
4378 | o 7
4379 | |\
4380 +---o 7
4381 | |
4382 | o 5
4383 |/
4384 o 3
4385
4386
4387 $ hg log --graph -T "{graphwidth}" -r 3
4388 o 5
4389 |\
4390 ~ ~
4391
4392 $ hg log --graph -T "{graphwidth}" -r 1
4393 o 3
4394 |
4395 ~
4396
4397 $ hg merge
4398 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
4399 (branch merge, don't forget to commit)
4400 $ hg commit -m "$wrappabletext"
4401
4402 $ printf "seventh\n" >> file
4403 $ hg commit -m "$wrappabletext"
4404
4405 $ hg log --graph -T "{graphwidth}"
4406 @ 3
4407 |
4408 o 5
4409 |\
4410 | o 5
4411 | |
4412 o | 7
4413 |\ \
4414 | o | 7
4415 | |/
4416 o / 5
4417 |/
4418 o 3
4419
4420
4421 The point of graphwidth is to allow wrapping that accounts for the space taken
4422 by the graph.
4423
4424 $ COLUMNS=10 hg log --graph -T "{fill(desc, termwidth - graphwidth)}"
4425 @ a a a a
4426 | a a a a
4427 | a a a a
4428 o a a a
4429 |\ a a a
4430 | | a a a
4431 | | a a a
4432 | o a a a
4433 | | a a a
4434 | | a a a
4435 | | a a a
4436 o | a a
4437 |\ \ a a
4438 | | | a a
4439 | | | a a
4440 | | | a a
4441 | | | a a
4442 | o | a a
4443 | |/ a a
4444 | | a a
4445 | | a a
4446 | | a a
4447 | | a a
4448 o | a a a
4449 |/ a a a
4450 | a a a
4451 | a a a
4452 o a a a a
4453 a a a a
4454 a a a a
4455
4456 Something tricky happens when there are elided nodes; the next drawn row of
4457 edges can be more than one column wider, but the graph width only increases by
4458 one column. The remaining columns are added in between the nodes.
4459
4460 $ hg log --graph -T "{graphwidth}" -r "0|2|4|5"
4461 o 5
4462 |\
4463 | \
4464 | :\
4465 o : : 7
4466 :/ /
4467 : o 5
4468 :/
4469 o 3
4470
4471
4472 $ cd ..
4473
General Comments 0
You need to be logged in to leave comments. Login now