"dorgon chang via GitGitGadget" <gitgitgadget@xxxxxxxxx> writes: > From: "dorgon.chang" <dorgonman@xxxxxxxxxxx> > > If the submit contain binary files, it will throw exception and > stop submit when try to append diff line description. OK, that explains how the program fails. > This commit will skip non-text data files when exception > UnicodeDecodeError thrown. If there are changes in aText and aBinary file and you try to submit a cl that contains both changes, you do want changes to both files go together, no? If you skip non-text, does that mean you ignore the changes to aBinary file and submit only the changes to aText file? I guess my confusion comes from not understanding what you exactly mean by "append diff line description". Whatever that means, if that is purely informational and does not affect what is actually submit in the resulting cl, then the patch would be an improvement. If not, and if for example it loses changes to binary files, then it is merely sweeping the problem under the rug. In short the explanation of the solution does not build confidence in the readers minds. You'd need to explain why such a skipping is a safe thing to do a bit better. Even if we assuming that what happens in the loop you threw in try/except block is purely cosmetic and optional thing that does not affect the correct operation of the program or its outcome, I wonder if we can do better. When you get a decode error, you'd have an early part of the change (which could be empty) before you hit the error in newdiff, and that is returned to the caller without any sign that it is a truncated output. I wonder something like except UnicodeDecodeError: newdiff = '<<new binary file>>' may be more helpful to the user. Assuming that this is purely for human consumption without affecting the correctness or outcome of the program and we can place pretty much any text there, that is. But because the proposed commit log message does not explain why skipping is safe, I do not know if that assumption holds in the first place. Thanks. > diff --git a/git-p4.py b/git-p4.py > index 4433ca53de7e..29a8c202399a 100755 > --- a/git-p4.py > +++ b/git-p4.py > @@ -1977,8 +1977,11 @@ 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 > + try: > + for line in f.readlines(): > + newdiff += "+" + line > + except UnicodeDecodeError: > + pass # Fond non-text data s/Fond/Found/ I would think. > f.close() > > return (diff + newdiff).replace('\r\n', '\n') > > base-commit: d4a392452e292ff924e79ec8458611c0f679d6d4