Changeset 5dc795bf225c…
Parent c1bcddedc2fe…
by
Changes to 3 files · Browse files at 5dc795bf225c Showing diff from parent c1bcddedc2fe Diff from another changeset...
@@ -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 )
|
@@ -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):
'''
|
@@ -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)
|
Loading...