diff --git a/Default.sublime-commands b/Default.sublime-commands index 592f33d1e..ceae12e69 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -97,6 +97,10 @@ "caption": "git: Line History", "command": "gs_line_history" }, + { + "caption": "git: Pick-axe selection", + "command": "gs_graph_pickaxe" + }, { "caption": "github: open file on remote", "command": "gs_github_open_file_on_remote", diff --git a/core/commands/log_graph.py b/core/commands/log_graph.py index 89ab3cd5e..80834f921 100644 --- a/core/commands/log_graph.py +++ b/core/commands/log_graph.py @@ -7,6 +7,7 @@ import re import shlex import subprocess +import textwrap import time import threading from typing import NamedTuple @@ -42,7 +43,7 @@ ) from ..ui_mixins.input_panel import show_single_line_input_panel from ..ui_mixins.quick_panel import show_branch_panel -from ..utils import add_selection_to_jump_history, focus_view, show_toast, Cache, SEPARATOR +from ..utils import add_selection_to_jump_history, flash, focus_view, show_toast, Cache, SEPARATOR from ...common import util from ...common.theme_generator import ThemeGenerator @@ -50,6 +51,7 @@ __all__ = ( "gs_graph", "gs_graph_current_file", + "gs_graph_pickaxe", "gs_log_graph_refresh", "gs_log_graph", "gs_log_graph_tab_out", @@ -247,6 +249,28 @@ def run(self, **kwargs): self.window.status_message("View has no filename to track.") +class gs_graph_pickaxe(TextCommand, GitCommand): + def run(self, edit): + # type: (sublime.Edit) -> None + view = self.view + window = view.window() + if not window: + return + repo_path = self.repo_path + frozen_sel = list(view.sel()) + filters = " ".join( + shlex.quote("-S{}".format(s)) + for r in frozen_sel + if (s := view.substr(r)) + if (s.strip()) + ) + if not filters: + flash(view, "Nothing selected.") + return + + window.run_command("gs_graph", {"repo_path": repo_path, "filters": filters}) + + def augment_color_scheme(view): # type: (sublime.View) -> None settings = GitSavvySettings() @@ -1317,6 +1341,30 @@ def prelude(view): elif repo_path: prelude += " REPO: {}\n".format(repo_path) + if apply_filters: + pickaxes, normal_ones = [], [] + for arg in shlex.split(filters): + if arg.startswith("-S") or arg.startswith("-G"): + if "\n" in arg: + pickaxes.append( + "\n {}'''\n{}\n '''".format( + arg[:2], + textwrap.indent(textwrap.dedent(arg[2:].rstrip()), " ") + ) + ) + else: + normal_ones.append( + "{}'{}'".format( + arg[:2], + arg[3:-1] if (arg[2], arg[-1]) == ("'", "'") else arg[2:] + ) + ) + else: + normal_ones.append(arg) + formatted_filters = "\n".join(filter_((" ".join(normal_ones), "".join(pickaxes)))) + else: + formatted_filters = None + prelude += ( " " + " ".join(filter_(( @@ -1326,7 +1374,7 @@ def prelude(view): else '[a]ll: true' if all_branches else '[a]ll: false' ), " ".join(branches) if not all_branches and not overview else None, - filters if apply_filters else None + formatted_filters ))) ) return prelude + "\n\n" diff --git a/syntax/graph.sublime-syntax b/syntax/graph.sublime-syntax index 401ebabee..58d118893 100644 --- a/syntax/graph.sublime-syntax +++ b/syntax/graph.sublime-syntax @@ -12,13 +12,20 @@ variables: contexts: main: - - match: ^ - push: - - meta_scope: meta.prelude.git_savvy.graph - - match: '^(?=\S)' - set: graph - - match: .* - scope: comment.prelude.git_savvy.graph + - match: '^$\n' + set: prelude + + prelude: + - meta_scope: meta.prelude.git_savvy.graph + - match: .* + scope: comment.prelude.git_savvy.graph + - match: '^$\n' + set: prelude_end + + prelude_end: + - meta_scope: meta.prelude.git_savvy.graph + - match: '^(?=\S)' + set: graph graph: - meta_scope: meta.content.git_savvy.graph diff --git a/syntax/test/syntax_test_graph.txt b/syntax/test/syntax_test_graph.txt index a1ba762ba..b0e5c77c1 100644 --- a/syntax/test/syntax_test_graph.txt +++ b/syntax/test/syntax_test_graph.txt @@ -1,5 +1,12 @@ # SYNTAX TEST "Packages/GitSavvy/syntax/graph.sublime-syntax" + +# <- meta.prelude + REPO: C:\Users\c-flo\AppData\Roaming\Sublime Text\Packages\SublimeLinter + [a]ll: true + +# <- meta.prelude * 2b17192 (HEAD -> develop, origin/master, origin/HEAD, master) replace all references to .tmLanguage to .sublime-syntax +# <- meta.content # <- keyword.graph.commit # ^ constant.numeric.graph.commit-hash # ^^^^ constant.other.git.head diff --git a/syntax/test/syntax_test_graph_pick_axe.txt b/syntax/test/syntax_test_graph_pick_axe.txt new file mode 100644 index 000000000..3f6558e39 --- /dev/null +++ b/syntax/test/syntax_test_graph_pick_axe.txt @@ -0,0 +1,27 @@ +# SYNTAX TEST "Packages/GitSavvy/syntax/graph.sublime-syntax" + + REPO: C:\Users\c-flo\AppData\Roaming\Sublime Text\Packages\GitSavvy + [a]ll: false + -S''' + class gs_revert_commit(LogMixin, WindowCommand, GitCommand): +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ git-savvy.graph meta.prelude.git_savvy.graph comment.prelude.git_savvy.graph + @on_worker +# ^^^^^^^^^^^^^^^^ git-savvy.graph meta.prelude.git_savvy.graph comment.prelude.git_savvy.graph + def do_action(self, commit_hash, **kwargs): +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ git-savvy.graph meta.prelude.git_savvy.graph comment.prelude.git_savvy.graph + try: +# ^^^^^^^^^^^^^^ git-savvy.graph meta.prelude.git_savvy.graph comment.prelude.git_savvy.graph + self.git("revert", *(commit_hash if isinstance(commit_hash, list) else [commit_hash])) +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ git-savvy.graph meta.prelude.git_savvy.graph comment.prelude.git_savvy.graph + finally: +# ^^^^^^^^^^^^^^^^^^ git-savvy.graph meta.prelude.git_savvy.graph comment.prelude.git_savvy.graph + util.view.refresh_gitsavvy(self.window.active_view(), refresh_sidebar=True) +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ git-savvy.graph meta.prelude.git_savvy.graph comment.prelude.git_savvy.graph + ''' +# ^^^ git-savvy.graph meta.prelude.git_savvy.graph comment.prelude.git_savvy.graph + +#< git-savvy.graph meta.prelude.git_savvy.graph +... +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ git-savvy.graph meta.content.git_savvy.graph +● 96c5f826 Allow to revert multiple commits in one invocation ​ Thu May 2 21:44, herr kaste +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ git-savvy.graph meta.content.git_savvy.graph