Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1, 2.1.1, and 2.1.2

Merge with stable

Changeset aff0628998c0

Parents a9a715092aff

Parents e724702efd06

by Steve Borho

Changes to 3 files · Browse files at aff0628998c0 Showing diff from parent a9a715092aff e724702efd06 Diff from another changeset...

 
445
446
447
 
 
 
 
 
 
 
 
 
 
448
449
450
451
 
452
453
454
 
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
 
461
462
463
464
@@ -445,10 +445,20 @@
  'Patch has been renamed, issue qrename'   if self.cmd.running():   return + from tortoisehg.hgqt import qrename + newpatchname = hglib.fromunicode(item.text()) + if newpatchname == item._thgpatch: + return + else: + res = qrename.checkPatchname(self.repo.root, + self.repo.thgactivemqname, newpatchname, self) + if not res: + item.setText(item._thgpatch) + return   self.repo.incrementBusyCount()   self.qtbar.setEnabled(False)   self.cmd.run(['qrename', '-R', self.repo.root, '--', - item._thgpatch, hglib.fromunicode(item.text())]) + item._thgpatch, newpatchname])     @pyqtSlot(int)   def onPatchSelected(self, row):
 
13
14
15
16
 
17
18
19
 
56
57
58
 
 
 
 
59
60
61
62
63
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
14
15
 
16
17
18
19
 
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
@@ -13,7 +13,7 @@
   from tortoisehg.util import hglib  from tortoisehg.hgqt.i18n import _ -from tortoisehg.hgqt import cmdui +from tortoisehg.hgqt import cmdui, qtlib    class QRenameDialog(QDialog):   @@ -56,9 +56,113 @@
  def accept(self):   self.newpatchname = hglib.fromunicode(self.le.text())   if self.newpatchname != self.oldpatchname: + res = checkPatchname(self.repo.root, self.repo.thgactivemqname, + self.newpatchname, self) + if not res: + return   cmdline = ['qrename', '--repository', self.repo.root, '--',   self.oldpatchname, self.newpatchname]   self.cmd.run(cmdline)   else:   self.close()   +def checkPatchname(reporoot, activequeue, newpatchname, parent): + if activequeue == 'patches': + pn = 'patches' + else: + pn = 'patches-%s' % activequeue + patchfile = os.sep.join([reporoot, ".hg", pn, newpatchname]) + if os.path.exists(patchfile): + dlg = CheckPatchnameDialog(newpatchname, parent) + choice = dlg.exec_() + if choice == 1: + # add .OLD to existing patchfile + try: + os.rename(patchfile, patchfile + '.OLD') + except (OSError, IOError), inst: + qtlib.ErrorMsgBox(self.errTitle, + _('Could not rename existing patchfile'), + hglib.tounicode(str(inst))) + return False + return True + elif choice == 2: + # overwite existing patchfile + try: + os.remove(patchfile) + except (OSError, IOError), inst: + qtlib.ErrorMsgBox(self.errTitle, + _('Could not delete existing patchfile'), + hglib.tounicode(str(inst))) + return False + return True + elif choice == 3: + # go back and change the new name + return False + else: + return False + else: + return True + +class CheckPatchnameDialog(QDialog): + + def __init__(self, patchname, parent): + super(CheckPatchnameDialog, self).__init__(parent) + self.setWindowTitle(_('QRename - Check patchname')) + + f = self.windowFlags() + self.setWindowFlags(f & ~Qt.WindowContextHelpButtonHint) + self.patchname = patchname + + self.vbox = QVBoxLayout() + self.vbox.setSpacing(4) + + lbl = QLabel(_('Patch name <b>%s</b> already exists:') + % (self.patchname)) + self.vbox.addWidget(lbl) + + self.extensionradio = \ + QRadioButton(_('Add .OLD extension to existing patchfile')) + self.vbox.addWidget(self.extensionradio) + self.overwriteradio = QRadioButton(_('Overwrite existing patchfile')) + self.vbox.addWidget(self.overwriteradio) + self.backradio = QRadioButton(_('Go back and change new patchname')) + self.vbox.addWidget(self.backradio) + + self.extensionradio.toggled.connect(self.onExtensionRadioChecked) + self.overwriteradio.toggled.connect(self.onOverwriteRadioChecked) + self.backradio.toggled.connect(self.onBackRadioChecked) + + self.choice = 0 + self.extensionradio.setChecked(True) + self.extensionradio.setFocus() + + self.setLayout(self.vbox) + + BB = QDialogButtonBox + bbox = QDialogButtonBox(BB.Ok|BB.Cancel) + bbox.accepted.connect(self.accept) + bbox.rejected.connect(self.reject) + self.layout().addWidget(bbox) + self.bbox = bbox + + @pyqtSlot() + def onExtensionRadioChecked(self): + if self.extensionradio.isChecked(): + self.choice = 1 + + @pyqtSlot() + def onOverwriteRadioChecked(self): + if self.overwriteradio.isChecked(): + self.choice = 2 + + @pyqtSlot() + def onBackRadioChecked(self): + if self.backradio.isChecked(): + self.choice = 3 + + def accept(self): + self.done(self.choice) + self.close() + + def reject(self): + self.done(0)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
 
 
 
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
 
 
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
 # qreorder.py - reorder unapplied MQ patches  #  # 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 os    from hgext import mq    from tortoisehg.hgqt import qtlib, thgrepo, qrename  from tortoisehg.util import hglib, paths  from tortoisehg.hgqt.i18n import _    from PyQt4.QtCore import *  from PyQt4.QtGui import *    # TODO:  # This approach will nuke any user configured guards  # Explicit refresh    class QReorderDialog(QDialog):   def __init__(self, repo, parent=None):   QDialog.__init__(self, parent)     self.setWindowTitle(_('Reorder Unapplied Patches'))   self.setWindowFlags(Qt.Window)   self.setWindowIcon(qtlib.geticon('hg-qreorder'))     self.repo = repo   self.cached = None   repo.repositoryChanged.connect(self.refresh)     layout = QVBoxLayout()   layout.setMargin(4)   self.setLayout(layout)     hb = QHBoxLayout()   hb.setMargin(2)   lbl = QLabel(_('Repository:'))   hb.addWidget(lbl)   le = QLineEdit()   hb.addWidget(le)   le.setReadOnly(True)   le.setFont(qtlib.getfont('fontlist').font())   le.setText(repo.displayname)   le.setFocusPolicy(Qt.NoFocus)   layout.addLayout(hb)   hl = qtlib.LabeledSeparator('')   layout.addWidget(hl)     class PatchListWidget(QListWidget):   menuRequested = pyqtSignal(QPoint, object)   def __init__(self, parent):   QListWidget.__init__(self, parent)   self.setCurrentRow(0)   def contextMenuEvent(self, event): - self.menuRequested.emit(event.globalPos(), - self.item(self.currentRow()).patchname) + i = self.item(self.currentRow()) + if i: + self.menuRequested.emit(event.globalPos(), i.patchname)   def focusInEvent(self, e):   i = self.item(self.currentRow())   if i:   self.parent().parent().showSummary(i)   QListWidget.focusInEvent(self, e)     ugb = QGroupBox(_('Unapplied Patches - drag to reorder'))   ugb.setLayout(QVBoxLayout())   ugb.layout().setContentsMargins(*(0,)*4)   self.ulw = PatchListWidget(self)   self.ulw.setDragDropMode(QListView.InternalMove)   ugb.layout().addWidget(self.ulw)   self.ulw.currentItemChanged.connect(lambda:   self.showSummary(self.ulw.item(self.ulw.currentRow())))   self.ulw.menuRequested.connect(self.patchlistMenuRequest)   layout.addWidget(ugb)     agb = QGroupBox(_('Applied Patches'))   agb.setLayout(QVBoxLayout())   agb.layout().setContentsMargins(*(0,)*4)   self.alw = PatchListWidget(self)   agb.layout().addWidget(self.alw)   self.alw.currentItemChanged.connect(lambda:   self.showSummary(self.alw.item(self.alw.currentRow())))   self.alw.menuRequested.connect(self.patchlistMenuRequest)   layout.addWidget(agb)     slbl = QLabel(_('Summary:'))   layout.addWidget(slbl)   self.summ = QTextEdit()   self.summ.setFont(qtlib.getfont('fontcomment').font())   self.summ.setMinimumWidth(500) # min 80 chars   self.summ.setMaximumHeight(100)   self.summ.setReadOnly(True)   self.summ.setFocusPolicy(Qt.NoFocus)   layout.addWidget(self.summ)     self._readsettings()     self.refresh()     # dialog buttons   BB = QDialogButtonBox   bb = QDialogButtonBox(BB.Ok|BB.Cancel)   self.apply_button = bb.button(BB.Apply)   bb.accepted.connect(self.accept)   bb.rejected.connect(self.reject)   bb.button(BB.Ok).setDefault(True)   layout.addWidget(bb)     self.alw.setCurrentRow(0)   self.ulw.setCurrentRow(0)   self.ulw.setFocus()     def patchlistMenuRequest(self, point, selection):   self.menuselection = selection   menu = QMenu(self)   act = QAction(_('Rename patch'), self)   act.triggered.connect(self.qrenamePatch)   menu.addAction(act)   menu.exec_(point)     def qrenamePatch(self):   patchname = self.menuselection   dlg = qrename.QRenameDialog(self.repo, patchname, self)   dlg.finished.connect(dlg.deleteLater) - dlg.output.connect(self.parent().output) - dlg.makeLogVisible.connect(self.parent().makeLogVisible) + if self.parent(): + dlg.output.connect(self.parent().output) + dlg.makeLogVisible.connect(self.parent().makeLogVisible)   dlg.exec_()     def refresh(self):   patchnames = self.repo.mq.series[:]   applied = [p.name for p in self.repo.mq.applied]   if (patchnames, applied) == self.cached:   return     alw, ulw = self.alw, self.ulw   if self.cached:   if applied != self.cached[1]:   cw = alw   else:   cw = ulw   else:   cw = ulw   ar = alw.currentRow()   ur = ulw.currentRow()   ulw.clear()   alw.clear()   for p in reversed(patchnames):   ctx = self.repo.changectx(p)   desc = ctx.longsummary()   item = QListWidgetItem('[%s]\t%s' % (hglib.tounicode(p), desc))   # Save the patchname with the item so that we can easily   # retrieve it later   item.patchname = p     if p in applied:   item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)   item.setForeground(QColor(111,111,111)) # gray, like disabled   alw.addItem(item)   else:   item.setFlags(Qt.ItemIsSelectable |   Qt.ItemIsEnabled |   Qt.ItemIsDragEnabled)   ulw.addItem(item)   self.cached = patchnames, applied   if cw == ulw:   alw.setCurrentRow(ar)   ulw.setCurrentRow(ur)   self.ulw.setFocus()   else:   ulw.setCurrentRow(ur)   alw.setCurrentRow(ar)   self.alw.setFocus()     def showSummary(self, item):   if item is None:   self.summ.clear()   else:   ctx = self.repo.changectx(item.patchname)   self.summ.setText(hglib.tounicode(ctx.description()))     def accept(self):   self._writesettings()   try:   self.repo.incrementBusyCount()   lines = []   for i in xrange(self.alw.count()-1, -1, -1):   item = self.alw.item(i)   lines.append(item.patchname)   for i in xrange(self.ulw.count()-1, -1, -1):   item = self.ulw.item(i)   lines.append(item.patchname)   if lines:   fp = self.repo.mq.opener('series', 'wb')   fp.write('\n'.join(lines))   fp.close()   finally:   self.repo.decrementBusyCount()   QDialog.accept(self)     def reject(self):   QDialog.reject(self)     def closeEvent(self, event):   self._writesettings()   super(QReorderDialog, self).closeEvent(event)     def _readsettings(self):   s = QSettings()   self.restoreGeometry(s.value('qreorder/geom').toByteArray())     def _writesettings(self):   s = QSettings()   s.setValue('qreorder/geom', self.saveGeometry())    def run(ui, *pats, **opts):   repo = thgrepo.repository(None, paths.find_root())   if hasattr(repo, 'mq'):   return QReorderDialog(repo)   else:   qtlib.ErrorMsgBox(_('TortoiseHg Error'),   _('Please enable the MQ extension first.'))