Kiln » TortoiseHg » TortoiseHg
Clone URL:  
tag.py
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
# tag.py - Tag dialog for TortoiseHg # # Copyright 2010 Yuki KODAMA <endflow.net@gmail.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 tortoisehg.util import hglib from tortoisehg.hgqt.i18n import _ from tortoisehg.hgqt import qtlib, cmdui, i18n from PyQt4.QtCore import * from PyQt4.QtGui import * keep = i18n.keepgettext() class TagDialog(QDialog): showMessage = pyqtSignal(QString) output = pyqtSignal(QString, QString) makeLogVisible = pyqtSignal(bool) def __init__(self, repo, tag='', rev='tip', parent=None, opts={}): super(TagDialog, self).__init__(parent) self.setWindowFlags(self.windowFlags() & \ ~Qt.WindowContextHelpButtonHint) self.repo = repo self.setWindowTitle(_('Tag - %s') % repo.displayname) self.setWindowIcon(qtlib.geticon('hg-tag')) # base layout box base = QVBoxLayout() base.setSpacing(0) base.setContentsMargins(*(0,)*4) base.setSizeConstraint(QLayout.SetFixedSize) self.setLayout(base) # main layout box box = QVBoxLayout() box.setSpacing(8) box.setContentsMargins(*(8,)*4) self.layout().addLayout(box) form = QFormLayout(fieldGrowthPolicy=QFormLayout.AllNonFixedFieldsGrow) box.addLayout(form) ctx = repo[rev] form.addRow(_('Revision:'), QLabel('%d (%s)' % (ctx.rev(), ctx))) self.rev = ctx.rev() ### tag combo self.tagCombo = QComboBox() self.tagCombo.setEditable(True) self.tagCombo.setEditText(hglib.tounicode(tag)) self.tagCombo.currentIndexChanged.connect(self.updateStates) self.tagCombo.editTextChanged.connect(self.updateStates) form.addRow(_('Tag:'), self.tagCombo) self.tagRevLabel = QLabel('') form.addRow(_('Tagged:'), self.tagRevLabel) ### options expander = qtlib.ExpanderLabel(_('Options'), False) expander.expanded.connect(self.show_options) box.addWidget(expander) optbox = QVBoxLayout() optbox.setSpacing(6) box.addLayout(optbox) hbox = QHBoxLayout() hbox.setSpacing(0) optbox.addLayout(hbox) self.localCheckBox = QCheckBox(_('Local tag')) self.localCheckBox.toggled.connect(self.updateStates) self.replaceCheckBox = QCheckBox(_('Replace existing tag (-f/--force)')) self.replaceCheckBox.toggled.connect(self.updateStates) optbox.addWidget(self.localCheckBox) optbox.addWidget(self.replaceCheckBox) self.englishCheckBox = QCheckBox(_('Use English commit message')) engmsg = repo.ui.configbool('tortoisehg', 'engmsg', False) self.englishCheckBox.setChecked(engmsg) optbox.addWidget(self.englishCheckBox) self.customCheckBox = QCheckBox(_('Use custom commit message:')) self.customCheckBox.toggled.connect(self.customMessageToggle) self.customTextLineEdit = QLineEdit() optbox.addWidget(self.customCheckBox) optbox.addWidget(self.customTextLineEdit) ## bottom buttons BB = QDialogButtonBox bbox = QDialogButtonBox(BB.Close) bbox.rejected.connect(self.reject) self.addBtn = bbox.addButton(_('&Add'), BB.ActionRole) self.removeBtn = bbox.addButton(_('&Remove'), BB.ActionRole) box.addWidget(bbox) self.addBtn.clicked.connect(self.onAddTag) self.removeBtn.clicked.connect(self.onRemoveTag) ## horizontal separator self.sep = QFrame() self.sep.setFrameShadow(QFrame.Sunken) self.sep.setFrameShape(QFrame.HLine) base.addWidget(self.sep) ## status line self.status = qtlib.StatusLabel() self.status.setContentsMargins(4, 2, 4, 4) base.addWidget(self.status) self.cmd = cmdui.Runner(False, self) self.cmd.output.connect(self.output) self.cmd.makeLogVisible.connect(self.makeLogVisible) self.cmd.commandFinished.connect(self.onCommandFinished) repo.repositoryChanged.connect(self.refresh) self.customTextLineEdit.setDisabled(True) self.replaceCheckBox.setChecked(bool(opts.get('force'))) self.localCheckBox.setChecked(bool(opts.get('local'))) if not opts.get('local') and opts.get('message'): msg = hglib.tounicode(opts['message']) self.customCheckBox.setChecked(True) self.customTextLineEdit.setText(msg) self.clear_statue() self.show_options(False) self.tagCombo.setFocus() self.refresh() @pyqtSlot() def refresh(self): """ update display on dialog with recent repo data """ cur = self.tagCombo.currentText() tags = list(self.repo.tags()) tags.sort(reverse=True) self.tagCombo.clear() for tag in tags: if tag in ('tip', 'qbase', 'qtip', 'qparent'): continue self.tagCombo.addItem(hglib.tounicode(tag)) if cur: self.tagCombo.setEditText(cur) else: self.tagCombo.clearEditText() self.updateStates() @pyqtSlot() def updateStates(self): """ update bottom button sensitives based on rev and tag """ tagu = self.tagCombo.currentText() tag = hglib.fromunicode(tagu) # check tag existence if tag: exists = tag in self.repo.tags() if exists: tagtype = self.repo.tagtype(tag) islocal = 'local' == tagtype try: ctx = self.repo[self.repo.tags()[tag]] trev = ctx.rev() thash = str(ctx) except: trev, thash, local = 0, '????????', '' self.localCheckBox.setChecked(islocal) self.localCheckBox.setEnabled(False) local = islocal and _('local') or '' self.tagRevLabel.setText('%d (%s) %s' % (trev, thash, local)) samerev = trev == self.rev else: islocal = self.localCheckBox.isChecked() self.localCheckBox.setEnabled(True) self.tagRevLabel.clear() force = self.replaceCheckBox.isChecked() custom = self.customCheckBox.isChecked() self.addBtn.setEnabled(not exists or (force and not samerev)) if exists and not samerev: self.addBtn.setText(_('Move')) else: self.addBtn.setText(_('Add')) self.removeBtn.setEnabled(exists) self.englishCheckBox.setEnabled(not islocal) self.customCheckBox.setEnabled(not islocal) self.customTextLineEdit.setEnabled(not islocal and custom) else: self.addBtn.setEnabled(False) self.removeBtn.setEnabled(False) self.localCheckBox.setEnabled(False) self.englishCheckBox.setEnabled(False) self.customCheckBox.setEnabled(False) self.customTextLineEdit.setEnabled(False) self.tagRevLabel.clear() def customMessageToggle(self, checked): self.customTextLineEdit.setEnabled(checked) if checked: self.customTextLineEdit.setFocus() def show_options(self, visible): self.localCheckBox.setVisible(visible) self.replaceCheckBox.setVisible(visible) self.englishCheckBox.setVisible(visible) self.customCheckBox.setVisible(visible) self.customTextLineEdit.setVisible(visible) def set_status(self, text, icon): self.status.setShown(True) self.sep.setShown(True) self.status.set_status(text, icon) self.showMessage.emit(text) def clear_statue(self): self.status.setHidden(True) self.sep.setHidden(True) def onCommandFinished(self, ret): if ret == 0: self.finishfunc() def onAddTag(self): tagu = self.tagCombo.currentText() tag = hglib.fromunicode(tagu) local = self.localCheckBox.isChecked() force = self.replaceCheckBox.isChecked() english = self.englishCheckBox.isChecked() if self.customCheckBox.isChecked(): message = self.customTextLineEdit.text() else: message = None exists = tag in self.repo.tags() if exists and not force: self.set_status(_("Tag '%s' already exists") % tagu, False) return if not local: parents = self.repo.parents() if len(parents) > 1: self.set_status(_('uncommitted merge'), False) return p1 = parents[0] if not force and p1.node() not in self.repo._branchheads: self.set_status(_('not at a branch head (use force)'), False) return if not message: ctx = self.repo[self.rev] if exists: origctx = self.repo[self.repo.tags()[tag]] msgset = keep._('Moved tag %s to changeset %s' \ ' (from changeset %s)') message = (english and msgset['id'] or msgset['str']) \ % (tagu, str(ctx), str(origctx)) else: msgset = keep._('Added tag %s for changeset %s') message = (english and msgset['id'] or msgset['str']) \ % (tagu, str(ctx)) message = hglib.fromunicode(message) def finished(): if exists: self.set_status(_("Tag '%s' has been moved") % tagu, True) else: self.set_status(_("Tag '%s' has been added") % tagu, True) user = qtlib.getCurrentUsername(self, self.repo) if not user: return cmd = ['tag', '--repository', self.repo.root, '--rev', str(self.rev), '--user', user] if local: cmd.append('--local') else: cmd.append('--message=%s' % message) if force: cmd.append('--force') cmd.append(tag) self.finishfunc = finished self.cmd.run(cmd) def onRemoveTag(self): tagu = self.tagCombo.currentText() tag = hglib.fromunicode(tagu) local = self.localCheckBox.isChecked() force = self.replaceCheckBox.isChecked() english = self.englishCheckBox.isChecked() if self.customCheckBox.isChecked(): message = self.customTextLineEdit.text() else: message = None tagtype = self.repo.tagtype(tag) if local: if tagtype != 'local': self.set_status(_("tag '%s' is not a local tag") % tagu) return else: if tagtype != 'global': self.set_status(_("tag '%s' is not a global tag") % tagu) return parents = self.repo.parents() if len(parents) > 1: self.set_status(_('uncommitted merge'), False) return p1 = parents[0] if not force and p1.node() not in self.repo._branchheads: self.set_status(_('not at a branch head (use force)'), False) return if not message: msgset = keep._('Removed tag %s') message = (english and msgset['id'] or msgset['str']) % tagu message = hglib.fromunicode(message) def finished(): self.set_status(_("Tag '%s' has been removed") % tagu, True) cmd = ['tag', '--repository', self.repo.root, '--remove'] if local: cmd.append('--local') else: cmd.append('--message=%s' % message) cmd.append(tag) self.finishfunc = finished self.cmd.run(cmd) def reject(self): # prevent signals from reaching deleted objects self.repo.repositoryChanged.disconnect(self.refresh) super(TagDialog, self).reject() def run(ui, *pats, **opts): kargs = {} tag = len(pats) > 0 and pats[0] or None if tag: kargs['tag'] = tag rev = opts.get('rev') if rev: kargs['rev'] = rev from tortoisehg.util import paths from tortoisehg.hgqt import thgrepo repo = thgrepo.repository(ui, path=paths.find_root()) return TagDialog(repo, opts=opts, **kargs)