##// END OF EJS Templates
graphlog: change state dict to attr struct...
Yuya Nishihara -
r44165:e006f09e default draft
parent child Browse files
Show More
@@ -20,6 +20,7 Data depends on type.
20 20 from __future__ import absolute_import
21 21
22 22 from .node import nullrev
23 from .thirdparty import attr
23 24 from . import (
24 25 dagop,
25 26 pycompat,
@@ -192,7 +193,7 def colored(dag, repo):
192 193
193 194 def asciiedges(type, char, state, rev, parents):
194 195 """adds edge info to changelog DAG walk suitable for ascii()"""
195 seen = state[b'seen']
196 seen = state.seen
196 197 if rev not in seen:
197 198 seen.append(rev)
198 199 nodeidx = seen.index(rev)
@@ -207,7 +208,7 def asciiedges(type, char, state, rev, p
207 208 knownparents.append(parent)
208 209 else:
209 210 newparents.append(parent)
210 state[b'edges'][parent] = state[b'styles'].get(ptype, b'|')
211 state.edges[parent] = state.styles.get(ptype, b'|')
211 212
212 213 ncols = len(seen)
213 214 width = 1 + ncols * 2
@@ -240,7 +241,7 def asciiedges(type, char, state, rev, p
240 241 if nmorecols > 0:
241 242 width += 2
242 243 # remove current node from edge characters, no longer needed
243 state[b'edges'].pop(rev, None)
244 state.edges.pop(rev, None)
244 245 yield (type, char, width, (nodeidx, edges, ncols, nmorecols))
245 246
246 247
@@ -322,7 +323,7 def _drawendinglines(lines, extra, edgem
322 323 while edgechars and edgechars[-1] is None:
323 324 edgechars.pop()
324 325 shift_size = max((edgechars.count(None) * 2) - 1, 0)
325 minlines = 3 if not state[b'graphshorten'] else 2
326 minlines = 3 if not state.graphshorten else 2
326 327 while len(lines) < minlines + shift_size:
327 328 lines.append(extra[:])
328 329
@@ -344,7 +345,7 def _drawendinglines(lines, extra, edgem
344 345 positions[i] = max(pos, targets[i])
345 346 line[pos] = b'/' if pos > targets[i] else extra[toshift[i]]
346 347
347 map = {1: b'|', 2: b'~'} if not state[b'graphshorten'] else {1: b'~'}
348 map = {1: b'|', 2: b'~'} if not state.graphshorten else {1: b'~'}
348 349 for i, line in enumerate(lines):
349 350 if None not in line:
350 351 continue
@@ -357,16 +358,16 def _drawendinglines(lines, extra, edgem
357 358 seen.remove(parent)
358 359
359 360
360 def asciistate():
361 """returns the initial value for the "state" argument to ascii()"""
362 return {
363 b'seen': [],
364 b'edges': {},
365 b'lastcoldiff': 0,
366 b'lastindex': 0,
367 b'styles': EDGES.copy(),
368 b'graphshorten': False,
369 }
361 @attr.s
362 class asciistate(object):
363 """State of ascii() graph rendering"""
364
365 seen = attr.ib(init=False, default=attr.Factory(list))
366 edges = attr.ib(init=False, default=attr.Factory(dict))
367 lastcoldiff = attr.ib(init=False, default=0)
368 lastindex = attr.ib(init=False, default=0)
369 styles = attr.ib(init=False, default=attr.Factory(EDGES.copy))
370 graphshorten = attr.ib(init=False, default=False)
370 371
371 372
372 373 def outputgraph(ui, graph):
@@ -409,7 +410,7 def ascii(ui, state, type, char, text, c
409 410 idx, edges, ncols, coldiff = coldata
410 411 assert -2 < coldiff < 2
411 412
412 edgemap, seen = state[b'edges'], state[b'seen']
413 edgemap, seen = state.edges, state.seen
413 414 # Be tolerant of history issues; make sure we have at least ncols + coldiff
414 415 # elements to work with. See test-glog.t for broken history test cases.
415 416 echars = [c for p in seen for c in (edgemap.get(p, b'|'), b' ')]
@@ -452,10 +453,10 def ascii(ui, state, type, char, text, c
452 453 _getnodelineedgestail(
453 454 echars,
454 455 idx,
455 state[b'lastindex'],
456 state.lastindex,
456 457 ncols,
457 458 coldiff,
458 state[b'lastcoldiff'],
459 state.lastcoldiff,
459 460 fix_nodeline_tail,
460 461 )
461 462 )
@@ -485,7 +486,7 def ascii(ui, state, type, char, text, c
485 486
486 487 # If 'graphshorten' config, only draw shift_interline
487 488 # when there is any non vertical flow in graph.
488 if state[b'graphshorten']:
489 if state.graphshorten:
489 490 if any(c in br'\/' for c in shift_interline if c):
490 491 lines.append(shift_interline)
491 492 # Else, no 'graphshorten' config so draw shift_interline.
@@ -512,5 +513,5 def ascii(ui, state, type, char, text, c
512 513 outputgraph(ui, zip(lines, text))
513 514
514 515 # ... and start over
515 state[b'lastcoldiff'] = coldiff
516 state[b'lastindex'] = idx
516 state.lastcoldiff = coldiff
517 state.lastindex = idx
@@ -1012,7 +1012,7 def displaygraph(ui, repo, dag, displaye
1012 1012 props = props or {}
1013 1013 formatnode = _graphnodeformatter(ui, displayer)
1014 1014 state = graphmod.asciistate()
1015 styles = state[b'styles']
1015 styles = state.styles
1016 1016
1017 1017 # only set graph styling if HGPLAIN is not set.
1018 1018 if ui.plain(b'graph'):
@@ -1033,7 +1033,7 def displaygraph(ui, repo, dag, displaye
1033 1033 styles[key] = None
1034 1034
1035 1035 # experimental config: experimental.graphshorten
1036 state[b'graphshorten'] = ui.configbool(b'experimental', b'graphshorten')
1036 state.graphshorten = ui.configbool(b'experimental', b'graphshorten')
1037 1037
1038 1038 for rev, type, ctx, parents in dag:
1039 1039 char = formatnode(repo, ctx)
General Comments 0
You need to be logged in to leave comments. Login now