# HG changeset patch
# User Mads Kiilerich <mads@kiilerich.com>
# Date 1565347663 -7200
# Fri Aug 09 12:47:43 2019 +0200
# Node ID 7b2f6416809c0853cf114dc33f77ebb3e2a2bbad
# Parent 9e8d211323e449177315cc2e29deb32896435a28
Make the curses UI work with Mercurial > 3.8 (closes #10132458)
https://www.logilab.org/ticket/10132458
Track 'edgemap' and 'seen' in the 'state' and pass them to Mercurial internals,
similar to how Mercurial did in
https://www.mercurial-scm.org/repo/hg/rev/0d6137891114 for Mercurial 3.8 .
# User Mads Kiilerich <mads@kiilerich.com>
# Date 1565347663 -7200
# Fri Aug 09 12:47:43 2019 +0200
# Node ID 7b2f6416809c0853cf114dc33f77ebb3e2a2bbad
# Parent 9e8d211323e449177315cc2e29deb32896435a28
Make the curses UI work with Mercurial > 3.8 (closes #10132458)
https://www.logilab.org/ticket/10132458
Track 'edgemap' and 'seen' in the 'state' and pass them to Mercurial internals,
similar to how Mercurial did in
https://www.mercurial-scm.org/repo/hg/rev/0d6137891114 for Mercurial 3.8 .
@@ -52,10 +52,25 @@
1 2 from hgviewlib.util import tounicode 3 from hgviewlib.hggraph import getlog, gettags, getdate, HgRepoListWalker 4 from hgviewlib.curses import connect_command, SelectableText 5 6 + 7 +def getnodelineedgestail(echars, idx, pidx, ncols, coldiff, pdiff, fix_tail): 8 + try: 9 + return _getnodelineedgestail(echars, idx, pidx, ncols, coldiff, pdiff, fix_tail) 10 + except TypeError: # Mercurial < 3.8: _getnodelineedgestail() takes exactly 6 arguments (7 given) 11 + return _getnodelineedgestail(idx, pidx, ncols, coldiff, pdiff, fix_tail) 12 + 13 + 14 +def drawedges(echars, edges, nodeline, interline): 15 + try: 16 + return _drawedges(echars, edges, nodeline, interline) 17 + except TypeError: # Mercurial < 3.8: _drawedges() takes exactly 3 arguments (4 given) 18 + return _drawedges(edges, nodeline, interline) 19 + 20 + 21 # __________________________________________________________________ constants 22 23 COLORS = ["brown", "dark red", "dark magenta", "dark blue", "dark cyan", 24 "dark green", "yellow", "light red", "light magenta", "light blue", 25 "light cyan", "light green"]
@@ -90,11 +105,11 @@
26 *args, **kwargs): 27 self._data_cache = {} 28 self._focus = 0 29 self.walker = walker 30 super(RevisionsWalker, self).__init__(*args, **kwargs) 31 - self.asciistate = [0, 0] # graphlog.asciistate() 32 + self.asciistate = [0, 0, {}, []] # coldiff, idx, , edgemap, seen 33 34 def connect_commands(self): 35 """Connect usefull commands to callbacks""" 36 connect_command('goto', self.set_rev) 37
@@ -217,11 +232,11 @@
38 prv, nxt, _, _ = zip(*gnode.bottomlines) 39 prv, nxt = len(set(prv)), len(set(nxt)) 40 except ValueError: # last 41 prv, nxt = 1, 0 42 coldata = (curcol, curedges, prv, nxt - prv) 43 - self.asciistate = self.asciistate or [0, 0] 44 + self.asciistate = self.asciistate or [0, 0, {}, []] 45 return hgview_ascii(self.asciistate, char, len(self._allfields), 46 coldata) 47 48 def get_focus(self): 49 """Get focused widget"""
@@ -306,10 +321,15 @@
50 51 :note: it is a Modified version of Joel Rosdahl <joel@rosdahl.net> 52 graphlog extension for mercurial 53 """ 54 idx, edges, ncols, coldiff = coldata 55 + edgemap = state[2] 56 + seen = state[3] 57 + echars = [c for p in seen for c in (edgemap.get(p, '|'), ' ')] 58 + echars.extend(('|', ' ') * max(ncols + coldiff - len(seen), 0)) 59 + 60 # graphlog is broken with multiple parent. But we have ignore that to allow 61 # some support of obsolete relation display 62 # assert -2 < coldiff < 2 63 assert height > 0 64 if coldiff == -1:
@@ -321,12 +341,12 @@
65 fix_nodeline_tail = height <= 2 and not add_padding_line 66 67 # nodeline is the line containing the node character (typically o) 68 nodeline = ["|", " "] * idx 69 nodeline.extend([('GraphLog.node', char), " "]) 70 - nodeline.extend(_getnodelineedgestail(idx, state[1], ncols, coldiff, 71 - state[0], fix_nodeline_tail)) 72 + nodeline.extend(getnodelineedgestail(echars, idx, state[1], ncols, coldiff, 73 + state[0], fix_nodeline_tail)) 74 # shift_interline is the line containing the non-vertical 75 # edges between this entry and the next 76 shift_interline = ["|", " "] * idx 77 if coldiff == -1: 78 n_spaces = 1
@@ -338,11 +358,11 @@
79 n_spaces = 3 80 edge_ch = "\\" 81 shift_interline.extend(n_spaces * [" "]) 82 shift_interline.extend([edge_ch, " "] * (ncols - idx - 1)) 83 # draw edges from the current node to its parents 84 - _drawedges(edges, nodeline, shift_interline) 85 + drawedges(echars, edges, nodeline, shift_interline) 86 # lines is the list of all graph lines to print 87 lines = [nodeline] 88 if add_padding_line: 89 lines.append(_getpaddingline(idx, ncols, edges)) 90 if not set(shift_interline).issubset(set([' ', '|'])): # compact