git-p4: fix bug with encoding of p4 client name

The Perforce client name can contain arbitrary characters which do not decode to UTF-8. Use the fallback strategy implemented in metadata_stream_to_writable_bytes() also for the client name. Signed-off-by: Kilian Kilger <kkilger@gmail.com> Reviewed-by: Tao Klerks <tao@klerks.biz> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kilian Kilger committed Jul 8, 2022 at 08:01 UTC 34f67c9619b56ab4718427c1a31071641f0dccdb
1 file changed +4 -2
git-p4.py
+4 -2
@@ -854,12 +854,12 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
854 if bytes is not str:
855 # Decode unmarshalled dict to use str keys and values, except for:
856 # - `data` which may contain arbitrary binary data
857 - # - `desc` or `FullName` which may contain non-UTF8 encoded text handled below, eagerly converted to bytes
857 + # - `desc` or `client` or `FullName` which may contain non-UTF8 encoded text handled below, eagerly converted to bytes
858 # - `depotFile[0-9]*`, `path`, or `clientFile` which may contain non-UTF8 encoded text, handled by decode_path()
859 decoded_entry = {}
860 for key, value in entry.items():
861 key = key.decode()
862 - if isinstance(value, bytes) and not (key in ('data', 'desc', 'FullName', 'path', 'clientFile') or key.startswith('depotFile')):
862 + if isinstance(value, bytes) and not (key in ('data', 'desc', 'FullName', 'path', 'clientFile', 'client') or key.startswith('depotFile')):
863 value = value.decode()
864 decoded_entry[key] = value
865 # Parse out data if it's an error response
@@ -871,6 +871,8 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
871 continue
872 if 'desc' in entry:
873 entry['desc'] = metadata_stream_to_writable_bytes(entry['desc'])
874 + if 'client' in entry:
875 + entry['client'] = metadata_stream_to_writable_bytes(entry['client'])
876 if 'FullName' in entry:
877 entry['FullName'] = metadata_stream_to_writable_bytes(entry['FullName'])
878 if cb is not None: