{"thread":{"id":"54272","subject":"[PATCH] git-p4: ignore binary file diffs in git-p4 commit","startedAt":"2020-09-22T08:31:42Z","lastAt":"2020-09-22T08:31:42Z","messageCount":1,"participants":["Berislav Lopac via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"406115","messageId":"pull.833.git.git.1600763496510.gitgitgadget@gmail.com","threadId":"54272","inReplyTo":null,"subject":"[PATCH] git-p4: ignore binary file diffs in git-p4 commit","fromName":"Berislav Lopac via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2020-09-22T08:31:36Z","receivedAt":"2020-09-22T08:31:42Z","isPatch":true,"sender":{"key":"name:Berislav Lopac","avatar":null},"body":"From: Berislav Lopac <berislav@lopac.net>\n\nCurrently, when submitting commits, `git p4 submit` helpfully builds a\ndiff of changes, and then displays them in a text editor before\ncontinuing (mimicking standard git commit behaviour). For changed files\nit asks p4 for the diff, but if a file is added it dumps all of its\nlines; to do so it opens a file, but as a text -- which obviously fails\nif a file is binary, raising `UnicodeDecodeError`.\nSigned-off-by: Berislav Lopac <berislav@lopac.net>\n---\n    ignore binary file diffs in git-p4 commit\n    \n    Currently, when submitting commits, git p4 submit helpfully builds a\n    diff of changes, and then displays them in a text editor before\n    continuing (mimicking standard git commit behaviour). For changed files\n    it asks git for the diff, but if a file is added it dumps all of its\n    lines; to do so it opens a file, but as a text -- which obviously fails\n    if a file is binary, raising UnicodeDecodeError.\n    \n    This simple patch catches that exception and stops building the diff, so\n    only the name of the added file is included.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-833%2Fberislavlopac%2Fignore-binary-file-diffs-in-git-p4-commit-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-833/berislavlopac/ignore-binary-file-diffs-in-git-p4-commit-v1\nPull-Request: https://github.com/git/git/pull/833\n\n git-p4.py | 10 +++++++---\n 1 file changed, 7 insertions(+), 3 deletions(-)\n\ndiff --git a/git-p4.py b/git-p4.py\nindex 9a71a6690d..3d72a0dbdb 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -1847,9 +1847,13 @@ def get_diff_description(self, editedFiles, filesToAdd, symlinks):\n                 newdiff += \"+%s\\n\" % os.readlink(newFile)\n             else:\n                 f = open(newFile, \"r\")\n-                for line in f.readlines():\n-                    newdiff += \"+\" + line\n-                f.close()\n+                try:\n+                    for line in f.readlines():\n+                        newdiff += \"+\" + line\n+                except UnicodeDecodeError:\n+                    pass\n+                finally:\n+                    f.close()\n \n         return (diff + newdiff).replace('\\r\\n', '\\n')\n \n\nbase-commit: af6b65d45ef179ed52087e80cb089f6b2349f4ec\n-- \ngitgitgadget\n"}]}