git-p4: git-p4.fallbackEncoding to specify non UTF-8 charset
authorTzadik Vanderhoof <tzadik.vanderhoof@gmail.com>
Thu, 29 Apr 2021 07:39:05 +0000 (00:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 30 Apr 2021 04:22:57 +0000 (13:22 +0900)
commit51a0478d2c65df251d69dda959f15260a5fbe50b
tree57e2b8c9d331c28ee1782cf13678fbc01a2295ee
parent311531c9de557d25ac087c1637818bd2aad6eb3a
git-p4: git-p4.fallbackEncoding to specify non UTF-8 charset

Add git-p4.fallbackEncoding config variable, to prevent git-p4 from
crashing on non UTF-8 changeset descriptions.

When git-p4 reads the output from a p4 command, it assumes it will
be 100% UTF-8. If even one character in the output of one p4 command is
not UTF-8, git-p4 crashes with:

    File "C:/Program Files/Git/bin/git-p4.py", line 774, in p4CmdList
        value = value.decode() UnicodeDecodeError: 'utf-8' codec can't
        decode byte Ox93 in position 42: invalid start byte

This is especially a problem for the "git p4 clone ... @all" command,
where git-p4 needs to read thousands of changeset descriptions, one of
which may have a stray smart quote, causing the whole clone operation
to fail.

Add a new config setting, allowing git-p4 to try a fallback encoding
(for example, "cp1252") and/or use the Unicode replacement character,
to prevent the whole program from crashing on such a minor problem.

Signed-off-by: Tzadik Vanderhoof <tzadik.vanderhoof@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-p4.txt
git-p4.py
t/t9836-git-p4-config-fallback-encoding.sh [new file with mode: 0755]