11
from mercurial import ui, util, error
11
from mercurial import ui, util, error, scmutil, phases
13
13
from tortoisehg.util import hglib, shlib, wconfig, bugtraq
16
16
from tortoisehg.hgqt.messageentry import MessageEntry
17
17
from tortoisehg.hgqt import qtlib, qscilib, status, cmdui, branchop, revpanel
18
18
from tortoisehg.hgqt import hgrcutil, mq, lfprompt
19
from tortoisehg.util.hgversion import hgversion
20
21
from PyQt4.QtCore import *
21
22
from PyQt4.QtGui import *
61
62
opts['recurseinsubrepos'] = repo.ui.config('tortoisehg', 'recurseinsubrepos', None)
62
63
opts['bugtraqplugin'] = repo.ui.config('tortoisehg', 'issue.bugtraqplugin', None)
63
64
opts['bugtraqparameters'] = repo.ui.config('tortoisehg', 'issue.bugtraqparameters', None)
65
if opts['bugtraqparameters']:
66
opts['bugtraqparameters'] = os.path.expandvars(opts['bugtraqparameters'])
64
67
opts['bugtraqtrigger'] = repo.ui.config('tortoisehg', 'issue.bugtraqtrigger', None)
65
68
self.opts = opts # user, date
116
119
tbar.setIconSize(QSize(16,16))
118
121
if self.opts['bugtraqplugin'] != None:
119
self.bugtraq = self.createBugTracker()
121
parameters = self.opts['bugtraqparameters']
122
linktext = self.bugtraq.get_link_text(parameters)
124
tracker = self.opts['bugtraqplugin'].split(' ', 1)[1]
125
qtlib.ErrorMsgBox(_('Issue Tracker'),
126
_('Failed to load issue tracker \'%s\': %s')
127
% (tracker, hglib.tounicode(str(e))),
131
# connect UI because we have a valid bug tracker
132
self.commitComplete.connect(self.bugTrackerPostCommit)
133
tbar.addAction(linktext).triggered.connect(
134
self.getBugTrackerCommitMessage)
122
# We create the "Show Issues" button, but we delay its setup
123
# because creating the bugtraq object is slow and blocks the GUI,
124
# which would result in a noticeable slow down while creating the commit widget
125
self.showIssues = tbar.addAction(_('Show Issues'))
126
self.showIssues.setEnabled(False)
127
self.showIssues.setToolTip(_('Please wait...'))
128
def setupBugTraqButton():
129
self.bugtraq = self.createBugTracker()
131
parameters = self.opts['bugtraqparameters']
132
linktext = self.bugtraq.get_link_text(parameters)
134
tracker = self.opts['bugtraqplugin'].split(' ', 1)[1]
135
errormsg = _('Failed to load issue tracker \'%s\': %s') \
136
% (tracker, hglib.tounicode(str(e)))
137
self.showIssues.setToolTip(errormsg)
138
qtlib.ErrorMsgBox(_('Issue Tracker'), errormsg,
142
# connect UI because we have a valid bug tracker
143
self.commitComplete.connect(self.bugTrackerPostCommit)
144
self.showIssues.setText(linktext)
145
self.showIssues.triggered.connect(self.getBugTrackerCommitMessage)
146
self.showIssues.setToolTip(_('Show Issues...'))
147
self.showIssues.setEnabled(True)
148
QTimer.singleShot(100, setupBugTraqButton)
136
150
self.stopAction = tbar.addAction(_('Stop'))
137
151
self.stopAction.triggered.connect(self.stop)
157
171
self.hasmqbutton = False
161
hbox.setContentsMargins(2, 0, 2, 2)
162
self.optionslabelhdr = QLabel(_('<b>Selected Options:</b>'))
163
self.optionslabelhdr.setContentsMargins(0, 0, 4, 0)
164
self.optionslabel = QLabel()
173
class TruncLabel(QLabel):
175
QLabel.__init__(self)
176
def minimumSizeHint(self):
177
s = QLabel.minimumSizeHint(self)
178
return QSize(0, s.height())
180
self.optionslabel = TruncLabel()
165
181
self.optionslabel.setAcceptDrops(False)
166
hbox.addWidget(self.optionslabelhdr)
167
hbox.addWidget(self.optionslabel)
182
vbox.addWidget(self.optionslabel, 0)
170
184
self.pcsinfo = revpanel.ParentWidget(repo)
171
185
vbox.addWidget(self.pcsinfo, 0)
245
259
def mqSetupButton(self):
246
260
ispatch = lambda r: 'qtip' in r.changectx('.').tags()
247
261
notpatch = lambda r: 'qtip' not in r.changectx('.').tags()
262
canamend = lambda r: False
263
# hg >= 2.2 has amend capabilities
264
if hgversion >= '2.2':
268
ctx = r.changectx('.')
269
return not ctx.children() \
270
and ctx.phase() != phases.public \
271
and len(ctx.parents()) < 2 \
272
and len(r.changectx(None).parents()) < 2
249
275
('commit', _('Commit changes'), _('Commit'), notpatch),
276
('amend', _('Amend current revision'), _('Amend'), canamend),
250
277
('qnew', _('Create a new patch'), _('QNew'), None),
251
278
('qref', _('Refresh current patch'), _('QRefresh'), ispatch),
340
367
curraction = switchAction(curraction, 'commit')
341
368
elif curraction._name == 'commit' and ispatch:
342
369
curraction = switchAction(curraction, 'qref')
343
if curraction._name == 'qref':
370
if curraction._name in ('qref', 'amend'):
344
371
refreshwctx = refresh
345
372
self.stwidget.setPatchContext(pctx)
346
373
elif curraction._name == 'commit':
347
374
refreshwctx = refresh and oldpctx is not None
348
375
self.stwidget.setPatchContext(None)
349
if curraction._name == 'qref':
350
if self.lastAction != 'qref':
376
if curraction._name in ('qref', 'amend'):
377
if self.lastAction not in ('qref', 'amend'):
351
378
self.lastCommitMsg = self.msgte.text()
352
379
self.setMessage(hglib.tounicode(pctx.description()))
354
if self.lastAction == 'qref':
381
if self.lastAction in ('qref', 'amend'):
355
382
self.setMessage(self.lastCommitMsg)
357
384
self.stwidget.refreshWctx()
537
566
title = _('New Branch: ') + self.branchop
538
567
self.branchbutton.setText(title)
540
# Update options label
569
# Update options label, showing only whitelisted options.
542
571
for opt, value in self.opts.iteritems():
543
if not opt.startswith('bugtraq'):
544
# The "bugtraq" related options are not very interesting as they are not passed to the commit command
545
# The user will already see an "issue tracker" button indicating that the bug tracker is active
572
if opt in ['user', 'date', 'pushafter', 'autoinc',
573
'recurseinsubrepos']:
546
574
if value is True:
547
575
opts.append('--' + opt)
549
577
opts.append('--%s=%s' % (opt, value))
551
self.optionslabel.setText(' '.join(opts))
579
self.optionslabelfmt = _('<b>Selected Options:</b> %s')
580
self.optionslabel.setText(self.optionslabelfmt
581
% hglib.tounicode(' '.join(opts)))
552
582
self.optionslabel.setVisible(bool(opts))
553
self.optionslabelhdr.setVisible(bool(opts))
555
584
# Update parent csinfo widget
556
585
self.pcsinfo.set_revision(None)
730
759
self.msgte.setFocus()
733
linkmandatory = self.repo.ui.config('tortoisehg',
734
'issue.linkmandatory', False)
762
linkmandatory = self.repo.ui.configbool('tortoisehg',
763
'issue.linkmandatory', False)
735
764
if linkmandatory:
736
765
issueregex = self.repo.ui.config('tortoisehg', 'issue.regex')
777
806
checkedUnknowns = self.stwidget.getChecked('?I')
778
807
if checkedUnknowns:
779
res = qtlib.CustomPrompt(
781
_('Add selected untracked files?'), self,
782
(_('&Add'), _('Cancel')), 0, 1,
783
checkedUnknowns).run()
808
confirm = self.repo.ui.configbool('tortoisehg', 'confirmaddfiles', True)
810
res = qtlib.CustomPrompt(
812
_('Add selected untracked files?'), self,
813
(_('&Add'), _('Cancel')), 0, 1,
814
checkedUnknowns).run()
785
818
haslf = 'largefiles' in repo.extensions()
786
haskbf = 'kbfiles' in repo.extensions()
788
820
result = lfprompt.promptForLfiles(self, repo.ui, repo,
789
checkedUnknowns, haskbf)
792
824
checkedUnknowns, lfiles = result
795
cmd = ['add', '--repository', repo.root, '--large'] + \
796
[repo.wjoin(f) for f in lfiles]
798
cmd = ['add', '--repository', repo.root, '--bf'] + \
799
[repo.wjoin(f) for f in lfiles]
826
cmd = ['add', '--repository', repo.root, '--large'] + \
827
[repo.wjoin(f) for f in lfiles]
800
828
commandlines.append(cmd)
801
829
cmd = ['add', '--repository', repo.root] + \
802
830
[repo.wjoin(f) for f in checkedUnknowns]
806
834
checkedMissing = self.stwidget.getChecked('!')
807
835
if checkedMissing:
808
res = qtlib.CustomPrompt(
810
_('Remove selected deleted files?'), self,
811
(_('&Remove'), _('Cancel')), 0, 1,
812
checkedMissing).run()
836
confirm = self.repo.ui.configbool('tortoisehg', 'confirmdeletefiles', True)
838
res = qtlib.CustomPrompt(
840
_('Remove selected deleted files?'), self,
841
(_('&Remove'), _('Cancel')), 0, 1,
842
checkedMissing).run()
814
846
cmd = ['remove', '--repository', repo.root] + \
815
847
[repo.wjoin(f) for f in checkedMissing]
852
887
commandlines.append(cmd)
854
889
repo.incrementBusyCount()
855
self.currentAction = 'commit'
891
self.currentAction = 'amend'
893
self.currentAction = 'commit'
856
894
self.currentProgress = _('Commit', 'start progress')
857
895
self.progress.emit(*cmdui.startProgress(self.currentProgress, ''))
858
896
self.commitButtonEnable.emit(False)
1293
1331
self.commit.stwidget.refthread.wait()
1294
1332
QTimer.singleShot(0, self.reject)
1297
self.commit.commit()
1300
if self.commit.canExit():
1334
def promptExit(self):
1335
exit = self.commit.canExit()
1337
exit = qtlib.QuestionMsgBox(_('TortoiseHg Commit'),
1338
_('Are you sure that you want to cancel the commit operation?'),
1301
1341
s = QSettings()
1302
1342
s.setValue('commit/geom', self.saveGeometry())
1303
1343
self.commit.saveSettings(s, 'committool')
1347
self.commit.commit()
1350
if self.promptExit():
1304
1351
QDialog.reject(self)
1353
def closeEvent(self, event):
1354
if not self.promptExit():
1306
1357
def run(ui, *pats, **opts):
1307
1358
from tortoisehg.util import paths
1308
1359
from tortoisehg.hgqt import thgrepo