Skip to content

Commit

Permalink
Merge pull request #1954 from timbrel/iter-diff
Browse files Browse the repository at this point in the history
Teach the diff view to open from inline diffs and historical files
  • Loading branch information
kaste authored Nov 27, 2024
2 parents f3cab3d + 548e79c commit cf2e695
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions core/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sublime
from sublime_plugin import WindowCommand, TextCommand, EventListener

from . import inline_diff
from . import intra_line_colorizer
from . import stage_hunk
from .navigate import GsNavigate
Expand Down Expand Up @@ -170,17 +171,42 @@ def run(
base_commit,
target_commit
)

if compute_identifier_for_view(active_view) == this_id and (
active_views_id = compute_identifier_for_view(active_view) or ()
if (
active_views_id[:2] == this_id[:2]
if base_commit is None and target_commit is None
else active_views_id == this_id
) and (
in_cached_mode is None
or active_view.settings().get('git_savvy.diff_view.in_cached_mode') == in_cached_mode
):
active_view.close()
return

av_fname = active_view.file_name()
cur_pos = None
if av_fname:
if active_view.settings().get("git_savvy.inline_diff_view"):
if base_commit is None and target_commit is None:
base_commit = active_view.settings().get("git_savvy.inline_diff_view.base_commit")
target_commit = active_view.settings().get("git_savvy.inline_diff_view.target_commit")
disable_stage = base_commit or target_commit
if in_cached_mode is None:
in_cached_mode = active_view.settings().get("git_savvy.inline_diff_view.in_cached_mode")
if _cur_pos := capture_cur_position(active_view):
rel_file_path = self.get_rel_path(file_path)
row, col, offset = _cur_pos
line_no, col_no = inline_diff.translate_pos_from_diff_view_to_file(active_view, row + 1, col + 1)
cur_pos = Position(line_no - 1, col_no - 1, offset), rel_file_path

elif active_view.settings().get("git_savvy.show_file_at_commit_view"):
if base_commit is None and target_commit is None:
target_commit = active_view.settings().get("git_savvy.show_file_at_commit_view.commit")
base_commit = self.previous_commit(target_commit, file_path)
disable_stage = True
if _cur_pos := capture_cur_position(active_view):
rel_file_path = self.get_rel_path(file_path)
cur_pos = _cur_pos, rel_file_path

elif av_fname := active_view.file_name():
if _cur_pos := capture_cur_position(active_view):
rel_file_path = self.get_rel_path(av_fname)
if in_cached_mode:
Expand Down Expand Up @@ -279,7 +305,7 @@ def run_impl(self, runs_on_ui_thread, match_position):
diff = self.strict_decode(raw_diff)
except UnicodeDecodeError:
diff = DECODE_ERROR_MESSAGE
diff += "\n-- Partially decoded output follows; � denotes decoding errors --\n\n"""
diff += "\n-- Partially decoded output follows; � denotes decoding errors --\n\n"
diff += raw_diff.decode("utf-8", "replace")

if not diff and settings.get("git_savvy.diff_view.just_hunked"):
Expand Down

0 comments on commit cf2e695

Please sign in to comment.