| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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 |
|
| 48 |
branch_label = QtWidgets.QLabel(gettext("Branch: %s") % url_for_display(self.branch.base)) |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 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 |
|
| 66 |
|
| 67 |
self.other_revision.textChanged['QString'].connect(self.do_other_revision_changed) |
| 68 |
|
| 69 |
|
| 70 |
self.subprocessStarted[bool].connect(groupbox.setDisabled) |
| 71 |
|
| 72 |
|
| 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 |
|
| 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 |
|
| 109 |
|
| 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) |