| 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.plugins.qbrz.lib.revtreeview import (RevisionTreeView, |
| 23 |
RevNoItemDelegate, |
| 24 |
get_text_color) |
| 25 |
from breezy.revision import NULL_REVISION, CURRENT_REVISION |
| 26 |
from breezy.plugins.qbrz.lib.util import ( |
| 27 |
runs_in_loading_queue, |
| 28 |
) |
| 29 |
from breezy.plugins.qbrz.lib.trace import reports_exception, SUB_LOAD_METHOD |
| 30 |
from breezy.plugins.qbrz.lib.uifactory import ui_current_widget |
| 31 |
|
| 32 |
from breezy.controldir import ControlDir |
| 33 |
from breezy.revisionspec import RevisionSpec |
| 34 |
from breezy.plugins.qbrz.lib.tag import TagWindow, CallBackTagWindow |
| 35 |
from breezy.plugins.qbrz.lib import logmodel |
| 36 |
from breezy.plugins.qbrz.lib import diff |
| 37 |
from breezy.plugins.qbrz.lib.i18n import gettext |
| 38 |
from breezy.plugins.qbrz.lib.subprocess import SimpleSubProcessDialog |
| 39 |
|
| 40 |
|
| 41 |
class LogList(RevisionTreeView): |
| 42 |
"""TreeView widget to show log with metadata and graph of revisions.""" |
| 43 |
|
| 44 |
def __init__(self, processEvents, throbber, parent=None, |
| 45 |
view_commands=True, action_commands=False): |
| 46 |
"""Costructing new widget. |
| 47 |
@param throbber: throbber widget in parent window |
| 48 |
@param parent: parent window |
| 49 |
""" |
| 50 |
RevisionTreeView.__init__(self, parent) |
| 51 |
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) |
| 52 |
self.setSelectionMode(QtWidgets.QAbstractItemView.ContiguousSelection) |
| 53 |
self.setUniformRowHeights(True) |
| 54 |
self.setAllColumnsShowFocus(True) |
| 55 |
self.setRootIsDecorated(False) |
| 56 |
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) |
| 57 |
|
| 58 |
self.setItemDelegateForColumn(logmodel.COL_MESSAGE, GraphTagsBugsItemDelegate(self)) |
| 59 |
self.rev_no_item_delegate = RevNoItemDelegate(parent=self) |
| 60 |
self.setItemDelegateForColumn(logmodel.COL_REV, self.rev_no_item_delegate) |
| 61 |
|
| 62 |
self.log_model = logmodel.LogModel(processEvents, throbber, self) |
| 63 |
self.lines_updated_selection = [] |
| 64 |
self.lines_updated_selection_current = None |
| 65 |
self.setModel(self.log_model) |
| 66 |
self.log_model.layoutAboutToBeChanged.connect(self.lines_updated_remember_selection) |
| 67 |
self.log_model.layoutChanged.connect(self.lines_updated_restore_selection) |
| 68 |
|
| 69 |
header = self.header() |
| 70 |
header.setStretchLastSection(False) |
| 71 |
|
| 72 |
header.setSectionResizeMode(logmodel.COL_REV, QtWidgets.QHeaderView.Interactive) |
| 73 |
header.setSectionResizeMode(logmodel.COL_MESSAGE, QtWidgets.QHeaderView.Stretch) |
| 74 |
header.setSectionResizeMode(logmodel.COL_DATE, QtWidgets.QHeaderView.Interactive) |
| 75 |
header.setSectionResizeMode(logmodel.COL_AUTHOR, QtWidgets.QHeaderView.Interactive) |
| 76 |
fm = self.fontMetrics() |
| 77 |
|
| 78 |
col_margin = (self.style().pixelMetric(QtWidgets.QStyle.PM_FocusFrameHMargin, None, self) + 1) *2 |
| 79 |
header.resizeSection(logmodel.COL_REV, fm.width("8888.8.888") + col_margin) |
| 80 |
|
| 81 |
|
| 82 |
header.resizeSection(logmodel.COL_DATE, fm.width("88-88-8888 88:88 ") + col_margin) |
| 83 |
header.resizeSection(logmodel.COL_AUTHOR, fm.width("Joe I have a Long Name") + col_margin) |
| 84 |
|
| 85 |
self.view_commands = view_commands |
| 86 |
self.action_commands = action_commands |
| 87 |
|
| 88 |
if self.view_commands: |
| 89 |
self.doubleClicked[QtCore.QModelIndex].connect(self.default_action) |
| 90 |
self.context_menu = QtWidgets.QMenu(self) |
| 91 |
self.context_menu_initialized = False |
| 92 |
|
| 93 |
def load(self, *args, **kargs): |
| 94 |
self.load_args = (args, kargs) |
| 95 |
self.log_model.load(*args, **kargs) |
| 96 |
self.create_context_menu() |
| 97 |
self._adjust_revno_column() |
| 98 |
|
| 99 |
@runs_in_loading_queue |
| 100 |
@ui_current_widget |
| 101 |
def refresh(self, b=True): |
| 102 |
(args, kargs) = self.load_args |
| 103 |
self.load(*args, **kargs) |
| 104 |
|
| 105 |
def create_context_menu(self, diff_is_default_action=True): |
| 106 |
if self.context_menu_initialized: |
| 107 |
return |
| 108 |
self.context_menu_initialized = True |
| 109 |
branch_count = len(self.log_model.graph_viz.branches) |
| 110 |
has_file_filter = bool(self.log_model.file_id_filter) |
| 111 |
|
| 112 |
self.context_menu = QtWidgets.QMenu(self) |
| 113 |
self.customContextMenuRequested[QtCore.QPoint].connect(self.show_context_menu) |
| 114 |
|
| 115 |
if self.view_commands: |
| 116 |
if has_file_filter: |
| 117 |
if diff.has_ext_diff(): |
| 118 |
diff_menu = diff.ExtDiffMenu(self, set_default=diff_is_default_action) |
| 119 |
diff_menu.setTitle(gettext("Show file &differences")) |
| 120 |
self.context_menu.addMenu(diff_menu) |
| 121 |
diff_menu.triggered['QString'].connect(self.show_diff_specified_files_ext) |
| 122 |
|
| 123 |
all_diff_menu = diff.ExtDiffMenu(self, set_default=False) |
| 124 |
all_diff_menu.setTitle(gettext("Show all &differences")) |
| 125 |
self.context_menu.addMenu(all_diff_menu) |
| 126 |
all_diff_menu.triggered['QString'].connect(self.show_diff_ext) |
| 127 |
else: |
| 128 |
show_diff_action = self.context_menu.addAction(gettext("Show file &differences..."), self.show_diff_specified_files) |
| 129 |
if diff_is_default_action: |
| 130 |
self.context_menu.setDefaultAction(show_diff_action) |
| 131 |
self.context_menu.addAction(gettext("Show all &differences..."), self.show_diff) |
| 132 |
else: |
| 133 |
if diff.has_ext_diff(): |
| 134 |
diff_menu = diff.ExtDiffMenu(self, set_default=diff_is_default_action) |
| 135 |
self.context_menu.addMenu(diff_menu) |
| 136 |
diff_menu._triggered.connect(self.show_diff_ext) |
| 137 |
else: |
| 138 |
show_diff_action = self.context_menu.addAction(gettext("Show &differences..."), self.show_diff) |
| 139 |
if diff_is_default_action: |
| 140 |
self.context_menu.setDefaultAction(show_diff_action) |
| 141 |
|
| 142 |
self.context_menu_show_tree = self.context_menu.addAction(gettext("Show &tree..."), self.show_revision_tree) |
| 143 |
|
| 144 |
if self.action_commands: |
| 145 |
self.context_menu.addSeparator() |
| 146 |
|
| 147 |
def add_branch_action(text, triggered, require_wt=False): |
| 148 |
if branch_count == 1: |
| 149 |
action = self.context_menu.addAction(text, triggered) |
| 150 |
if require_wt: |
| 151 |
action.setDisabled(self.log_model.graph_viz.branches[0].tree is None) |
| 152 |
else: |
| 153 |
menu = BranchMenu(text, self, self.log_model.graph_viz, require_wt) |
| 154 |
menu.bm_triggered.connect(triggered) |
| 155 |
action = self.context_menu.addMenu(menu) |
| 156 |
return action |
| 157 |
|
| 158 |
self.context_menu_tag = add_branch_action(gettext("Tag &revision..."), self.tag_revision) |
| 159 |
self.context_menu_revert = add_branch_action(gettext("R&evert to this revision"), self.revert_to_revision, require_wt=True) |
| 160 |
self.context_menu_update = add_branch_action(gettext("&Update to this revision"), self.update_to_revision, require_wt=True) |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
if branch_count > 1: |
| 166 |
self.context_menu_cherry_pick = add_branch_action(gettext("&Cherry pick"), self.cherry_pick, require_wt=True) |
| 167 |
else: |
| 168 |
self.context_menu_cherry_pick = None |
| 169 |
|
| 170 |
self.context_menu_reverse_cherry_pick = add_branch_action(gettext("Re&verse Cherry pick"), self.reverse_cherry_pick, require_wt=True) |
| 171 |
|
| 172 |
def _adjust_revno_column(self): |
| 173 |
|
| 174 |
max_mainline_digits = self.rev_no_item_delegate.set_max_revno( |
| 175 |
self.log_model.graph_viz.max_mainline_revno) |
| 176 |
|
| 177 |
header = self.header() |
| 178 |
fm = self.fontMetrics() |
| 179 |
col_margin = (self.style().pixelMetric(QtWidgets.QStyle.PM_FocusFrameHMargin, None, self) + 1) *2 |
| 180 |
header.resizeSection(logmodel.COL_REV, fm.width(("8" * max_mainline_digits)+".8.888") + col_margin) |
| 181 |
|
| 182 |
def refresh_tags(self): |
| 183 |
self.log_model.graph_viz.lock_read_branches() |
| 184 |
try: |
| 185 |
self.log_model.graph_viz.load_tags() |
| 186 |
finally: |
| 187 |
self.log_model.graph_viz.unlock_branches() |
| 188 |
|
| 189 |
def get_c_rev_under_twisty_pos(self, pos): |
| 190 |
index = self.indexAt(pos) |
| 191 |
rect = self.visualRect(index) |
| 192 |
boxsize = rect.height() |
| 193 |
c_rev = self.log_model.c_rev_from_index(index) |
| 194 |
if c_rev and c_rev.twisty_state is not None: |
| 195 |
twistyRect = QtCore.QRect(rect.x() + boxsize * c_rev.col_index, |
| 196 |
rect.y(), |
| 197 |
boxsize, |
| 198 |
boxsize) |
| 199 |
if twistyRect.contains(pos): |
| 200 |
return c_rev |
| 201 |
|
| 202 |
def mousePressEvent(self, e): |
| 203 |
collapse_expand_click = False |
| 204 |
if e.button() & QtCore.Qt.LeftButton: |
| 205 |
c_rev = self.get_c_rev_under_twisty_pos(e.pos()) |
| 206 |
if c_rev: |
| 207 |
collapse_expand_click = True |
| 208 |
self.log_model.collapse_expand_rev(c_rev) |
| 209 |
new_index = self.log_model.index_from_rev(c_rev.rev) |
| 210 |
if new_index: |
| 211 |
self.scrollTo(new_index) |
| 212 |
e.accept() |
| 213 |
if not collapse_expand_click: |
| 214 |
QtWidgets.QTreeView.mousePressEvent(self, e) |
| 215 |
|
| 216 |
def mouseMoveEvent(self, e): |
| 217 |
|
| 218 |
|
| 219 |
if not self.get_c_rev_under_twisty_pos(e.pos()): |
| 220 |
QtWidgets.QTreeView.mouseMoveEvent(self, e) |
| 221 |
|
| 222 |
def keyPressEvent(self, e): |
| 223 |
e_key = e.key() |
| 224 |
if e_key in (QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return) and self.view_commands: |
| 225 |
e.accept() |
| 226 |
self.default_action() |
| 227 |
elif e_key in (QtCore.Qt.Key_Left, QtCore.Qt.Key_Right): |
| 228 |
e.accept() |
| 229 |
indexes = self.get_selection_indexes() |
| 230 |
if not indexes: |
| 231 |
return |
| 232 |
c_rev = self.log_model.c_rev_from_index(indexes[0]) |
| 233 |
|
| 234 |
if (e.key() == QtCore.Qt.Key_Right |
| 235 |
and c_rev and not c_rev.twisty_state): |
| 236 |
self.log_model.collapse_expand_rev(c_rev) |
| 237 |
if e.key() == QtCore.Qt.Key_Left: |
| 238 |
if c_rev and c_rev.twisty_state: |
| 239 |
self.log_model.collapse_expand_rev(c_rev) |
| 240 |
else: |
| 241 |
|
| 242 |
if c_rev.rev.merged_by: |
| 243 |
merged_by = self.log_model.computed.revisions[ |
| 244 |
c_rev.rev.merged_by] |
| 245 |
self.setCurrentIndex(self.log_model.index_from_c_rev(merged_by)) |
| 246 |
self.scrollTo(self.currentIndex()) |
| 247 |
else: |
| 248 |
QtWidgets.QTreeView.keyPressEvent(self, e) |
| 249 |
|
| 250 |
def select_revid(self, revid): |
| 251 |
try: |
| 252 |
rev = self.log_model.graph_viz.revid_rev[revid] |
| 253 |
except KeyError: |
| 254 |
return |
| 255 |
self.log_model.ensure_rev_visible(rev) |
| 256 |
index = self.log_model.index_from_rev(rev) |
| 257 |
if index: |
| 258 |
self.setCurrentIndex(index) |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
def lines_updated_remember_selection(self): |
| 266 |
selection_model = self.selectionModel() |
| 267 |
rows = selection_model.selectedRows() |
| 268 |
expand_indexes_to_ids = \ |
| 269 |
lambda l: [str(i.data(logmodel.RevIdRole)) |
| 270 |
for i in l] |
| 271 |
|
| 272 |
if rows: |
| 273 |
self.lines_updated_selection = \ |
| 274 |
expand_indexes_to_ids((rows[0], rows[-1])) |
| 275 |
current_index = self.currentIndex() |
| 276 |
if current_index.isValid(): |
| 277 |
self.lines_updated_selection_current = \ |
| 278 |
str(current_index.data(logmodel.RevIdRole)) |
| 279 |
else: |
| 280 |
self.lines_updated_selection_current = None |
| 281 |
|
| 282 |
def lines_updated_restore_selection(self): |
| 283 |
selection_model = self.selectionModel() |
| 284 |
indexes = [self.log_model.index_from_revid(revid) |
| 285 |
for revid in self.lines_updated_selection] |
| 286 |
selection_model.clear() |
| 287 |
if self.lines_updated_selection_current: |
| 288 |
current_index = self.log_model.index_from_revid( |
| 289 |
self.lines_updated_selection_current) |
| 290 |
if current_index: |
| 291 |
self.setCurrentIndex(current_index) |
| 292 |
if not len(indexes) == 0 and indexes[0]: |
| 293 |
if not indexes[1]: |
| 294 |
indexes[1] = indexes[0] |
| 295 |
selection = QtCore.QItemSelection(*indexes) |
| 296 |
selection_model.select(selection, |
| 297 |
(QtCore.QItemSelectionModel.SelectCurrent | |
| 298 |
QtCore.QItemSelectionModel.Rows)) |
| 299 |
|
| 300 |
def get_selection_indexes(self, index=None): |
| 301 |
if index is None: |
| 302 |
return sorted(self.selectionModel().selectedRows(0), |
| 303 |
key=lambda x: x.row()) |
| 304 |
else: |
| 305 |
return [index] |
| 306 |
|
| 307 |
def get_selection_and_merged_revids(self, index=None): |
| 308 |
indexes = self.get_selection_indexes(index) |
| 309 |
revids = set() |
| 310 |
for index in indexes: |
| 311 |
revid = index.data(logmodel.RevIdRole) |
| 312 |
revids.add(revid) |
| 313 |
merges = [self.log_model.graph_viz.revisions[rev_index].revid |
| 314 |
for rev_index in |
| 315 |
self.log_model.graph_viz.revid_rev[revid].merges] |
| 316 |
revids.update(set(merges)) |
| 317 |
return revids |
| 318 |
|
| 319 |
def get_selection_top_and_parent_revids_and_count(self, index=None): |
| 320 |
indexes = self.get_selection_indexes(index) |
| 321 |
if len(indexes) == 0: |
| 322 |
return (None, None), 0 |
| 323 |
top_revid = indexes[0].data(logmodel.RevIdRole) |
| 324 |
bot_revid = indexes[-1].data(logmodel.RevIdRole) |
| 325 |
parents = self.log_model.graph_viz.known_graph.get_parent_keys(bot_revid) |
| 326 |
if parents: |
| 327 |
|
| 328 |
parent_revid = parents[0] |
| 329 |
|
| 330 |
|
| 331 |
if parent_revid == "root:": |
| 332 |
parent_revid = self.log_model.graph_viz.graph.get_parent_map([bot_revid])[bot_revid][0] |
| 333 |
else: |
| 334 |
parent_revid = NULL_REVISION |
| 335 |
return (top_revid, parent_revid), len(indexes) |
| 336 |
|
| 337 |
def set_search(self, str, field): |
| 338 |
self.log_model.prop_search_filter.set_search(str, field) |
| 339 |
|
| 340 |
def default_action(self, index=None): |
| 341 |
self.show_diff_specified_files() |
| 342 |
|
| 343 |
def tag_revision(self, selected_branch_info=None): |
| 344 |
gv = self.log_model.graph_viz |
| 345 |
|
| 346 |
if selected_branch_info: |
| 347 |
selected_branch_info = selected_branch_info |
| 348 |
else: |
| 349 |
assert(len(gv.branches)==1) |
| 350 |
selected_branch_info = gv.branches[0] |
| 351 |
|
| 352 |
revid = self.currentIndex().data(logmodel.RevIdRole) |
| 353 |
revno = gv.revid_rev[revid].revno_str |
| 354 |
revs = [RevisionSpec.from_string(revno)] |
| 355 |
branch = selected_branch_info.branch |
| 356 |
action = TagWindow.action_from_options(force=False, delete=False) |
| 357 |
window = CallBackTagWindow(branch, self.refresh_tags, action=action, revision=revs) |
| 358 |
window.show() |
| 359 |
self.window().windows.append(window) |
| 360 |
|
| 361 |
def sub_process_action(self, selected_branch_info, get_dialog, |
| 362 |
auto_run=False, refresh_method=None): |
| 363 |
gv = self.log_model.graph_viz |
| 364 |
(top_revid, old_revid), rev_count = \ |
| 365 |
self.get_selection_top_and_parent_revids_and_count() |
| 366 |
top_revno_str = gv.revid_rev[top_revid].revno_str |
| 367 |
if old_revid==NULL_REVISION: |
| 368 |
old_revno_str = 0 |
| 369 |
else: |
| 370 |
old_revno_str = gv.revid_rev[old_revid].revno_str |
| 371 |
|
| 372 |
if selected_branch_info: |
| 373 |
single_branch = False |
| 374 |
else: |
| 375 |
assert(len(gv.branches)==1) |
| 376 |
selected_branch_info = gv.branches[0] |
| 377 |
single_branch = True |
| 378 |
|
| 379 |
dialog = get_dialog(rev_count, |
| 380 |
top_revid, old_revid, |
| 381 |
top_revno_str, old_revno_str, |
| 382 |
selected_branch_info, single_branch) |
| 383 |
|
| 384 |
if refresh_method: |
| 385 |
dialog.subprocessFinished[bool].connect(refresh_method) |
| 386 |
|
| 387 |
dialog.show() |
| 388 |
self.window().windows.append(dialog) |
| 389 |
|
| 390 |
if auto_run: |
| 391 |
dialog.do_accept() |
| 392 |
|
| 393 |
def revert_to_revision(self, selected_branch_info=None): |
| 394 |
def get_dialog(rev_count, |
| 395 |
top_revid, old_revid, |
| 396 |
top_revno_str, old_revno_str, |
| 397 |
selected_branch_info, single_branch): |
| 398 |
assert(rev_count==1) |
| 399 |
|
| 400 |
if single_branch: |
| 401 |
desc = (gettext("Revert to revision %s revid:%s.") % (top_revno_str, top_revid)) |
| 402 |
else: |
| 403 |
desc = (gettext("Revert %s to revision %s revid:%s.") % (selected_branch_info.label, top_revno_str, top_revid)) |
| 404 |
|
| 405 |
args = ["revert", '-r', 'revid:%s' % top_revid] |
| 406 |
return SimpleSubProcessDialog(gettext("Revert"), desc=desc, args=args, dir=selected_branch_info.tree.basedir, parent=self) |
| 407 |
|
| 408 |
self.sub_process_action(selected_branch_info, get_dialog) |
| 409 |
|
| 410 |
def update_to_revision(self, selected_branch_info=None): |
| 411 |
def get_dialog(rev_count, |
| 412 |
top_revid, old_revid, |
| 413 |
top_revno_str, old_revno_str, |
| 414 |
selected_branch_info, single_branch): |
| 415 |
assert(rev_count==1) |
| 416 |
|
| 417 |
if single_branch: |
| 418 |
desc = (gettext("Update to revision %s revid:%s.") % (top_revno_str, top_revid)) |
| 419 |
else: |
| 420 |
desc = (gettext("Update %s to revision %s revid:%s.") % (selected_branch_info.label, top_revno_str, top_revid)) |
| 421 |
|
| 422 |
args = ["update", '-r', 'revid:%s' % top_revid] |
| 423 |
return SimpleSubProcessDialog(gettext("Update"), desc=desc, args=args, dir=selected_branch_info.tree.basedir, parent=self) |
| 424 |
|
| 425 |
self.sub_process_action(selected_branch_info, get_dialog, True, |
| 426 |
self.refresh) |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
def cherry_pick(self, selected_branch_info=None): |
| 431 |
def get_dialog(rev_count, |
| 432 |
top_revid, old_revid, |
| 433 |
top_revno_str, old_revno_str, |
| 434 |
selected_branch_info, single_branch): |
| 435 |
from_branch_info = self.log_model.graph_viz.get_revid_branch_info(top_revid) |
| 436 |
|
| 437 |
desc = (gettext("Cherry-pick revisions %s - %s from %s to %s.") % |
| 438 |
(old_revno_str, top_revno_str, |
| 439 |
from_branch_info.label, selected_branch_info.label)) |
| 440 |
|
| 441 |
args = ["merge", from_branch_info.branch.base, |
| 442 |
'-r', 'revid:%s..revid:%s' % (old_revid, top_revid)] |
| 443 |
return SimpleSubProcessDialog( |
| 444 |
gettext("Cherry-pick"), desc=desc, args=args, |
| 445 |
dir=selected_branch_info.tree.basedir, |
| 446 |
parent=self) |
| 447 |
|
| 448 |
self.sub_process_action(selected_branch_info, get_dialog) |
| 449 |
|
| 450 |
|
| 451 |
def reverse_cherry_pick(self, selected_branch_info=None): |
| 452 |
def get_dialog(rev_count, |
| 453 |
top_revid, old_revid, |
| 454 |
top_revno_str, old_revno_str, |
| 455 |
selected_branch_info, single_branch): |
| 456 |
if single_branch: |
| 457 |
desc = (gettext("Reverse cherry-pick revisions %s - %s") % |
| 458 |
(old_revno_str, top_revno_str)) |
| 459 |
else: |
| 460 |
desc = (gettext("Reverse cherry-pick revisions %s - %s in %s.") % |
| 461 |
(old_revno_str, top_revno_str, selected_branch_info.label)) |
| 462 |
|
| 463 |
args = ["merge", '.', |
| 464 |
'-r', 'revid:%s..revid:%s' % (top_revid, old_revid)] |
| 465 |
return SimpleSubProcessDialog( |
| 466 |
gettext("Reverse cherry-pick"), desc=desc, args=args, |
| 467 |
dir=selected_branch_info.tree.basedir, |
| 468 |
parent=self) |
| 469 |
|
| 470 |
self.sub_process_action(selected_branch_info, get_dialog) |
| 471 |
|
| 472 |
|
| 473 |
def show_diff(self, index=None, |
| 474 |
specific_files=None, specific_file_ids=None, |
| 475 |
ext_diff=None): |
| 476 |
|
| 477 |
(new_revid, old_revid), count = \ |
| 478 |
self.get_selection_top_and_parent_revids_and_count(index) |
| 479 |
if new_revid is None and old_revid is None: |
| 480 |
|
| 481 |
return |
| 482 |
new_branch = self.log_model.graph_viz.get_revid_branch(new_revid) |
| 483 |
old_branch = self.log_model.graph_viz.get_revid_branch(old_revid) |
| 484 |
|
| 485 |
def get_tree_if_current(revid): |
| 486 |
if (revid.startswith(CURRENT_REVISION) and |
| 487 |
isinstance(self.log_model.graph_viz, |
| 488 |
logmodel.WithWorkingTreeGraphVizLoader)): |
| 489 |
return self.log_model.graph_viz.working_trees[revid] |
| 490 |
|
| 491 |
arg_provider = diff.InternalDiffArgProvider( |
| 492 |
old_revid, new_revid, |
| 493 |
old_branch, new_branch, |
| 494 |
old_tree=get_tree_if_current(old_revid), |
| 495 |
new_tree=get_tree_if_current(new_revid), |
| 496 |
specific_files = specific_files, |
| 497 |
specific_file_ids = specific_file_ids) |
| 498 |
|
| 499 |
diff.show_diff(arg_provider, ext_diff=ext_diff, |
| 500 |
parent_window=self.window(), context=self.diff_context) |
| 501 |
|
| 502 |
def show_diff_specified_files(self, ext_diff=None): |
| 503 |
if self.log_model.file_id_filter: |
| 504 |
self.show_diff( |
| 505 |
ext_diff=ext_diff, |
| 506 |
specific_file_ids = self.log_model.file_id_filter.file_ids) |
| 507 |
else: |
| 508 |
self.show_diff(ext_diff=ext_diff) |
| 509 |
|
| 510 |
def show_diff_ext(self, ext_diff): |
| 511 |
self.show_diff(ext_diff=ext_diff) |
| 512 |
|
| 513 |
def show_diff_specified_files_ext(self, ext_diff=None): |
| 514 |
self.show_diff_specified_files(ext_diff=ext_diff) |
| 515 |
|
| 516 |
def show_revision_tree(self): |
| 517 |
from breezy.plugins.qbrz.lib.browse import BrowseWindow |
| 518 |
revid = self.currentIndex().data(logmodel.RevIdRole) |
| 519 |
gv = self.log_model.graph_viz |
| 520 |
if revid.startswith(CURRENT_REVISION): |
| 521 |
location = gv.working_trees[revid].abspath('') |
| 522 |
window = BrowseWindow(location=location, parent=self) |
| 523 |
else: |
| 524 |
revno = gv.revid_rev[revid].revno_str |
| 525 |
branch = gv.get_revid_branch(revid) |
| 526 |
window = BrowseWindow(branch=branch, revision_id=revid, |
| 527 |
revision_spec=revno, parent=self) |
| 528 |
window.show() |
| 529 |
self.window().windows.append(window) |
| 530 |
|
| 531 |
def show_context_menu(self, pos): |
| 532 |
branch_count = len(self.log_model.graph_viz.branches) |
| 533 |
(top_revid, old_revid), count = \ |
| 534 |
self.get_selection_top_and_parent_revids_and_count() |
| 535 |
|
| 536 |
wt_selected = top_revid.startswith(CURRENT_REVISION) |
| 537 |
|
| 538 |
def filter_rev_ancestor(action, is_ancestor=True): |
| 539 |
branch_menu = action.menu() |
| 540 |
if branch_menu: |
| 541 |
vis_branch_count = branch_menu.filter_rev_ancestor( |
| 542 |
top_revid, is_ancestor) |
| 543 |
if vis_branch_count == 0: |
| 544 |
action.setVisible(False) |
| 545 |
|
| 546 |
if self.view_commands: |
| 547 |
self.context_menu_show_tree.setVisible(count == 1) |
| 548 |
|
| 549 |
if self.action_commands: |
| 550 |
self.context_menu_tag.setVisible(count == 1 and not wt_selected) |
| 551 |
if count == 1: |
| 552 |
filter_rev_ancestor(self.context_menu_tag) |
| 553 |
self.context_menu_revert.setVisible(count == 1 and not wt_selected) |
| 554 |
self.context_menu_update.setVisible(count == 1 and not wt_selected) |
| 555 |
|
| 556 |
if branch_count > 1: |
| 557 |
if wt_selected: |
| 558 |
self.context_menu_cherry_pick.setVisible(False) |
| 559 |
else: |
| 560 |
filter_rev_ancestor(self.context_menu_cherry_pick, |
| 561 |
is_ancestor=False) |
| 562 |
|
| 563 |
if wt_selected: |
| 564 |
self.context_menu_reverse_cherry_pick.setVisible(False) |
| 565 |
else: |
| 566 |
filter_rev_ancestor(self.context_menu_reverse_cherry_pick) |
| 567 |
|
| 568 |
self.context_menu.popup(self.viewport().mapToGlobal(pos)) |
| 569 |
|
| 570 |
|
| 571 |
class BranchMenu(QtWidgets.QMenu): |
| 572 |
bm_triggered = QtCore.pyqtSignal() |
| 573 |
|
| 574 |
def __init__(self, text, parent, graphprovider, require_wt): |
| 575 |
QtWidgets.QMenu.__init__(self, text, parent) |
| 576 |
self.graphprovider = graphprovider |
| 577 |
for branch in self.graphprovider.branches: |
| 578 |
action = QtWidgets.QAction(branch.label, self) |
| 579 |
action.setData(branch) |
| 580 |
self.addAction(action) |
| 581 |
if require_wt and branch.tree is None: |
| 582 |
action.setDisabled(True) |
| 583 |
|
| 584 |
self.triggered[QAction].connect(self.triggered) |
| 585 |
|
| 586 |
def filter_rev_ancestor(self, rev, is_ancestor=True): |
| 587 |
visible_action_count = 0 |
| 588 |
|
| 589 |
for action in self.actions(): |
| 590 |
branch_info = action.data() |
| 591 |
branch_tip = branch_info.branch.last_revision() |
| 592 |
is_ancestor_ = ( |
| 593 |
frozenset((branch_tip,)) == self.graphprovider.known_graph.heads((branch_tip, rev))) |
| 594 |
visible = is_ancestor_ == is_ancestor |
| 595 |
action.setVisible(visible) |
| 596 |
if visible: |
| 597 |
visible_action_count += 1 |
| 598 |
|
| 599 |
return visible_action_count |
| 600 |
|
| 601 |
def triggered(self, action): |
| 602 |
branch_info = action.data() |
| 603 |
self.bm_triggered.emit(branch_info) |
| 604 |
|
| 605 |
|
| 606 |
class GraphTagsBugsItemDelegate(QtWidgets.QStyledItemDelegate): |
| 607 |
|
| 608 |
_twistyColor = QtCore.Qt.black |
| 609 |
|
| 610 |
def paint(self, painter, option, index): |
| 611 |
if index.isValid(): |
| 612 |
draw_graph = True |
| 613 |
data = index.data(logmodel.GraphDataRole) |
| 614 |
c_rev, prev_c_rev, labels, is_clicked = data |
| 615 |
else: |
| 616 |
draw_graph = False |
| 617 |
|
| 618 |
option = QtWidgets.QStyleOptionViewItem(option) |
| 619 |
self.initStyleOption(option, index) |
| 620 |
widget = self.parent() |
| 621 |
style = widget.style() |
| 622 |
|
| 623 |
text_margin = style.pixelMetric(QtWidgets.QStyle.PM_FocusFrameHMargin, None, widget) + 1 |
| 624 |
|
| 625 |
painter.save() |
| 626 |
painter.setClipRect(option.rect) |
| 627 |
style.drawPrimitive(QtWidgets.QStyle.PE_PanelItemViewItem, option, painter, widget) |
| 628 |
|
| 629 |
graphCols = 0 |
| 630 |
rect = option.rect |
| 631 |
if draw_graph: |
| 632 |
painter.save() |
| 633 |
try: |
| 634 |
painter.setRenderHint(QtGui.QPainter.Antialiasing) |
| 635 |
boxsize = float(rect.height()) |
| 636 |
dotsize = 0.7 |
| 637 |
pen = QtGui.QPen() |
| 638 |
penwidth = 1 |
| 639 |
pen.setWidth(penwidth) |
| 640 |
pen.setCapStyle(QtCore.Qt.FlatCap) |
| 641 |
|
| 642 |
painter.translate(0.5, 0.5) |
| 643 |
|
| 644 |
|
| 645 |
if prev_c_rev: |
| 646 |
for start, end, color, direct in prev_c_rev.lines: |
| 647 |
self.drawLine(painter, pen, rect, boxsize, |
| 648 |
rect.y(), boxsize, |
| 649 |
start, end, color, direct) |
| 650 |
graphCols = max((graphCols, min(start, end))) |
| 651 |
|
| 652 |
|
| 653 |
if c_rev: |
| 654 |
for start, end, color, direct in c_rev.lines: |
| 655 |
self.drawLine(painter, pen, rect,boxsize, |
| 656 |
rect.y() + boxsize, boxsize, |
| 657 |
start, end, color, direct) |
| 658 |
graphCols = max((graphCols, min(start, end))) |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
if c_rev.col_index is not None: |
| 663 |
graphCols = max((graphCols, c_rev.col_index)) |
| 664 |
pen.setColor(self.get_color(c_rev.rev.color, False)) |
| 665 |
painter.setPen(pen) |
| 666 |
if not is_clicked: |
| 667 |
painter.setBrush(QtGui.QBrush( |
| 668 |
self.get_color(c_rev.rev.color,True))) |
| 669 |
else: |
| 670 |
painter.setBrush(QtGui.QBrush(QtCore.Qt.white)) |
| 671 |
|
| 672 |
centerx = rect.x() + boxsize * (c_rev.col_index + 0.5) |
| 673 |
centery = rect.y() + boxsize * 0.5 |
| 674 |
painter.drawEllipse( |
| 675 |
QtCore.QRectF(centerx - (boxsize * dotsize * 0.5), |
| 676 |
centery - (boxsize * dotsize * 0.5), |
| 677 |
boxsize * dotsize, boxsize * dotsize)) |
| 678 |
|
| 679 |
|
| 680 |
if not is_clicked and c_rev.twisty_state is not None: |
| 681 |
linesize = 0.35 |
| 682 |
pen.setColor(self._twistyColor) |
| 683 |
painter.setPen(pen) |
| 684 |
|
| 685 |
painter.drawLine(QtCore.QLineF |
| 686 |
(centerx - boxsize * linesize / 2, |
| 687 |
centery, |
| 688 |
centerx + boxsize * linesize / 2, |
| 689 |
centery)) |
| 690 |
if not c_rev.twisty_state: |
| 691 |
painter.drawLine(QtCore.QLineF |
| 692 |
(centerx, |
| 693 |
centery - boxsize * linesize / 2, |
| 694 |
centerx, |
| 695 |
centery + boxsize * linesize / 2)) |
| 696 |
|
| 697 |
finally: |
| 698 |
painter.restore() |
| 699 |
rect.adjust(int((graphCols + 1.5) * boxsize), 0, 0, 0) |
| 700 |
|
| 701 |
painter.save() |
| 702 |
x = 0 |
| 703 |
try: |
| 704 |
tagFont = QtGui.QFont(option.font) |
| 705 |
tagFont.setPointSizeF(tagFont.pointSizeF() * 9 / 10) |
| 706 |
|
| 707 |
for label, bg_color, text_color in labels: |
| 708 |
tagRect = rect.adjusted(1, 1, -1, -1) |
| 709 |
tagRect.setWidth(QtGui.QFontMetrics(tagFont).width(label) + 6) |
| 710 |
tagRect.moveLeft(tagRect.x() + x) |
| 711 |
painter.setPen(bg_color) |
| 712 |
painter.fillRect(tagRect.adjusted(1, 1, -1, -1), bg_color) |
| 713 |
tl = tagRect.topLeft() |
| 714 |
br = tagRect.bottomRight() |
| 715 |
painter.drawLine(tl.x(), tl.y() + 1, tl.x(), br.y() - 1) |
| 716 |
painter.drawLine(br.x(), tl.y() + 1, br.x(), br.y() - 1) |
| 717 |
painter.drawLine(tl.x() + 1, tl.y(), br.x() - 1, tl.y()) |
| 718 |
painter.drawLine(tl.x() + 1, br.y(), br.x() - 1, br.y()) |
| 719 |
painter.setFont(tagFont) |
| 720 |
painter.setPen(text_color) |
| 721 |
painter.drawText(tagRect.left() + 3, tagRect.bottom() - option.fontMetrics.descent() + 1, label) |
| 722 |
x += tagRect.width() + text_margin |
| 723 |
finally: |
| 724 |
painter.restore() |
| 725 |
rect.adjust(x, 0, 0, 0) |
| 726 |
|
| 727 |
if option.text: |
| 728 |
painter.setPen(get_text_color(option, style)) |
| 729 |
text_rect = rect.adjusted(0, 0, -text_margin, 0) |
| 730 |
painter.setFont(option.font) |
| 731 |
fm = painter.fontMetrics() |
| 732 |
text_width = fm.width(option.text) |
| 733 |
text = option.text |
| 734 |
if text_width > text_rect.width(): |
| 735 |
|
| 736 |
text = fm.elidedText(text, QtCore.Qt.ElideRight, text_rect.width()) |
| 737 |
|
| 738 |
painter.drawText(text_rect, QtCore.Qt.AlignLeft, text) |
| 739 |
|
| 740 |
painter.restore() |
| 741 |
|
| 742 |
def get_color(self, color, back): |
| 743 |
qcolor = QtGui.QColor() |
| 744 |
if color == 0: |
| 745 |
if back: |
| 746 |
qcolor.setHsvF(0,0,0.8) |
| 747 |
else: |
| 748 |
qcolor.setHsvF(0,0,0) |
| 749 |
else: |
| 750 |
h = float(color % 6) / 6 |
| 751 |
if back: |
| 752 |
qcolor.setHsvF(h,0.4,1) |
| 753 |
else: |
| 754 |
qcolor.setHsvF(h,1,0.7) |
| 755 |
|
| 756 |
return qcolor |
| 757 |
|
| 758 |
def drawLine(self, painter, pen, rect, boxsize, mid, height, |
| 759 |
start, end, color, direct): |
| 760 |
pen.setColor(self.get_color(color,False)) |
| 761 |
if direct: |
| 762 |
pen.setStyle(QtCore.Qt.SolidLine) |
| 763 |
else: |
| 764 |
pen.setStyle(QtCore.Qt.DotLine) |
| 765 |
painter.setPen(pen) |
| 766 |
startx = round(rect.x() + boxsize * start + boxsize / 2) |
| 767 |
endx = round(rect.x() + boxsize * end + boxsize / 2) |
| 768 |
|
| 769 |
path = QtGui.QPainterPath() |
| 770 |
path.moveTo(QtCore.QPointF(startx, mid - height / 2)) |
| 771 |
|
| 772 |
if start - end == 0: |
| 773 |
path.lineTo(QtCore.QPointF(endx, mid + height / 2)) |
| 774 |
else: |
| 775 |
path.cubicTo(QtCore.QPointF(startx, mid - height / 5), |
| 776 |
QtCore.QPointF(startx, mid - height / 5), |
| 777 |
QtCore.QPointF(startx + (endx - startx) / 2, mid)) |
| 778 |
|
| 779 |
path.cubicTo(QtCore.QPointF(endx, mid + height / 5), |
| 780 |
QtCore.QPointF(endx, mid + height / 5), |
| 781 |
QtCore.QPointF(endx, mid + height / 2 + 1)) |
| 782 |
painter.drawPath(path) |
| 783 |
pen.setStyle(QtCore.Qt.SolidLine) |
| 784 |
|
| 785 |
def sizeHint(self, option, index): |
| 786 |
size = QtWidgets.QStyledItemDelegate.sizeHint(self, option, index) |
| 787 |
height = size.height() |
| 788 |
|
| 789 |
if height < 14: |
| 790 |
height = 14 |
| 791 |
|
| 792 |
|
| 793 |
if height % 2 == 1: |
| 794 |
height += 1 |
| 795 |
|
| 796 |
size.setHeight(height) |
| 797 |
return size |