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

chunkselect: and again

Changeset 87732d1a9452

Parent 966043d60b7c

by Steve Borho

Changes to one file · Browse files at 87732d1a9452 Showing diff from parent 966043d60b7c Diff from another changeset...

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
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
 # 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, hglib  from tortoisehg.util.i18n import _  from tortoisehg.hgqt.htmllistview import HtmlListView  from tortoisehg.hgqt import htmlui    def check_max_diff(ctx, wfile):   lines = []   try:   fctx = ctx.filectx(wfile)   size = fctx.size()   except (EnvironmentError, error.LookupError):   fctx = None   if fctx and 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 fctx and '\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()   try: - for p in repo[None].diff(opts={'git':True,'nodates':True}): + for p in repo[None].diff(git=True, nodates=True):   fp.write(p)   except (IOError, error.RepoError, error.LookupError, util.Abort), e:   print e   fp.seek(0)   hu = htmlui.htmlui()   items = []   for chunk in hgshelve.parsepatch(fp):   ui.pushbuffer()   chunk.write(ui)   data = ui.popbuffer()   for a, l in patch.difflabel(data.splitlines, True):   hu.write(a, label=l)   o, e = hu.getdata()   items.append(o)     cm = ChunkModel(items)   lv = HtmlListView(cm)   lv.show()   return lv