Changeset aa5eebcf2f3c…
Parent e45db46f820d…
by
Changes to 3 files · Browse files at aa5eebcf2f3c Showing diff from parent e45db46f820d Diff from another changeset...
|
@@ -0,0 +1,99 @@ + # chunkselect.py - Change chunk selection dialog
+#
+# Copyright 2010 Steve Borho <steve@borho.org>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2, incorporated herein by reference.
+
+import sys
+import cStringIO
+
+from PyQt4.QtCore import *
+from PyQt4.QtGui import *
+
+from mercurial import hg, commands, util, cmdutil, mdiff, error, patch
+
+from tortoisehg.util import hgshelve
+from tortoisehg.hgqt.htmllistview import HtmlListView
+from tortoisehg.hgqt import htmlui
+
+def check_max_diff(ctx, wfile):
+ lines = []
+ try:
+ fctx = ctx.filectx(wfile)
+ except error.LookupError:
+ fctx = None
+ if fctx and fctx.size() > hglib.getmaxdiffsize(ctx._repo.ui):
+ # Fake patch that displays size warning
+ lines = ['diff --git a/%s b/%s\n' % (wfile, wfile)]
+ lines.append(_('File is larger than the specified max size.\n'))
+ lines.append(_('Hunk selection is disabled for this file.\n'))
+ lines.append('--- a/%s\n' % wfile)
+ lines.append('+++ b/%s\n' % wfile)
+ elif '\0' in fctx.data():
+ # Fake patch that displays binary file warning
+ lines = ['diff --git a/%s b/%s\n' % (wfile, wfile)]
+ lines.append(_('File is binary.\n'))
+ lines.append(_('Hunk selection is disabled for this file.\n'))
+ lines.append('--- a/%s\n' % wfile)
+ lines.append('+++ b/%s\n' % wfile)
+ return lines
+
+class ChunkModel(QAbstractListModel):
+
+ def __init__(self, chunks):
+ QAbstractTableModel.__init__(self)
+ self.chunks = chunks
+
+ def rowCount(self, parent):
+ if not parent.isValid():
+ return len(self.chunks)
+ return 0
+
+ def columnCount(self):
+ return 1
+
+ def data(self, index, role):
+ if not index.isValid() or role != Qt.DisplayRole:
+ return QVariant()
+ if index.row() < 0 or index.row() >= len(self.chunks):
+ return QVariant()
+ return QVariant(self.chunks[index.row()])
+
+ def headerData(self, col, orientation, role):
+ if col != 0 or role != Qt.DisplayRole or orientation != Qt.Horizontal:
+ return QVariant()
+ else:
+ return QVariant("Change chunks")
+
+ def flags(self, index):
+ return Qt.ItemIsSelectable | Qt.ItemIsEnabled
+
+
+def run(ui, *pats, **opts):
+ repo = hg.repository(ui)
+ fp = cStringIO.StringIO()
+ matcher = cmdutil.matchall(repo)
+ diffopts = mdiff.diffopts(git=True, nodates=True)
+ try:
+ node1, node2 = repo['tip'].node(), repo['tip'].parents()[0].node()
+ for s in patch.diff(repo, node1, node2, match=matcher, opts=diffopts):
+ fp.writelines(s.splitlines(True))
+ except (IOError, error.RepoError, error.LookupError, util.Abort), e:
+ self.stat.stbar.set_text(str(e))
+ fp.seek(0)
+ hu = htmlui.htmlui()
+ items = []
+ for chunk in hgshelve.parsepatch(fp):
+ fp = cStringIO.StringIO()
+ chunk.write(fp)
+ fp.seek(0)
+ for a, l in patch.difflabel(fp.readlines):
+ if a: hu.write(a, label=l)
+ o, e = hu.getdata()
+ items.append(o)
+
+ cm = ChunkModel(items)
+ lv = HtmlListView(cm)
+ lv.show()
+ return lv
|
@@ -93,8 +93,9 @@ doc.setHtml(index.data().toString())
painter.save()
- options.widget.style().drawControl(QStyle.CE_ItemViewItem,
- options, painter)
+ if options.widget:
+ options.widget.style().drawControl(QStyle.CE_ItemViewItem,
+ options, painter)
painter.translate(options.rect.left(), options.rect.top())
clip = QRectF(0, 0, options.rect.width(), options.rect.height())
doc.drawContents(painter, clip)
|
@@ -35,7 +35,10 @@ def label(self, msg, label):
msg = hglib.tounicode(msg)
style = qtlib.geteffect(label)
- return '<pre style="%s">%s</pre>' % (style, msg)
+ if style:
+ return '<pre style="%s">%s</pre>' % (style, msg)
+ else:
+ return '<pre>%s</pre>' % msg
def popbuffer(self, labeled=False):
b = self._buffers.pop()
|
Loading...