From: "Berislav Lopac via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Berislav Lopac <berislav@lopac.net>, Berislav Lopac <berislav@lopac.net>
Subject: [PATCH] git-p4: ignore binary file diffs in git-p4 commit
Date: Tue, 22 Sep 2020 08:31:36 +0000 [thread overview]
Message-ID: <pull.833.git.git.1600763496510.gitgitgadget@gmail.com> (raw)
From: Berislav Lopac <berislav@lopac.net>
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`.
Signed-off-by: Berislav Lopac <berislav@lopac.net>
---
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(-)
diff --git a/git-p4.py b/git-p4.py
index 9a71a6690d..3d72a0dbdb 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -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
--
gitgitgadget
reply other threads:[~2020-09-22 8:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.833.git.git.1600763496510.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=berislav@lopac.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox