Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

qtlib: introduce a thg specific patch.difflabel

Changeset 582af01c0493

Parent 8f056beaa79e

by Steve Borho

Changes to one file · Browse files at 582af01c0493 Showing diff from parent 8f056beaa79e Diff from another changeset...

 
89
90
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
93
94
 
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
@@ -89,6 +89,42 @@
  effects.append('bgcolor: ' + e)   return ';'.join(effects)   + +# Copy of patch.difflabel from Mercurial, hacked to always return +# a label for unmatched text, so it gets escaped by our htmlui +def difflabel(func, *args, **kw): + '''yields 2-tuples of (output, label) based on the output of func()''' + prefixes = [('diff', 'diff.diffline'), + ('copy', 'diff.extended'), + ('rename', 'diff.extended'), + ('old', 'diff.extended'), + ('new', 'diff.extended'), + ('deleted', 'diff.extended'), + ('---', 'diff.file_a'), + ('+++', 'diff.file_b'), + ('@@', 'diff.hunk'), + ('-', 'diff.deleted'), + ('+', 'diff.inserted')] + + for chunk in func(*args, **kw): + lines = chunk.split('\n') + for i, line in enumerate(lines): + if i != 0: + yield ('\n', '') + stripline = line + if line and line[0] in '+-': + # highlight trailing whitespace, but only in changed lines + stripline = line.rstrip() + for prefix, label in prefixes: + if stripline.startswith(prefix): + yield (stripline, label) + break + else: + yield (line, 'ui.status') + if line != stripline: + yield (line[len(stripline):], 'diff.trailingwhitespace') + +  NAME_MAP = {   'fg': 'color', 'bg': 'background-color', 'family': 'font-family',   'size': 'font-size', 'weight': 'font-weight', 'space': 'white-space',