timbrel / GitSavvy

Full git and GitHub integration with Sublime Text
MIT License
1.9k stars 135 forks source link

Disable inline diff for binaries (images) #579

Open franciscolourenco opened 7 years ago

franciscolourenco commented 7 years ago

If you accidentally try to inline-diff an image, sublime starts opening popups until it freezes.

randy3k commented 7 years ago

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
asfaltboy commented 7 years ago

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)

stoivo commented 6 years ago

@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?

asfaltboy commented 6 years ago

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

stoivo commented 6 years ago

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.