From 1705c3a2143f610f0644ea9cc7cfd3591f569288 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Mon, 26 Dec 2011 23:40:44 -0800 Subject: [PATCH] main: Simplify the "Diff->SHA-1" action Use a modal dialog instead of changing the mode of the main interface when diffing against arbitrary revisions. This uses the difftool module to diff commits and eliminates another "diff mode" use case. Signed-off-by: David Aguilar --- cola/classic/view.py | 2 +- cola/cmds.py | 8 -------- cola/guicmds.py | 20 ++++++++++---------- cola/main/model.py | 4 +--- cola/main/view.py | 7 +++---- cola/signals.py | 1 - 6 files changed, 15 insertions(+), 27 deletions(-) diff --git a/cola/classic/view.py b/cola/classic/view.py index 52eaaac0..ab6240b5 100644 --- a/cola/classic/view.py +++ b/cola/classic/view.py @@ -49,7 +49,7 @@ class RepoDialog(standard.Dialog): self.setToolTip(msg) title = '%s [%s]' % (self.model.project, branch) - if self.mode in (self.model.mode_diff, self.model.mode_diff_expr): + if self.mode == self.model.mode_diff_expr: title += ' *** diff mode***' elif self.mode == self.model.mode_amend: title += ' *** amending ***' diff --git a/cola/cmds.py b/cola/cmds.py index 1988e9a4..afea0196 100644 --- a/cola/cmds.py +++ b/cola/cmds.py @@ -370,13 +370,6 @@ class Diff(Command): cached=cached, **opts) -class DiffMode(HeadChangeCommand): - """Enter diff mode and clear the model's diff text.""" - def __init__(self, treeish): - HeadChangeCommand.__init__(self, treeish) - self.new_mode = self.model.mode_diff - - class DiffExprMode(HeadChangeCommand): """Enter diff-expr mode and clear the model's diff text.""" def __init__(self, treeish): @@ -900,7 +893,6 @@ def register(): signals.delete: Delete, signals.delete_branch: DeleteBranch, signals.diff: Diff, - signals.diff_mode: DiffMode, signals.diff_expr_mode: DiffExprMode, signals.diff_staged: DiffStaged, signals.diffstat: Diffstat, diff --git a/cola/guicmds.py b/cola/guicmds.py index 9bbf0909..6d841c74 100644 --- a/cola/guicmds.py +++ b/cola/guicmds.py @@ -54,15 +54,12 @@ def branch_delete(): cola.notifier().broadcast(signals.delete_branch, branch) -def branch_diff(): - """Diff against an arbitrary revision, branch, tag, etc.""" - branch = choose_from_combo('Select Branch, Tag, or Commit-ish', - ['HEAD^'] + - cola.model().all_branches() + - cola.model().tags) - if not branch: +def diff_revision(): + """Diff an arbitrary revision against the worktree""" + ref = choose_ref('Select Revision to Diff', 'Diff', pre=['HEAD^']) + if not ref: return - cola.notifier().broadcast(signals.diff_mode, branch) + difftool.diff_commits(qtutils.active_window(), ref, None) def browse_current(): @@ -222,9 +219,12 @@ def rebase(): qtutils.log(status, output) -def choose_ref(title, button_text): +def choose_ref(title, button_text, pre=None): + provider = None + if pre: + provider = qt.GitRefProvider(pre=pre) parent = qtutils.active_window() - return qt.GitRefDialog.ref(title, button_text, parent) + return qt.GitRefDialog.ref(title, button_text, parent, provider=provider) def review_branch(): diff --git a/cola/main/model.py b/cola/main/model.py index a471350f..e890d841 100644 --- a/cola/main/model.py +++ b/cola/main/model.py @@ -3,7 +3,6 @@ """ import os -import time import copy from cola import core @@ -45,11 +44,10 @@ class MainModel(Observable): mode_index = 'index' # Comparing index to last commit mode_amend = 'amend' # Amending a commit mode_grep = 'grep' # We ran Search -> Grep - mode_diff = 'diff' # Diffing against an arbitrary branch mode_diff_expr = 'diff_expr' # Diffing using arbitrary expression # Modes where we don't do anything like staging, etc. - modes_read_only = (mode_grep, mode_diff, mode_diff_expr) + modes_read_only = (mode_grep, mode_diff_expr) # Modes where we can checkout files from the $head modes_undoable = (mode_none, mode_index, mode_worktree) diff --git a/cola/main/view.py b/cola/main/view.py index c8cef284..360052e1 100644 --- a/cola/main/view.py +++ b/cola/main/view.py @@ -232,7 +232,7 @@ class MainView(standard.MainWindow): 'About', launch_about_dialog) self.menu_branch_diff = add_action(self, - 'SHA-1...', guicmds.branch_diff) + 'SHA-1...', guicmds.diff_revision) self.menu_diff_expression = add_action(self, 'Expression...', guicmds.diff_expression) self.menu_branch_compare = add_action(self, @@ -437,8 +437,7 @@ class MainView(standard.MainWindow): def _mode_changed(self, mode): """React to mode changes; hide/show the "Exit Diff Mode" button.""" - if mode in (self.model.mode_diff, - self.model.mode_diff_expr): + if mode == self.model.mode_diff_expr: height = self.stage_button.minimumHeight() self.alt_button.setMinimumHeight(height) self.alt_button.show() @@ -497,7 +496,7 @@ class MainView(standard.MainWindow): self.commitdockwidget.setToolTip(msg) title = '%s: %s' % (self.model.project, branch) - if self.mode in (self.model.mode_diff, self.model.mode_diff_expr): + if self.mode == self.model.mode_diff_expr: title += ' *** diff mode***' elif self.mode == self.model.mode_amend: title += ' *** amending ***' diff --git a/cola/signals.py b/cola/signals.py index 5e7606b7..8563944d 100644 --- a/cola/signals.py +++ b/cola/signals.py @@ -17,7 +17,6 @@ ignore = 'ignore' delete_branch = 'delete_branch' diff = 'diff' diff_expr_mode = 'diff_expr_mode' -diff_mode = 'diff_mode' diff_staged = 'diff_staged' diffstat = 'diffstat' difftool = 'difftool' -- 2.11.4.GIT