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

chunkselect: introduce a chunk selection widget

Still under construction

Changeset aa5eebcf2f3c

Parent e45db46f820d

by Steve Borho

Changes to 3 files · Browse files at aa5eebcf2f3c Showing diff from parent e45db46f820d Diff from another changeset...

Change 1 of 1 Show Entire File tortoisehg/​hgqt/​chunkselect.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
99
@@ -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
94
95
96
97
 
 
 
98
99
100
 
93
94
95
 
 
96
97
98
99
100
101
@@ -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
36
37
38
 
 
 
 
39
40
41
 
35
36
37
 
38
39
40
41
42
43
44
@@ -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()