From: dorgon.chang Date: Mon, 21 Jun 2021 05:16:13 +0000 (+0000) Subject: git-p4: fix failed submit by skip non-text data files X-Git-Tag: v2.33.0-rc0~61^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=54662d595846dae8884c6b5f9be084e10ada9e4e;p=thirdparty%2Fgit.git git-p4: fix failed submit by skip non-text data files If the submit contain binary files, it will throw exception and stop submit when try to append diff line description. This commit will skip non-text data files when exception UnicodeDecodeError thrown. The skip will not affect actual submit files in the resulting cl, the diff line description will only appear in submit template, so you can review what changed before actully submit to p4. I don't know if add any message here will be helpful for users, so I choose to just skip binary content, since it already append filename previously. Signed-off-by: dorgon.chang Signed-off-by: Junio C Hamano --- diff --git a/git-p4.py b/git-p4.py index d34a1946b7..2b4500226a 100755 --- a/git-p4.py +++ b/git-p4.py @@ -1977,8 +1977,11 @@ class P4Submit(Command, P4UserMap): newdiff += "+%s\n" % os.readlink(newFile) else: f = open(newFile, "r") - for line in f.readlines(): - newdiff += "+" + line + try: + for line in f.readlines(): + newdiff += "+" + line + except UnicodeDecodeError: + pass # Found non-text data and skip, since diff description should only include text f.close() return (diff + newdiff).replace('\r\n', '\n')