pr-1206/TaoK/git-p4-encoding-strategy-v4
tagged this
30 Apr 19:26
From: Tao Klerks <tao@klerks.biz> git-p4 is designed to run correctly under python2.7 and python3, but its functional behavior wrt importing user-entered text differs across these environments: Under python2, git-p4 "naively" writes the Perforce bytestream into git metadata (and does not set an "encoding" header on the commits); this means that any non-utf-8 byte sequences end up creating invalidly-encoded commit metadata in git. Under python3, git-p4 attempts to decode the Perforce bytestream as utf-8 data, and fails badly (with an unhelpful error) when non-utf-8 data is encountered. Perforce clients (especially p4v) encourage user entry of changelist descriptions (and user full names) in OS-local encoding, and store the resulting bytestream to the server unmodified - such that different clients can end up creating mutually-unintelligible messages. The most common inconsistency, in many Perforce environments, is likely to be utf-8 (typical in linux) vs cp-1252 (typical in windows). Make the changelist-description- and user-fullname-handling code python-runtime-agnostic, introducing three "strategies" selectable via config: - 'passthrough', behaving as previously under python2, - 'strict', behaving as previously under python3, and - 'fallback', favoring utf-8 but supporting a secondary encoding when utf-8 decoding fails, and finally escaping high-range bytes if the decoding with the secondary encoding also fails. Keep the python2 default behavior as-is ('legacy' strategy), but switch the python3 default strategy to 'fallback' with default fallback encoding 'cp1252'. Also include tests exercising these encoding strategies, documentation for the new config, and improve the user-facing error messages when decoding does fail. Signed-off-by: Tao Klerks <tao@klerks.biz> Submitted-As: https://lore.kernel.org/git/pull.1206.v4.git.1651346812586.gitgitgadget@gmail.com In-Reply-To: https://lore.kernel.org/git/pull.1206.git.1649670174972.gitgitgadget@gmail.com In-Reply-To: https://lore.kernel.org/git/pull.1206.v2.git.1649831069578.gitgitgadget@gmail.com In-Reply-To: https://lore.kernel.org/git/pull.1206.v3.git.1650399590844.gitgitgadget@gmail.com
Assets 2
-
2022-04-30T19:26:52Z -
2022-04-30T19:26:52Z - Loading