Skip to content
6 changes: 2 additions & 4 deletions core/commands/blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,11 @@ def run(self, edit):

def get_content(self, file_path, ignore_whitespace=False, detect_options=None, commit_hash=None):
if commit_hash and self.savvy_settings.get("blame_follow_rename"):
filename_at_commit = self.filename_at_commit(file_path, commit_hash)
else:
filename_at_commit = file_path
file_path = self.filename_at_commit(file_path, commit_hash)

blame_porcelain = self.git(
"blame", "-p", '-w' if ignore_whitespace else None, detect_options,
commit_hash, "--", filename_at_commit
commit_hash, "--", file_path
)
blame_porcelain = unicodedata.normalize('NFC', blame_porcelain)
blamed_lines, commits = self.parse_blame(blame_porcelain.split('\n'))
Expand Down
10 changes: 9 additions & 1 deletion core/commands/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,13 @@ def blame_file_atcommit(self):
})

def checkout_file_at_commit(self):
self.checkout_ref(self._commit_hash, fpath=self._file_path)
commit_hash = self._commit_hash
file_path = self._file_path

if commit_hash and file_path and self.savvy_settings.get("log_follow_rename"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point all three predicates should be True all the time if I'm reading this correctly.

There is also

def checkout_file_at_commit(self, commit_hash, file_path):
self.checkout_ref(commit_hash, fpath=file_path)
util.view.refresh_gitsavvy_interfaces(self.window)
which would need the same patch I think.

Copy link
Author

@kylebebak kylebebak Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the three expressions in the if statement, if commit_hash and file_path and self.savvy_settings.get("log_follow_rename"):?

Type checker says file_path is Unknown | None in line 254 above, and self.filename_at_commit takes (str, str), so I figured I'd just make sure both were truthy

As for self.savvy_settings.get("log_follow_rename"), that's a user setting that's not guaranteed to be truthy in general, right?


Agreed on making same patch in log_graph.py` module, I'll do that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for self.savvy_settings.get("log_follow_rename"), that's a user setting that's not guaranteed to be truthy in general, right?

Ah right, looks like log_follow_rename can be False still, but self._commit_hash is always truthy here and self._file_path too otherwise the menu item would not appear (see def update_actions(self)).

filename_at_commit = self.filename_at_commit(file_path, commit_hash)
else:
filename_at_commit = file_path

self.checkout_ref(self._commit_hash, fpath=filename_at_commit)
util.view.refresh_gitsavvy_interfaces(self.window, refresh_sidebar=True)
3 changes: 3 additions & 0 deletions core/commands/log_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@
needle in line.hash
or needle == line.decoration
or f" {needle}" in line.decoration
or f"{needle}," in line.decoration

Check failure on line 872 in core/commands/log_graph.py

View workflow job for this annotation

GitHub Actions / lint

missing whitespace after ','
)

def process_graph(lines):
Expand Down Expand Up @@ -943,7 +943,7 @@

def trunc(text, width):
# type: (str, int) -> str
return f"{text[:width - 2]}.." if len(text) > width else f"{text:{width}}"

Check failure on line 946 in core/commands/log_graph.py

View workflow job for this annotation

GitHub Actions / lint

missing whitespace after ':'

def resolve_refs_from_the_logs():
# type: () -> Dict[str, str]
Expand Down Expand Up @@ -3240,5 +3240,8 @@
})

def checkout_file_at_commit(self, commit_hash, file_path):
if self.savvy_settings.get("log_follow_rename"):
file_path = self.filename_at_commit(file_path, commit_hash)

self.checkout_ref(commit_hash, fpath=file_path)
util.view.refresh_gitsavvy_interfaces(self.window)
3 changes: 3 additions & 0 deletions core/commands/show_file_at_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def run(self, edit: sublime.Edit, position: Position = None, sync: bool = True)
file_path = settings.get("git_savvy.file_path")
commit_hash = settings.get("git_savvy.show_file_at_commit_view.commit")

if commit_hash and self.savvy_settings.get("log_follow_rename"):
file_path = self.filename_at_commit(file_path, commit_hash)

def program():
text = self.get_file_content_at_commit(file_path, commit_hash)
render(view, text, position)
Expand Down
Loading