Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph

quickop: use kbfiles/largefiles status to check if files have been modified

Changeset 2eab72bd970d

Parent 110b74bfa2a2

by David Golub

Changes to one file · Browse files at 2eab72bd970d Showing diff from parent 110b74bfa2a2 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
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
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
 # quickop.py - TortoiseHg's dialog for quick dirstate operations  #  # Copyright 2009 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  import sys    from mercurial import util    from tortoisehg.util import hglib, shlib  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import qtlib, status, cmdui, lfprompt    from PyQt4.QtCore import *  from PyQt4.QtGui import *    LABELS = { 'add': (_('Checkmark files to add'), _('Add')),   'forget': (_('Checkmark files to forget'), _('Forget')),   'revert': (_('Checkmark files to revert'), _('Revert')),   'remove': (_('Checkmark files to remove'), _('Remove')),}    ICONS = { 'add': 'fileadd',   'forget': 'hg-remove',   'revert': 'hg-revert',   'remove': 'hg-remove',}    class QuickOpDialog(QDialog):   """ Dialog for performing quick dirstate operations """   def __init__(self, repo, command, pats, parent):   QDialog.__init__(self, parent)   self.setWindowFlags(Qt.Window)   self.pats = pats   self.repo = repo   os.chdir(repo.root)     # Handle rm alias   if command == 'rm':   command = 'remove'   self.command = command     self.setWindowTitle(_('%s - hg %s') % (repo.displayname, command))   self.setWindowIcon(qtlib.geticon(ICONS[command]))     layout = QVBoxLayout()   layout.setMargin(0)   self.setLayout(layout)     toplayout = QVBoxLayout()   toplayout.setContentsMargins(5, 5, 5, 0)   layout.addLayout(toplayout)     hbox = QHBoxLayout()   lbl = QLabel(LABELS[command][0])   slbl = QLabel()   hbox.addWidget(lbl)   hbox.addStretch(1)   hbox.addWidget(slbl)   self.status_label = slbl   toplayout.addLayout(hbox)     types = { 'add' : 'I?',   'forget' : 'MAR!C',   'revert' : 'MAR!',   'remove' : 'MAR!CI?',   }   filetypes = types[self.command]     opts = {}   for s, val in status.statusTypes.iteritems():   opts[val.name] = s in filetypes     opts['checkall'] = True # pre-check all matching files   stwidget = status.StatusWidget(repo, pats, opts, self)   toplayout.addWidget(stwidget, 1)     hbox = QHBoxLayout()   if self.command == 'revert':   ## no backup checkbox   chk = QCheckBox(_('Do not save backup files (*.orig)'))   elif self.command == 'remove':   ## force checkbox   chk = QCheckBox(_('Force removal of modified files (--force)'))   else:   chk = None   if chk:   self.chk = chk   hbox.addWidget(chk)     self.statusbar = cmdui.ThgStatusBar(self)   stwidget.showMessage.connect(self.statusbar.showMessage)     self.cmd = cmd = cmdui.Runner(True, self)   cmd.commandStarted.connect(self.commandStarted)   cmd.commandFinished.connect(self.commandFinished)   cmd.progress.connect(self.statusbar.progress)     BB = QDialogButtonBox   bb = QDialogButtonBox(BB.Ok|BB.Close)   bb.accepted.connect(self.accept)   bb.rejected.connect(self.reject)   bb.button(BB.Ok).setDefault(True)   bb.button(BB.Ok).setText(LABELS[command][1])   hbox.addStretch()   hbox.addWidget(bb)   toplayout.addLayout(hbox)   self.bb = bb     if self.command == 'add':   if 'largefiles' in self.repo.extensions():   self.addLfilesButton = QPushButton(_('Add &Largefiles'))   elif 'kbfiles' in self.repo.extensions():   self.addLfilesButton = QPushButton(_("Add &Bfiles"))   else:   self.addLfilesButton = None   if self.addLfilesButton:   self.addLfilesButton.clicked.connect(self.addLfiles)   bb.addButton(self.addLfilesButton, BB.ActionRole)     layout.addWidget(self.statusbar)     s = QSettings()   stwidget.loadSettings(s, 'quickop')   self.restoreGeometry(s.value('quickop/geom').toByteArray())   if hasattr(self, 'chk'):   if self.command == 'revert':   self.chk.setChecked(s.value('quickop/nobackup', True).toBool())   elif self.command == 'remove':   self.chk.setChecked(s.value('quickop/forceremove', False).toBool())   self.stwidget = stwidget   self.stwidget.refreshWctx()   QShortcut(QKeySequence('Ctrl+Return'), self, self.accept)   QShortcut(QKeySequence('Ctrl+Enter'), self, self.accept)   QShortcut(QKeySequence.Refresh, self, self.stwidget.refreshWctx)   QShortcut(QKeySequence('Escape'), self, self.reject)     def commandStarted(self):   self.bb.button(QDialogButtonBox.Ok).setEnabled(False)     def commandFinished(self, ret):   self.bb.button(QDialogButtonBox.Ok).setEnabled(True)   if ret == 0:   shlib.shell_notify(self.files)   self.reject()     def accept(self):   cmdline = [self.command]   if hasattr(self, 'chk') and self.chk.isChecked():   if self.command == 'revert':   cmdline.append('--no-backup')   elif self.command == 'remove':   cmdline.append('--force')   files = self.stwidget.getChecked()   if not files:   qtlib.WarningMsgBox(_('No files selected'),   _('No operation to perform'),   parent=self)   return + self.repo.bfstatus = True + self.repo.lfstatus = True + repostate = self.repo.status() + self.repo.bfstatus = False + self.repo.lfstatus = False   if self.command == 'remove':   if not self.chk.isChecked(): - modified = self.repo.status()[0] + modified = repostate[0]   selmodified = []   for wfile in files:   if wfile in modified:   selmodified.append(wfile)   if selmodified:   prompt = qtlib.CustomPrompt(_('Confirm Remove'),   _('You have selected one or more files that have been '   'modified. By default, these files will not be '   'removed. What would you like to do?'), self,   (_('Remove &Unmodified Files'),   _('Remove &All Selected Files'), _('Cancel')),   0, 2, selmodified)   ret = prompt.run()   if ret == 1:   cmdline.append('--force')   elif ret == 2:   return - self.repo.bfstatus = True - self.repo.lfstatus = True - repostate = self.repo.status() - self.repo.bfstatus = False - self.repo.lfstatus = False   unknown, ignored = repostate[4:6]   for wfile in files:   if wfile in unknown or wfile in ignored:   try:   util.unlink(wfile)   except EnvironmentError:   pass   files.remove(wfile)   elif self.command == 'add':   if 'largefiles' in self.repo.extensions() or 'kbfiles' in self.repo.extensions():   self.addWithPrompt(files)   return   if files:   cmdline.extend(files)   self.files = files   self.cmd.run(cmdline)   else:   self.reject()     def reject(self):   if self.cmd.core.running():   self.cmd.core.cancel()   elif not self.stwidget.canExit():   return   else:   s = QSettings()   self.stwidget.saveSettings(s, 'quickop')   s.setValue('quickop/geom', self.saveGeometry())   if hasattr(self, 'chk'):   if self.command == 'revert':   s.setValue('quickop/nobackup', self.chk.isChecked())   elif self.command == 'remove':   s.setValue('quickop/forceremove', self.chk.isChecked())   QDialog.reject(self)     def addLfiles(self):   if 'kbfiles' in self.repo.extensions():   cmdline = ['add', '--bf']   else:   cmdline = ['add', '--large']   files = self.stwidget.getChecked()   if not files:   qtlib.WarningMsgBox(_('No files selected'),   _('No operation to perform'),   parent=self)   return   cmdline.extend(files)   self.files = files   self.cmd.run(cmdline)     def addWithPrompt(self, files):   result = lfprompt.promptForLfiles(self, self.repo.ui, self.repo, files,   'kbfiles' in self.repo.extensions())   if not result:   return   files, bfiles = result   if files:   cmdline = ['add']   cmdline.extend(files)   self.files = files   self.cmd.run(cmdline)   if bfiles:   if 'kbfiles' in self.repo.extensions():   cmdline = ['add', '--bf']   else:   cmdline = ['add', '--large']   cmdline.extend(bfiles)   self.files = bfiles   self.cmd.run(cmdline)    instance = None  class HeadlessQuickop(QWidget):   def __init__(self, repo, cmdline):   QWidget.__init__(self)   self.files = cmdline[1:]   os.chdir(repo.root)   self.cmd = cmdui.Runner(True, self)   self.cmd.commandFinished.connect(self.commandFinished)   self.cmd.run(cmdline)   self.hide()     def commandFinished(self, ret):   if ret == 0:   shlib.shell_notify(self.files)   sys.exit(0)    def run(ui, *pats, **opts):   pats = hglib.canonpaths(pats)   if opts.get('canonpats'):   pats = list(pats) + opts['canonpats']     from tortoisehg.util import paths   from tortoisehg.hgqt import thgrepo   repo = thgrepo.repository(ui, path=paths.find_root())     command = opts['alias']   imm = repo.ui.config('tortoisehg', 'immediate', '')   if command in imm.lower():   cmdline = [command] + pats   global instance   instance = HeadlessQuickop(repo, cmdline)   return None   else:   return QuickOpDialog(repo, command, pats, None)