git-p4: ignore binary file diffs in git-p4 commit
PATCH 1/1 git-p4: ignore binary file diffs in git-p4 commit
From: Berislav Lopac <[email protected]>
Currently, when submitting commits, git p4 submit helpfully builds a diff of changes, and then displays them in a text editor before continuing (mimicking standard git commit behaviour). For changed files it asks p4 for the diff, but if a file is added it dumps all of its lines; to do so it opens a file, but as a text -- which obviously fails if a file is binary, raising UnicodeDecodeError.
---
ignore binary file diffs in git-p4 commit
Currently, when submitting commits, git p4 submit helpfully builds a diff of changes, and then displays them in a text editor before continuing (mimicking standard git commit behaviour). For changed files it asks git for the diff, but if a file is added it dumps all of its lines; to do so it opens a file, but as a text -- which obviously fails if a file is binary, raising UnicodeDecodeError.
This simple patch catches that exception and stops building the diff, so only the name of the added file is included.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-833%2Fberislavlopac%2Fignore-binary-file-diffs-in-git-p4-commit-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-833/berislavlopac/ignore-binary-file-diffs-in-git-p4-commit-v1
Pull-Request: https://github.com/git/git/pull/833
git-p4.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
git-p4.py +7 -3
@@ -1847,9 +1847,13 @@ def get_diff_description(self, editedFiles, filesToAdd, symlinks): newdiff += "+%s\n" % os.readlink(newFile) else: f = open(newFile, "r") - for line in f.readlines(): - newdiff += "+" + line - f.close() + try: + for line in f.readlines(): + newdiff += "+" + line + except UnicodeDecodeError: + pass + finally: + f.close() return (diff + newdiff).replace('\r\n', '\n')
base-commit: af6b65d45ef179ed52087e80cb089f6b2349f4ec
Signature · 1 line
gitgitgadget