~ubuntu-branches/debian/sid/tortoisehg/sid

« back to all changes in this revision

Viewing changes to tortoisehg/hgqt/commit.py

  • Committer: Package Import Robot
  • Author(s): Ludovico Cavedon
  • Date: 2012-05-29 00:59:17 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20120529005917-ae1mdohuiimxxkc0
Tags: 2.4-1
* Imported Upstream version 2.4 (Closes: #671473).
* Re-add Nautilus extension (LP: #990527).
* Update Standards-Version to 3.9.3.
* Update copyright format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
import os
9
9
import re
10
10
 
11
 
from mercurial import ui, util, error
 
11
from mercurial import ui, util, error, scmutil, phases
12
12
 
13
13
from tortoisehg.util import hglib, shlib, wconfig, bugtraq
14
14
 
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
19
20
 
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
66
69
 
116
119
        tbar.setIconSize(QSize(16,16))
117
120
 
118
121
        if self.opts['bugtraqplugin'] != None:
119
 
            self.bugtraq = self.createBugTracker()
120
 
            try:
121
 
                parameters = self.opts['bugtraqparameters']
122
 
                linktext = self.bugtraq.get_link_text(parameters)
123
 
            except Exception, e:
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))),
128
 
                                  parent=self)
129
 
                self.bugtraq = None
130
 
            else:
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()
 
130
                try:
 
131
                    parameters = self.opts['bugtraqparameters']
 
132
                    linktext = self.bugtraq.get_link_text(parameters)
 
133
                except Exception, e:
 
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,
 
139
                                      parent=self)
 
140
                    self.bugtraq = None
 
141
                else:
 
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)
135
149
 
136
150
        self.stopAction = tbar.addAction(_('Stop'))
137
151
        self.stopAction.triggered.connect(self.stop)
156
170
        else:
157
171
            self.hasmqbutton = False
158
172
 
159
 
        hbox = QHBoxLayout()
160
 
        vbox.addLayout(hbox)
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):
 
174
            def __init__(self):
 
175
                QLabel.__init__(self)
 
176
            def minimumSizeHint(self):
 
177
                s = QLabel.minimumSizeHint(self)
 
178
                return QSize(0, s.height())
 
179
 
 
180
        self.optionslabel = TruncLabel()
165
181
        self.optionslabel.setAcceptDrops(False)
166
 
        hbox.addWidget(self.optionslabelhdr)
167
 
        hbox.addWidget(self.optionslabel)
168
 
        hbox.addStretch()
 
182
        vbox.addWidget(self.optionslabel, 0)
169
183
 
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':
 
265
            def canamend(r):
 
266
                if ispatch(r):
 
267
                    return False
 
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
 
273
 
248
274
        acts = (
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),
252
279
        )
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()))
353
380
        else:
354
 
            if self.lastAction == 'qref':
 
381
            if self.lastAction in ('qref', 'amend'):
355
382
                self.setMessage(self.lastCommitMsg)
356
383
        if refreshwctx:
357
384
            self.stwidget.refreshWctx()
408
435
        curraction = self.mqgroup.checkedAction()
409
436
        if curraction._name == 'commit':
410
437
            return self.commit()
 
438
        elif curraction._name == 'amend':
 
439
            return self.commit(amend=True)
411
440
 
412
441
        # Check if we need to change branch first
413
442
        commandlines = []
537
566
            title = _('New Branch: ') + self.branchop
538
567
        self.branchbutton.setText(title)
539
568
 
540
 
        # Update options label
 
569
        # Update options label, showing only whitelisted options.
541
570
        opts = []
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)
548
576
                elif value:
549
577
                    opts.append('--%s=%s' % (opt, value))
550
578
 
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))
554
583
 
555
584
        # Update parent csinfo widget
556
585
        self.pcsinfo.set_revision(None)
706
735
        self.userhist.insert(0, user)
707
736
        self.userhist = self.userhist[:10]
708
737
 
709
 
    def commit(self):
 
738
    def commit(self, amend=False):
710
739
        repo = self.repo
711
740
        try:
712
741
            msg = self.getMessage(False)
730
759
            self.msgte.setFocus()
731
760
            return
732
761
 
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')
737
766
            if issueregex:
776
805
 
777
806
        checkedUnknowns = self.stwidget.getChecked('?I')
778
807
        if checkedUnknowns:
779
 
            res = qtlib.CustomPrompt(
780
 
                    _('Confirm Add'),
781
 
                    _('Add selected untracked files?'), self,
782
 
                    (_('&Add'), _('Cancel')), 0, 1,
783
 
                    checkedUnknowns).run()
 
808
            confirm = self.repo.ui.configbool('tortoisehg', 'confirmaddfiles', True)
 
809
            if confirm:
 
810
                res = qtlib.CustomPrompt(
 
811
                        _('Confirm Add'),
 
812
                        _('Add selected untracked files?'), self,
 
813
                        (_('&Add'), _('Cancel')), 0, 1,
 
814
                        checkedUnknowns).run()
 
815
            else:
 
816
                res = 0
784
817
            if res == 0:
785
818
                haslf = 'largefiles' in repo.extensions()
786
 
                haskbf = 'kbfiles' in repo.extensions()
787
 
                if haslf or haskbf:
 
819
                if haslf:
788
820
                    result = lfprompt.promptForLfiles(self, repo.ui, repo,
789
 
                                                      checkedUnknowns, haskbf)
 
821
                                                      checkedUnknowns)
790
822
                    if not result:
791
823
                        return
792
824
                    checkedUnknowns, lfiles = result
793
825
                    if lfiles:
794
 
                        if haslf:
795
 
                            cmd = ['add', '--repository', repo.root, '--large'] + \
796
 
                                  [repo.wjoin(f) for f in lfiles]
797
 
                        else:
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]
805
833
                return
806
834
        checkedMissing = self.stwidget.getChecked('!')
807
835
        if checkedMissing:
808
 
            res = qtlib.CustomPrompt(
809
 
                    _('Confirm Remove'),
810
 
                    _('Remove selected deleted files?'), self,
811
 
                    (_('&Remove'), _('Cancel')), 0, 1,
812
 
                    checkedMissing).run()
 
836
            confirm = self.repo.ui.configbool('tortoisehg', 'confirmdeletefiles', True)
 
837
            if confirm:
 
838
                res = qtlib.CustomPrompt(
 
839
                        _('Confirm Remove'),
 
840
                        _('Remove selected deleted files?'), self,
 
841
                        (_('&Remove'), _('Cancel')), 0, 1,
 
842
                        checkedMissing).run()
 
843
            else:
 
844
                res = 0
813
845
            if res == 0:
814
846
                cmd = ['remove', '--repository', repo.root] + \
815
847
                      [repo.wjoin(f) for f in checkedMissing]
838
870
        if self.opts.get('recurseinsubrepos'):
839
871
            cmdline.append('--subrepos')
840
872
 
 
873
        if amend:
 
874
            cmdline.append('--amend')
 
875
 
841
876
        cmdline.append('--')
842
877
        cmdline.extend([repo.wjoin(f) for f in self.files])
843
878
        if len(repo.parents()) == 1:
852
887
            commandlines.append(cmd)
853
888
 
854
889
        repo.incrementBusyCount()
855
 
        self.currentAction = 'commit'
 
890
        if amend:
 
891
            self.currentAction = 'amend'
 
892
        else:
 
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)
875
913
                return
876
914
            self.branchop = None
877
915
            umsg = self.msgte.text()
878
 
            if self.currentAction != 'qref':
 
916
            if self.currentAction not in ('qref', 'amend'):
879
917
                self.lastCommitMsg = ''
880
918
                if self.currentAction == 'commit':
881
919
                    # capture last message for BugTraq plugin
1037
1075
        self.saveToPath([fn])
1038
1076
 
1039
1077
    def saveGlobal(self):
1040
 
        self.saveToPath(hglib.user_rcpath())
 
1078
        self.saveToPath(scmutil.userrcpath())
1041
1079
 
1042
1080
    def saveToPath(self, path):
1043
1081
        fn, cfg = hgrcutil.loadIniFile(path, self)
1293
1331
                self.commit.stwidget.refthread.wait()
1294
1332
                QTimer.singleShot(0, self.reject)
1295
1333
 
1296
 
    def accept(self):
1297
 
        self.commit.commit()
1298
 
 
1299
 
    def reject(self):
1300
 
        if self.commit.canExit():
 
1334
    def promptExit(self):
 
1335
        exit = self.commit.canExit()
 
1336
        if not exit:
 
1337
            exit = qtlib.QuestionMsgBox(_('TortoiseHg Commit'),
 
1338
                _('Are you sure that you want to cancel the commit operation?'),
 
1339
                parent=self)
 
1340
        if exit:
1301
1341
            s = QSettings()
1302
1342
            s.setValue('commit/geom', self.saveGeometry())
1303
1343
            self.commit.saveSettings(s, 'committool')
 
1344
        return exit
 
1345
    
 
1346
    def accept(self):
 
1347
        self.commit.commit()
 
1348
 
 
1349
    def reject(self):
 
1350
        if self.promptExit():
1304
1351
            QDialog.reject(self)
1305
1352
 
 
1353
    def closeEvent(self, event):
 
1354
        if not self.promptExit():
 
1355
            event.ignore()
 
1356
 
1306
1357
def run(ui, *pats, **opts):
1307
1358
    from tortoisehg.util import paths
1308
1359
    from tortoisehg.hgqt import thgrepo