Debian Codegraph @

lib/uncommit.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 # Copyright (C) 2009 Canonical Ltd
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 from PyQt5 import QtCore, QtGui, QtWidgets
21
22 from breezy import controldir, errors, log
23 from breezy.revisionspec import RevisionSpec
24
25 from breezy.plugins.qbrz.lib.html_log import log_as_html
26 from breezy.plugins.qbrz.lib.i18n import gettext
27 from breezy.plugins.qbrz.lib.subprocess import SubProcessDialog
28 from breezy.plugins.qbrz.lib.trace import reports_exception, SUB_LOAD_METHOD
29 from breezy.plugins.qbrz.lib.util import url_for_display
30
31
32 class QBzrUncommitWindow(SubProcessDialog):
33
34 def __init__(self, location, dialog=True, ui_mode=True, parent=None,
35 local=None, message=None):
36 super(QBzrUncommitWindow, self).__init__(
37 gettext("Uncommit"),
38 name="uncommit",
39 default_size=(400, 400),
40 ui_mode=ui_mode,
41 dialog=dialog,
42 parent=parent,
43 hide_progress=True,
44 )
45 self.tree, self.branch = controldir.ControlDir.open_tree_or_branch(location)
46
47 # Display the branch
48 branch_label = QtWidgets.QLabel(gettext("Branch: %s") % url_for_display(self.branch.base))
49
50 # Display the revision selection section. We nearly always
51 # want to just uncommit the last revision (to tweak the
52 # commit message say) so we make that the default.
53 groupbox = QtWidgets.QGroupBox(gettext("Move tip to"), self)
54 self.last_radio = QtWidgets.QRadioButton(gettext("Parent of current tip revision"))
55 self.last_radio.setChecked(QtCore.Qt.Checked)
56 self.other_radio = QtWidgets.QRadioButton(gettext("Other revision:"))
57 self.other_revision = QtWidgets.QLineEdit()
58 other = QtWidgets.QHBoxLayout()
59 other.addWidget(self.other_radio)
60 other.addWidget(self.other_revision)
61 vbox = QtWidgets.QVBoxLayout(groupbox)
62 vbox.addWidget(self.last_radio)
63 vbox.addLayout(other)
64
65 # If the user starts entering a value in the 'other revision' field,
66 # set the matching radio button implicitly
67 self.other_revision.textChanged['QString'].connect(self.do_other_revision_changed)
68
69 # groupbox gets disabled as we are executing.
70 self.subprocessStarted[bool].connect(groupbox.setDisabled)
71
72 # Put the form together
73 layout = QtWidgets.QVBoxLayout(self)
74 layout.addWidget(branch_label)
75 layout.addWidget(groupbox)
76 layout.addWidget(self.make_default_status_box())
77 layout.addWidget(self.buttonbox)
78
79 def do_other_revision_changed(self, text):
80 if text and not self.other_radio.isChecked():
81 self.other_radio.setChecked(True)
82
83 def _revision_identifier(self):
84 """What revision did the user select?
85
86 :return: None for the last revision.
87 Otherwise the revision identifier as a string.
88 """
89 if self.other_radio.isChecked():
90 result = str(self.other_revision.text())
91 if result:
92 return result
93 else:
94 msg = gettext("No other revision specified.")
95 raise errors.BzrError(msg)
96 # Default is the tip revision
97 return None
98
99 @reports_exception(type=SUB_LOAD_METHOD)
100 def validate(self):
101 """Check that the user really wants to uncommit the given revisions."""
102 revision = self._revision_identifier()
103 if revision is None:
104 log_rqst = log.make_log_request_dict(limit=1)
105 else:
106 rev_spec = RevisionSpec.from_string(revision)
107 revno = rev_spec.in_history(self.branch).revno
108 # We need to offset the revno by +1 because we'll be uncommitting
109 # *back* to revno, meaning those after it are 'deleted'
110 log_rqst = log.make_log_request_dict(start_revision=revno + 1)
111 log_data = log_as_html(self.branch, log_rqst)
112 question = gettext("Do you really want to uncommit these revisions?")
113 if self.ask_confirmation('<font color="red">%s</font><br/>%s' % (question, log_data),type='warning'):
114 return True
115 return False
116
117 def do_start(self):
118 args = ['--force']
119 revision = self._revision_identifier()
120 if revision:
121 args.append('--revision')
122 args.append(revision)
123 if self.tree:
124 dest = self.tree.basedir
125 else:
126 dest = self.branch.base
127 args.append(dest)
128 self.process_widget.do_start(None, 'uncommit', *args)