Skip to content

git-p4.py: Cast byte strings to unicode strings in python3

Ben Keene via GitGitGadget git 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest1 patch 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1Cast byte strings to unicode strings in python3git-p4.py+24 -20 replies

Reviews trailers per patch

The patch has no Reviewed-by or Acked-by.

PatchJunio C HamanoDenton Liu
SeriesHelped-by Helped-by
1/1

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/1] git-p4.py: Cast byte strings to unicode strings in python3

commit: git-p4.py: Cast byte strings to unicode strings in python3

I tried to run git-p4 under python3 and it failed with an error that it could not connect to the P4 server. This is caused by the return values from the process.popen returning byte strings and the code is failing when it is comparing these with literal strings which are Unicode in Python 3.

To support this, I added a new function ustring() in the code that determines if python is natively supporting Unicode (Python 3) or not (Python 2).

* If the python version supports Unicode (Python 3), it will cast the text (expected a byte string) to UTF-8. This allows the existing code to match literal strings as expected.

* If the python version does not natively support Unicode (Python 2) the ustring() function does not change the byte string, maintaining current behavior.

There are a few notable methods changed:

* pipe functions have their output passed through the ustring() function:

* read_pipe_full(c)
* p4_has_move_command()

* p4CmdList has new conditional code to parse the dictionary marshaled from the process call. Both the keys and values are converted to Unicode.

* gitConfig passes the return value through ustring() so all calls to gitConfig return unicode values.

Ben Keene (1):
Cast byte strings to unicode strings in python3

 git-p4.py | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

base-commit: d9f6f3b6195a0ca35642561e530798ad1469bd41
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-463%2Fseraphire%2Fseraphire%2Fp4-python3-unicode-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-463/seraphire/seraphire/p4-python3-unicode-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/463

Signature · 1 line
gitgitgadget