GitSavvy
GitSavvy copied to clipboard
Disable inline diff for binaries (images)
If you accidentally try to inline-diff an image, sublime starts opening popups until it freezes.
Is this sufficient to check if a file is binary?
def is_valid_unicode(file_name):
with open(file_name, "r") as f:
try:
# read the first 512 bytes
block = f.read(512)
return True
except UnicodeDecodeError:
return False
I feel this would be better solved by generally marking the "decode error" and aborting command in case we depend on it to work correctly. I'll submit a PR demonstrating what I mean (edit: when I get a bit more time)
@asfaltboy Why don't you open a PR for this?
https://github.com/divmain/GitSavvy/compare/dev...asfaltboy:feature/inline-diff-loop-579?expand=1
The conflict only pycodestyle fixes for something you changes too?
To be honest I haven't touched that code in so long I can't even read it and understand the intent ... possibly this indicates bad code (or at least a code smell) ...
Though, we can create the PR right now and discuss it's usability and refactoring for readability ?
Edit: I think those changes are referring to code that was initially there but we refactored later... this is how it looks today: https://github.com/asfaltboy/GitSavvy/blob/master/core/git_command.py#L170-L179
We should use python-magic, is does what we need, but we need to enable it as a dependency, which I don't think is done yet.