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

stable update, thgstrip, branchop: show sorted branch names (closes #103)

Changeset d3c9339974df

Parent cc866f2fcafa

by Steve Borho

Changes to 3 files · Browse files at d3c9339974df Showing diff from parent cc866f2fcafa Diff from another changeset...

 
43
44
45
46
47
 
 
 
 
48
49
 
50
 
51
52
53
 
43
44
45
 
 
46
47
48
49
50
 
51
52
53
54
55
56
@@ -43,11 +43,14 @@
  closebranch = QRadioButton(_('Close current branch'))   branchCombo = QComboBox()   branchCombo.setEditable(True) - for name in hglib.getlivebranch(repo): - if name == wctx.branch(): + + wbu = hglib.tounicode(wctx.branch()) + for name in repo.livebranches: + if name == wbu:   continue - branchCombo.addItem(hglib.tounicode(name)) + branchCombo.addItem(name)   branchCombo.activated.connect(self.accept) +   grid.addWidget(nochange, 0, 0)   grid.addWidget(newbranch, 1, 0)   grid.addWidget(branchCombo, 1, 1)
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
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
 # thgstrip.py - MQ strip dialog for TortoiseHg  #  # Copyright 2009 Yuki KODAMA <endflow.net@gmail.com>  # Copyright 2010 David Wilhelm <dave@jumbledpile.com>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2, incorporated herein by reference.    from PyQt4.QtCore import *  from PyQt4.QtGui import *    from mercurial import hg, ui, error    from tortoisehg.util import hglib, paths  from tortoisehg.hgqt.i18n import _  from tortoisehg.hgqt import cmdui, cslist, qtlib, thgrepo    class StripDialog(QDialog):   """Dialog to strip changesets"""     def __init__(self, repo=None, rev=None, parent=None, opts={}):   super(StripDialog, self).__init__(parent)   self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)     self.setWindowIcon(qtlib.geticon('menudelete'))     self.ui = ui.ui()   if repo:   self.repo = repo   else:   root = paths.find_root()   if root:   self.repo = thgrepo.repository(self.ui, path=root)   else:   raise 'not repository'     # base layout box   box = QVBoxLayout()   box.setSpacing(6)     ## main layout grid   self.grid = grid = QGridLayout()   grid.setSpacing(6)   box.addLayout(grid)     ### target revision combo   self.rev_combo = combo = QComboBox()   combo.setEditable(True)   grid.addWidget(QLabel(_('Strip:')), 0, 0)   grid.addWidget(combo, 0, 1)   grid.addWidget(QLabel(_('Preview:')), 1, 0, Qt.AlignLeft | Qt.AlignTop)   self.status = QLabel("")   grid.addWidget(self.status, 1, 1, Qt.AlignLeft | Qt.AlignTop)     if rev is None:   rev = self.repo.dirstate.branch()   else:   rev = str(rev)   combo.addItem(hglib.tounicode(rev))   combo.setCurrentIndex(0) - for name in hglib.getlivebranch(self.repo): - combo.addItem(hglib.tounicode(name)) + for name in self.repo.livebranches: + combo.addItem(name)     tags = list(self.repo.tags())   tags.sort()   tags.reverse()   for tag in tags:   combo.addItem(hglib.tounicode(tag))     ### preview box, contained in scroll area, contains preview grid   self.cslist = cslist.ChangesetList()   self.cslistrow = cslistrow = 2   self.cslistcol = cslistcol = 1   grid.addWidget(self.cslist, cslistrow, cslistcol,   Qt.AlignLeft | Qt.AlignTop)     ### options   optbox = QVBoxLayout()   optbox.setSpacing(6)   expander = qtlib.ExpanderLabel(_('Options:'), False)   expander.expanded.connect(self.show_options)   grid.addWidget(expander, 3, 0, Qt.AlignLeft | Qt.AlignTop)   grid.addLayout(optbox, 3, 1)     self.discard_chk = QCheckBox(_('Discard local changes, no backup (-f/--force)'))   self.nobackup_chk = QCheckBox(_('No backup (-n/--nobackup)'))   optbox.addWidget(self.discard_chk)   optbox.addWidget(self.nobackup_chk)     self.discard_chk.setChecked(bool(opts.get('force')))   self.nobackup_chk.setChecked(bool(opts.get('nobackup')))     ## command widget   self.cmd = cmdui.Widget(True, True, self)   self.cmd.commandStarted.connect(self.command_started)   self.cmd.commandFinished.connect(self.command_finished)   self.cmd.commandCanceling.connect(self.command_canceling)   box.addWidget(self.cmd)     ## bottom buttons   buttons = QDialogButtonBox()   self.cancel_btn = buttons.addButton(QDialogButtonBox.Cancel)   self.cancel_btn.clicked.connect(self.cancel_clicked)   self.close_btn = buttons.addButton(QDialogButtonBox.Close)   self.close_btn.clicked.connect(self.reject)   self.close_btn.setAutoDefault(False)   self.strip_btn = buttons.addButton(_('&Strip'),   QDialogButtonBox.ActionRole)   self.strip_btn.clicked.connect(self.strip)   self.detail_btn = buttons.addButton(_('Detail'),   QDialogButtonBox.ResetRole)   self.detail_btn.setAutoDefault(False)   self.detail_btn.setCheckable(True)   self.detail_btn.toggled.connect(self.detail_toggled)   grid.setRowStretch(cslistrow, 1)   grid.setColumnStretch(cslistcol, 1)   box.addWidget(buttons)     # signal handlers   self.rev_combo.editTextChanged.connect(lambda *a: self.preview())   self.rev_combo.lineEdit().returnPressed.connect(self.strip)   self.discard_chk.toggled.connect(lambda *a: self.preview())     # dialog setting   self.setLayout(box)   self.layout().setSizeConstraint(QLayout.SetMinAndMaxSize)   self.setWindowTitle(_('Strip - %s') % self.repo.displayname)   #self.setWindowIcon(qtlib.geticon('strip'))     # prepare to show   self.rev_combo.lineEdit().selectAll()   self.cslist.setHidden(False)   self.cmd.setHidden(True)   self.cancel_btn.setHidden(True)   self.detail_btn.setHidden(True)   self.nobackup_chk.setHidden(True)   self.preview()     ### Private Methods ###     def resizeEvent(self, event):   w = self.grid.cellRect(self.cslistrow, self.cslistcol).width()   h = self.grid.cellRect(self.cslistrow, self.cslistcol).height()   self.cslist.resize(w, h)     def get_rev(self):   """Return the integer revision number of the input or None"""   revstr = hglib.fromunicode(self.rev_combo.currentText())   if not revstr:   return None   try:   rev = self.repo[revstr].rev()   except (error.RepoError, error.LookupError):   return None   return rev     def updatecslist(self, uselimit=True):   """Update the cs list and return the success status as a bool"""   rev = self.get_rev()   if not rev:   return False   striprevs = list(self.repo.changelog.descendants(rev))   striprevs.append(rev)   striprevs.sort()   self.cslist.clear()   self.cslist.update(self.repo, striprevs)   return True     def preview(self):   if self.updatecslist():   striprevs = self.cslist.curitems   cstext = qtlib.markup(_("%s changesets") % len(striprevs),   weight='bold')   self.status.setText(_("%s will be stripped") % cstext)   self.strip_btn.setEnabled(True)   else:   self.cslist.clear()   self.cslist.updatestatus()   cstext = qtlib.markup(_('Unknown revision!'), fg='red',   weight='bold')   self.status.setText(cstext)   self.strip_btn.setDisabled(True)     def strip(self):   cmdline = ['strip', '--repository', self.repo.root, '--verbose']   rev = hglib.fromunicode(self.rev_combo.currentText())   if not rev:   return   cmdline.append(rev)     if self.discard_chk.isChecked():   cmdline.append('--force')   else:   try:   node = self.repo[rev]   except (error.LookupError, error.RepoLookupError, error.RepoError):   return   def isclean():   """return whether WD is changed"""   wc = self.repo[None]   return not (wc.modified() or wc.added() or wc.removed())   if not isclean():   main = _("Detected uncommitted local changes.")   text = _("Do you want to discard them and continue?")   labels = ((QMessageBox.Yes, _('&Yes (--force)')),   (QMessageBox.No, _('&No')))   if qtlib.QuestionMsgBox(_('Confirm Strip'), main, text,   labels=labels, parent=self):   cmdline.append('--force')   else:   return     # backup options   if self.nobackup_chk.isChecked():   cmdline.append('--nobackup')     # start the strip   self.repo.incrementBusyCount()   self.cmd.run(cmdline)     ### Signal Handlers ###     def cancel_clicked(self):   self.cmd.cancel()   self.reject()     def detail_toggled(self, checked):   self.cmd.setShowOutput(checked)     def show_options(self, visible):   self.nobackup_chk.setShown(visible)     def command_started(self):   self.cmd.setShown(True)   self.strip_btn.setHidden(True)   self.close_btn.setHidden(True)   self.cancel_btn.setShown(True)   self.detail_btn.setShown(True)     def command_finished(self, ret):   self.repo.decrementBusyCount()   if ret is not 0 or self.cmd.outputShown():   self.detail_btn.setChecked(True)   self.close_btn.setShown(True)   self.close_btn.setAutoDefault(True)   self.close_btn.setFocus()   self.cancel_btn.setHidden(True)   else:   self.accept()     def command_canceling(self):   self.cancel_btn.setDisabled(True)    def run(ui, *pats, **opts):   rev = None   if opts.get('rev'):   rev = opts.get('rev')   elif len(pats) == 1:   rev = pats[0]   return StripDialog(rev=rev, opts=opts)
 
51
52
53
54
55
 
 
 
56
57
58
59
 
60
61
62
 
51
52
53
 
 
54
55
56
57
58
 
 
59
60
61
62
@@ -51,12 +51,12 @@
  rev = str(rev)   combo.addItem(hglib.tounicode(rev))   combo.setCurrentIndex(0) - for name in hglib.getlivebranch(self.repo): - combo.addItem(hglib.tounicode(name)) + + for name in repo.livebranches: + combo.addItem(name)     tags = list(self.repo.tags()) - tags.sort() - tags.reverse() + tags.sort(reverse=True)   for tag in tags:   combo.addItem(hglib.tounicode(tag))