Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.7, 0.7.1, and 0.7.2

hggtk: add wrapper utility function for diffexpand

Needed to check for short lines, it's best to do this in one place

Changeset 5dc795bf225c

Parent c1bcddedc2fe

by Steve Borho

Changes to 3 files · Browse files at 5dc795bf225c Showing diff from parent c1bcddedc2fe Diff from another changeset...

 
22
23
24
25
 
26
27
28
 
374
375
376
377
378
379
380
 
409
410
411
412
413
 
414
415
416
417
418
 
419
420
421
422
 
423
424
425
 
22
23
24
 
25
26
27
28
 
374
375
376
 
377
378
379
 
408
409
410
 
 
411
412
413
414
 
 
415
416
417
 
 
418
419
420
421
@@ -22,7 +22,7 @@
 from mercurial import context, patch, revlog  from gdialog import *  from hgcmd import CmdDialog -from hglib import toutf, fromutf, displaytime, gettabwidth, hgcmd_toq +from hglib import toutf, fromutf, displaytime, hgcmd_toq, diffexpand  from gtklib import StatusBar    class ChangeSet(GDialog): @@ -374,7 +374,6 @@
    def prepare_diff(self, difflines, offset, fname):   '''Borrowed from hgview; parses changeset diffs''' - tw = gettabwidth(self.ui)   DIFFHDR = "=== %s ===\n"   idx = 0   outlines = [] @@ -409,17 +408,14 @@
  elif l.startswith("+"):   tag = "green"   stats[0] += 1 - if tw: - l = l[0] + l[1:].expandtabs(tw) + l = diffexpand(l)   elif l.startswith("-"):   stats[1] += 1   tag = "red" - if tw: - l = l[0] + l[1:].expandtabs(tw) + l = diffexpand(l)   else:   tag = "black" - if tw: - l = l[0] + l[1:].expandtabs(tw) + l = diffexpand(l)   l = l+"\n"   length = len(l.decode('utf-8'))   addtag( tag, offset, length )
Change 1 of 1 Show Entire File hggtk/​hglib.py Stacked
 
72
73
74
 
75
 
76
77
78
79
80
 
81
82
 
 
83
84
 
 
 
 
 
 
 
 
85
86
87
 
72
73
74
75
76
77
78
79
80
81
 
82
83
 
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
@@ -72,16 +72,27 @@
  return ''   return p   +_tabwidth = None  def gettabwidth(ui): + global _tabwidth   tabwidth = ui.config('tortoisehg', 'tabwidth')   try:   tabwidth = int(tabwidth)   if tabwidth < 1 or tabwidth > 16: - tabwidth = None + tabwidth = 0   except (ValueError, TypeError), e: - tabwidth = None + tabwidth = 0 + _tabwidth = tabwidth   return tabwidth   +def diffexpand(line): + 'Expand tabs in a line of diff/patch text' + if _tabwidth is None: + gettabwidth(ui.ui()) + if not _tabwidth or len(line) < 2: + return line + return line[0] + line[1:].expandtabs(_tabwidth) +    class GtkUi(ui.ui):   '''
Change 1 of 3 Show Entire File hggtk/​status.py Stacked
 
19
20
21
22
 
23
24
25
 
197
198
199
200
201
202
203
204
 
766
767
768
769
770
 
771
772
773
774
 
775
776
777
778
779
780
 
781
782
783
 
19
20
21
 
22
23
24
25
 
197
198
199
 
 
200
201
202
 
764
765
766
 
 
767
768
769
 
 
770
771
772
773
774
 
 
775
776
777
778
@@ -19,7 +19,7 @@
 from mercurial import cmdutil, util, ui, hg, commands, patch, mdiff  from mercurial import merge as merge_  from shlib import shell_notify -from hglib import toutf, rootpath, gettabwidth +from hglib import toutf, rootpath, diffexpand  from gdialog import *  from dialog import entry_dialog  import hgshelve @@ -197,8 +197,6 @@
  else:   self._setting_pos = 64000   self._setting_lastpos = 270 - self.tabwidth = gettabwidth(self.ui) -       def get_body(self): @@ -766,18 +764,15 @@
  if line.startswith('---') or line.startswith('+++'):   buffer.insert_with_tags_by_name(iter, line, 'header')   elif line.startswith('-'): - if self.tabwidth: - line = line[0] + line[1:].expandtabs(self.tabwidth) + line = diffexpand(line)   buffer.insert_with_tags_by_name(iter, line, 'removed')   elif line.startswith('+'): - if self.tabwidth: - line = line[0] + line[1:].expandtabs(self.tabwidth) + line = diffexpand(line)   buffer.insert_with_tags_by_name(iter, line, 'added')   elif line.startswith('@@'):   buffer.insert_with_tags_by_name(iter, line, 'position')   else: - if self.tabwidth: - line = line[0] + line[1:].expandtabs(self.tabwidth) + line = diffexpand(line)   buffer.insert(iter, line)     self.merge_diff_text.set_buffer(buffer)