Skip to content

Commit

Permalink
Merge pull request #1929 from timbrel/create-scratch-view
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste committed Jun 17, 2024
2 parents a42590f + 7dc57bc commit 8bc4841
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions core/commands/show_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ..parse_diff import SplittedDiff, TextRange
from ..runtime import ensure_on_ui, enqueue_on_worker
from ..view import replace_view_content, Position
from ...common import util

from GitSavvy.github import github
from GitSavvy.github.git_mixins import GithubRemotesMixin
Expand Down Expand Up @@ -62,36 +63,33 @@ def compute_identifier_for_view(view):
class gs_show_commit(WindowCommand, GitCommand):

def run(self, commit_hash):
# need to get repo_path before the new view is created.
repo_path = self.repo_path
if commit_hash in {"", "HEAD"}:
commit_hash = self.git("rev-parse", "--short", "HEAD").strip()

this_id = (
self.repo_path,
repo_path,
commit_hash
)
for view in self.window.views():
if compute_identifier_for_view(view) == this_id:
focus_view(view)
break
else:
view = self.window.new_file()
settings = view.settings()
settings.set("git_savvy.show_commit_view", True)
settings.set("git_savvy.show_commit_view.commit", commit_hash)
settings.set("git_savvy.repo_path", repo_path)
settings.set("git_savvy.show_commit_view.ignore_whitespace", False)
settings.set("git_savvy.show_commit_view.show_diffstat", self.savvy_settings.get("show_diffstat", True))

settings.set("result_file_regex", diff.FILE_RE)
settings.set("result_line_regex", diff.LINE_RE)
settings.set("result_base_dir", repo_path)

view.set_syntax_file("Packages/GitSavvy/syntax/show_commit.sublime-syntax")
view.set_name(SHOW_COMMIT_TITLE.format(self.get_short_hash(commit_hash)))
view.set_scratch(True)
view.set_read_only(True)
title = SHOW_COMMIT_TITLE.format(self.get_short_hash(commit_hash))
view = util.view.create_scratch_view(self.window, "show_commit", {
"title": title,
"syntax": "Packages/GitSavvy/syntax/show_commit.sublime-syntax",
"git_savvy.repo_path": repo_path,
"git_savvy.show_commit_view.commit": commit_hash,
"git_savvy.show_commit_view.ignore_whitespace": False,
"git_savvy.show_commit_view.show_diffstat":
self.savvy_settings.get("show_diffstat", True),
"result_file_regex": diff.FILE_RE,
"result_line_regex": diff.LINE_RE,
"result_base_dir": repo_path,
})

view.run_command("gs_show_commit_refresh")
view.run_command("gs_handle_vintageous")

Expand Down

0 comments on commit 8bc4841

Please sign in to comment.