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