]> git.ipfire.org Git - thirdparty/git.git/commit - git-p4.py
git-p4: encode/decode communication with p4 for python3
authorYang Zhao <yang.zhao@skyboxlabs.com>
Fri, 13 Dec 2019 23:52:38 +0000 (15:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Jan 2020 20:53:39 +0000 (12:53 -0800)
commit6cec21a82f437184c69cce2b8fe6011d02acfa06
treea96aa25be16ce5847bf93a2e1799afbfc294153c
parent1f8b46d0a4fdcb6fea566405cfc5422d39c36d52
git-p4: encode/decode communication with p4 for python3

The marshalled dict in the response given on STDOUT by p4 uses `str` for
keys and string values. When run using python3, these values are
deserialized as `bytes`, leading to a whole host of problems as the rest
of the code assumes `str` is used throughout.

This patch changes the deserialization behaviour such that, as much as
possible, text output from p4 is decoded to native unicode strings.
Exceptions are made for the field `data` as it is usually arbitrary
binary data. `depotFile[0-9]*`, `path`, and `clientFile` are also exempt
as they contain path strings not encoded with UTF-8, and must survive
round-trip back to p4.

Conversely, text data being piped to p4 must always be encoded when
running under python3.

encode_text_stream() and decode_text_stream() were added to make these
transformations more convenient.

Signed-off-by: Yang Zhao <yang.zhao@skyboxlabs.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-p4.py