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

shelve: deleting chunks from patches mostly works

Currently no way to delete a file when it has no chunks, after asking for its
header to be kept. And the context menu in general for the file list is mostly
innapropriate. The same is true of revdetails in the workbench when displaying
the working directory or an unapplied patch.

Changeset ba3bbb597b04

Parent 14e176304db2

by Steve Borho

Changes to 3 files · Browse files at ba3bbb597b04 Showing diff from parent 14e176304db2 Diff from another changeset...

 
110
111
112
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
115
116
 
148
149
150
151
 
 
 
152
153
154
 
351
352
353
354
 
355
356
357
 
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
 
168
169
170
 
171
172
173
174
175
176
 
373
374
375
 
376
377
378
379
@@ -110,7 +110,27 @@
  revertall = True   ctx = self.filelistmodel._ctx   if isinstance(ctx, patchctx): - raise 'unimplemented' + try: + fp = util.atomictempfile(ctx._path, 'wb') + if ctx._ph.comments: + fp.write('\n'.join(ctx._ph.comments)) + fp.write('\n\n') + for wfile in ctx._fileorder: + if wfile == self.currentFile: + if revertall: + continue + chunks[0].write(fp) + for chunk in kchunks: + chunk.write(fp) + if not chunks[-1].selected: + fp.write('\n') + else: + for chunk in ctx._files[wfile]: + chunk.write(fp) + fp.rename() + finally: + del fp + self.fileModified.emit()   else:   path = repo.wjoin(self.currentFile)   if not os.path.exists(path): @@ -148,7 +168,9 @@
  def displayFile(self, file, rev, status):   if file:   self.currentFile = file - self.mtime = os.path.getmtime(self.repo.wjoin(file)) + path = self.repo.wjoin(file) + if os.path.exists(path): + self.mtime = os.path.getmtime(path)   self.diffbrowse.displayFile(file, status)   self.fileSelected.emit(True)   else: @@ -351,7 +373,7 @@
  chunks = self._ctx._files[filename]   else:   buf = cStringIO.StringIO() - buf.write('diff -r XX %s\n' % filename) + buf.write('diff -r aaaaaaaaaaaa -r bbbbbbbbbbb %s\n' % filename)   buf.write('\n'.join(fd.diff))   buf.seek(0)   chunks = record.parsepatch(buf)
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
226
227
228
229
230
231
232
233
234
235
236
237
238
 
 
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
 
258
259
 
260
261
262
 
 
 
 
 
 
 
263
264
265
266
267
 
 
 
 
 
 
 
 
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
 
259
260
 
261
262
 
 
263
264
265
266
267
268
269
270
 
 
 
 
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
 # shelve.py - TortoiseHg shelve and patch tool  #  # Copyright 2011 Steve Borho <steve@borho.org>  #  # This software may be used and distributed according to the terms  # of the GNU General Public License, incorporated herein by reference.    import os  import time    from tortoisehg.util import hglib  from tortoisehg.util.patchctx import patchctx  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import qtlib, cmdui, chunks    from PyQt4.QtCore import *  from PyQt4.QtGui import *    class ShelveDialog(QMainWindow):     finished = pyqtSignal(int)     wdir = _('Working Directory')     def __init__(self, repo):   QMainWindow.__init__(self)     self.repo = repo   self.shelves = []   self.patches = []     self.splitter = QSplitter(self)   self.splitter.setOrientation(Qt.Horizontal)   self.splitter.setChildrenCollapsible(False)   self.splitter.setObjectName('splitter')   self.setCentralWidget(self.splitter)     aframe = QFrame(self.splitter)   avbox = QVBoxLayout()   avbox.setSpacing(2)   avbox.setMargin(2)   avbox.setContentsMargins(2, 2, 2, 2)   aframe.setLayout(avbox)   ahbox = QHBoxLayout()   ahbox.setSpacing(2)   ahbox.setMargin(2)   ahbox.setContentsMargins(2, 2, 2, 2)   avbox.addLayout(ahbox)   self.comboa = QComboBox(self)   self.comboa.currentIndexChanged.connect(self.comboAChanged)   self.delShelfButtonA = QPushButton(_('Delete'))   self.delShelfButtonA.setToolTip(_('Delete the current shelf file'))   self.delShelfButtonA.clicked.connect(self.deleteShelfA)   ahbox.addWidget(self.comboa, 1)   ahbox.addWidget(self.delShelfButtonA)     self.browsea = chunks.ChunksWidget(repo, self)   self.browsea.splitter.splitterMoved.connect(self.linkSplitters)   self.browsea.linkActivated.connect(self.linkActivated)   self.browsea.showMessage.connect(self.showMessage)   avbox.addWidget(self.browsea)     bframe = QFrame(self.splitter)   bvbox = QVBoxLayout()   bvbox.setSpacing(2)   bvbox.setMargin(2)   bvbox.setContentsMargins(2, 2, 2, 2)   bframe.setLayout(bvbox)   bhbox = QHBoxLayout()   bhbox.setSpacing(2)   bhbox.setMargin(2)   bhbox.setContentsMargins(2, 2, 2, 2)   bvbox.addLayout(bhbox)   self.combob = QComboBox(self)   self.combob.currentIndexChanged.connect(self.comboBChanged)   self.delShelfButtonB = QPushButton(_('Delete'))   self.delShelfButtonB.setToolTip(_('Delete the current shelf file'))   self.delShelfButtonB.clicked.connect(self.deleteShelfB)   bhbox.addWidget(self.combob, 1)   bhbox.addWidget(self.delShelfButtonB)     self.browseb = chunks.ChunksWidget(repo, self)   self.browseb.splitter.splitterMoved.connect(self.linkSplitters)   self.browseb.linkActivated.connect(self.linkActivated)   self.browseb.showMessage.connect(self.showMessage)   bvbox.addWidget(self.browseb)     self.rbar = QToolBar(_('Refresh Toolbar'), objectName='rbar')   self.addToolBar(self.rbar)   self.refreshAction = a = QAction(_('Refresh'), self)   a.setIcon(qtlib.geticon('reload'))   a.setShortcut(QKeySequence.Refresh)   a.triggered.connect(self.refreshCombos)   self.rbar.addAction(self.refreshAction)   self.actionNew = a = QAction(_('New Shelf'), self)   a.setIcon(qtlib.geticon('document-new'))   a.triggered.connect(self.newShelf)   self.rbar.addAction(self.actionNew)     self.lefttbar = QToolBar(_('Left Toolbar'), objectName='lefttbar')   self.addToolBar(self.lefttbar)   self.deletea = a = QAction(_('Deleted selected chunks'), self)   self.deletea.triggered.connect(self.browsea.deleteSelectedChunks)   a.setIcon(qtlib.geticon('delfilesleft'))   self.lefttbar.addAction(self.deletea)   self.allright = a = QAction(_('Move all files right'), self)   a.setIcon(qtlib.geticon('media-seek-forward'))   self.lefttbar.addAction(self.allright)   self.fileright = a = QAction(_('Move selected file right'), self)   a.setIcon(qtlib.geticon('file2right'))   self.lefttbar.addAction(self.fileright)   self.editfilea = a = QAction(_('Edit file'), self)   a.setIcon(qtlib.geticon('edit-find'))   self.lefttbar.addAction(self.editfilea)   self.chunksright = a = QAction(_('Move selected chunks right'), self)   a.setIcon(qtlib.geticon('chunk2right'))   self.lefttbar.addAction(self.chunksright)     self.righttbar = QToolBar(_('Right Toolbar'), objectName='righttbar')   self.addToolBar(self.righttbar)   self.chunksleft = a = QAction(_('Move selected chunks left'), self)   a.setIcon(qtlib.geticon('chunk2left'))   self.righttbar.addAction(self.chunksleft)   self.editfileb = a = QAction(_('Edit file'), self)   a.setIcon(qtlib.geticon('edit-find'))   self.righttbar.addAction(self.editfileb)   self.fileleft = a = QAction(_('Move selected file left'), self)   a.setIcon(qtlib.geticon('file2left'))   self.righttbar.addAction(self.fileleft)   self.allleft = a = QAction(_('Move all files left'), self)   a.setIcon(qtlib.geticon('media-seek-backward'))   self.righttbar.addAction(self.allleft)   self.deleteb = a = QAction(_('Deleted selected chunks'), self)   self.deleteb.triggered.connect(self.browseb.deleteSelectedChunks)   a.setIcon(qtlib.geticon('delfilesright'))   self.righttbar.addAction(self.deleteb)     self.editfilea.triggered.connect(self.browsea.editCurrentFile)   self.editfileb.triggered.connect(self.browseb.editCurrentFile)     self.browsea.chunksSelected.connect(self.chunksright.setEnabled)   self.browsea.chunksSelected.connect(self.deletea.setEnabled)   self.browsea.fileSelected.connect(self.fileright.setEnabled)   self.browsea.fileSelected.connect(self.editfilea.setEnabled)   self.browsea.fileModified.connect(self.refreshCombos)   self.browseb.chunksSelected.connect(self.chunksleft.setEnabled)   self.browseb.chunksSelected.connect(self.deleteb.setEnabled)   self.browseb.fileSelected.connect(self.fileleft.setEnabled)   self.browseb.fileSelected.connect(self.editfileb.setEnabled)   self.browseb.fileModified.connect(self.refreshCombos)     self.statusbar = cmdui.ThgStatusBar(self)   self.setStatusBar(self.statusbar)     self.refreshCombos()   repo.repositoryChanged.connect(self.refreshCombos)     self.setWindowTitle(_('TortoiseHg Shelve - %s') % repo.displayname)   self.restoreSettings()     @pyqtSlot()   def newShelf(self):   dlg = QInputDialog(self, Qt.Sheet)   dlg.setWindowModality(Qt.WindowModal)   dlg.setWindowTitle(_('TortoiseHg New Shelf Name'))   dlg.setLabelText(_('Specify name of new shelf'))   dlg.setTextValue(time.strftime('%Y-%m-%d_%H-%M-%S'))   if not dlg.exec_():   return   shelve = hglib.fromunicode(dlg.textValue())   try:   fn = os.path.join('shelves', shelve)   if os.path.exists(self.repo.join(fn)):   qtlib.ErrorMsgBox(_('File already exists'),   _('A shelf file of that name already exists'))   return   self.repo.opener(fn, 'wb').write('')   self.showMessage(_('New shelf created'))   except EnvironmentError, e:   self.showMessage(hglib.tounicode(str(e)))   self.refreshCombos()     @pyqtSlot()   def deleteShelfA(self):   shelf = self.currentPatchA()   ushelf = hglib.tounicode(os.path.basename(shelf))   if not qtlib.QuestionMsgBox(_('Are you sure?'),   _('Delete shelf file %s?') % ushelf):   return   try:   os.unlink(shelf)   self.showMessage(_('Shelf deleted'))   except EnvironmentError, e:   self.showMessage(hglib.tounicode(str(e)))   self.refreshCombos()     @pyqtSlot()   def deleteShelfB(self):   shelf = self.currentPatchB()   ushelf = hglib.tounicode(os.path.basename(shelf))   if not qtlib.QuestionMsgBox(_('Are you sure?'),   _('Delete shelf file %s?') % ushelf):   return   try:   os.unlink(shelf)   self.showMessage(_('Shelf deleted'))   except EnvironmentError, e:   self.showMessage(hglib.tounicode(str(e)))   self.refreshCombos()     def currentPatchA(self):   idx = self.comboa.currentIndex()   if idx == -1:   return None   if idx == 0:   return self.wdir   idx -= 1   if idx < len(self.shelves):   return self.shelves[idx]   idx -= len(self.shelves)   if idx < len(self.patches):   return self.patches[idx]   return None     def currentPatchB(self):   idx = self.combob.currentIndex()   if idx == -1:   return None   if idx < len(self.shelves):   return self.shelves[idx]   idx -= len(self.shelves)   if idx < len(self.patches):   return self.patches[idx]   return None     @pyqtSlot()   def refreshCombos(self):   shelvea, shelveb = self.currentPatchA(), self.currentPatchB() + oldidxa = self.comboa.currentIndex() + oldidxb = self.comboa.currentIndex()     shelves = self.repo.thgshelves()   disp = [_('Shelf: %s') % hglib.tounicode(s) for s in shelves]     patches = self.repo.thgmqunappliedpatches   disp += [_('Patch: %s') % hglib.tounicode(p) for p in patches]     # store fully qualified paths   self.shelves = [os.path.join(self.repo.shelfdir, s) for s in shelves]   self.patches = [self.repo.mq.join(p) for p in patches]     self.comboa.clear()   self.combob.clear()   self.comboa.addItems([self.wdir] + disp)   self.combob.addItems(disp)     # attempt to restore selection   if shelvea == self.wdir: - self.comboa.setCurrentIndex(0) + idx = 0   elif shelvea in self.shelves: - self.comboa.setCurrentIndex(1 + self.shelves.index(shelvea)) + idx = self.shelves.index(shelvea) + 1   elif shelvea in self.patches: - self.comboa.setCurrentIndex(1 + len(self.shelves) + - self.patches.index(shelvea)) + idx = len(self.shelves) + self.patches.index(shelvea) + 1 + else: + idx = 0 + self.comboa.setCurrentIndex(idx) + if idx == oldidxa: + self.comboAChanged(idx) +   if shelveb in self.shelves: - self.combob.setCurrentIndex(self.shelves.index(shelveb)) - if shelveb in self.shelves: - self.combob.setCurrentIndex(len(self.shelves) + - self.patches.index(shelveb)) + idx = self.shelves.index(shelveb) + elif shelveb in self.patches: + idx = len(self.shelves) + self.patches.index(shelveb) + else: + idx = 0 + self.combob.setCurrentIndex(idx) + if idx == oldidxb: + self.comboBChanged(idx)   if not patches and not shelves:   self.delShelfButtonB.setEnabled(False)   self.browseb.setContext(patchctx('', self.repo, None))     @pyqtSlot(int)   def comboAChanged(self, index):   if index == 0:   rev = None   self.delShelfButtonA.setEnabled(False)   else:   rev = self.currentPatchA()   self.delShelfButtonA.setEnabled(index <= len(self.shelves))   self.browsea.setContext(self.repo.changectx(rev))     @pyqtSlot(int)   def comboBChanged(self, index):   rev = self.currentPatchB()   self.delShelfButtonB.setEnabled(index < len(self.shelves))   self.browseb.setContext(self.repo.changectx(rev))     @pyqtSlot(int, int)   def linkSplitters(self, pos, index):   if self.browsea.splitter.sizes()[0] != pos:   self.browsea.splitter.moveSplitter(pos, index)   if self.browseb.splitter.sizes()[0] != pos:   self.browseb.splitter.moveSplitter(pos, index)     @pyqtSlot(QString)   def linkActivated(self, linktext):   pass     @pyqtSlot(QString)   def showMessage(self, message):   self.statusbar.showMessage(message)     def storeSettings(self):   s = QSettings()   wb = "shelve/"   s.setValue(wb + 'geometry', self.saveGeometry())   s.setValue(wb + 'windowState', self.saveState())   s.setValue(wb + 'filesplitter', self.browsea.splitter.saveState())     def restoreSettings(self):   s = QSettings()   wb = "shelve/"   self.restoreGeometry(s.value(wb + 'geometry').toByteArray())   self.restoreState(s.value(wb + 'windowState').toByteArray())   self.browsea.splitter.restoreState(   s.value(wb + 'filesplitter').toByteArray())   self.browseb.splitter.restoreState(   s.value(wb + 'filesplitter').toByteArray())     def safeToExit(self):   return True     def closeEvent(self, event):   if not self.safeToExit():   event.ignore()   else:   self.storeSettings()   # mimic QDialog exit   self.finished.emit(0)    def run(ui, *pats, **opts):   from tortoisehg.util import paths   from tortoisehg.hgqt import thgrepo   repo = thgrepo.repository(ui, path=paths.find_root())   return ShelveDialog(repo)
 
32
33
34
 
35
36
37
 
166
167
168
 
169
170
171
 
32
33
34
35
36
37
38
 
167
168
169
170
171
172
173
@@ -32,6 +32,7 @@
  self._repo = repo   self._rev = rev   self._status = [[], [], []] + self._fileorder = []   self._user = ''   self._date = ''   self._desc = '' @@ -166,6 +167,7 @@
  if path not in files:   self._status[type].append(path)   files[path] = [chunk] + self._fileorder.append(path)   else:   files[path].append(chunk)   except patch.PatchError: