From: "Ben Keene via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Ben Keene <seraphire@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Ben Keene <bkeene@partswatch.com>
Subject: [PATCH 1/2] Cast byte strings to unicode strings in python3
Date: Wed, 13 Nov 2019 21:14:24 +0000 [thread overview]
Message-ID: <0bca930ff82623bbef172b4cb6c36ef8e5c46098.1573679665.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.465.git.1573679665.gitgitgadget@gmail.com>
From: Ben Keene <bkeene@partswatch.com>
Signed-off-by: Ben Keene <seraphire@gmail.com>
---
git-p4.py | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 60c73b6a37..6e8b3a26cd 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -36,12 +36,22 @@
unicode = str
bytes = bytes
basestring = (str,bytes)
+ isunicode = True
+ def ustring(text):
+ """Returns the byte string as a unicode string"""
+ if text == '' or text == b'':
+ return ''
+ return unicode(text, "utf-8")
else:
# 'unicode' exists, must be Python 2
str = str
unicode = unicode
bytes = str
basestring = basestring
+ isunicode = False
+ def ustring(text):
+ """Returns the byte string unchanged"""
+ return text
try:
from subprocess import CalledProcessError
@@ -196,6 +206,8 @@ def read_pipe_full(c):
expand = isinstance(c,basestring)
p = subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=expand)
(out, err) = p.communicate()
+ out = ustring(out)
+ err = ustring(err)
return (p.returncode, out, err)
def read_pipe(c, ignore_error=False):
@@ -263,6 +275,7 @@ def p4_has_move_command():
cmd = p4_build_cmd(["move", "-k", "@from", "@to"])
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate()
+ err = ustring(err)
# return code will be 1 in either case
if err.find("Invalid option") >= 0:
return False
@@ -646,10 +659,18 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
if skip_info:
if 'code' in entry and entry['code'] == 'info':
continue
+ if b'code' in entry and entry[b'code'] == b'info':
+ continue
if cb is not None:
cb(entry)
else:
- result.append(entry)
+ if isunicode:
+ out = {}
+ for key, value in entry.items():
+ out[ustring(key)] = ustring(value)
+ result.append(out)
+ else:
+ result.append(entry)
except EOFError:
pass
exitCode = p4.wait()
@@ -792,7 +813,7 @@ def gitConfig(key, typeSpecifier=None):
cmd += [ key ]
s = read_pipe(cmd, ignore_error=True)
_gitConfig[key] = s.strip()
- return _gitConfig[key]
+ return ustring(_gitConfig[key])
def gitConfigBool(key):
"""Return a bool, using git config --bool. It is True only if the
@@ -860,6 +881,7 @@ def branch_exists(branch):
cmd = [ "git", "rev-parse", "--symbolic", "--verify", branch ]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, _ = p.communicate()
+ out = ustring(out)
if p.returncode:
return False
# expect exactly one line of output: the branch name
--
gitgitgadget
next prev parent reply other threads:[~2019-11-13 21:14 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-13 21:14 [PATCH 0/2] Feature: New Variable git-p4.binary Ben Keene via GitGitGadget
2019-11-13 21:14 ` Ben Keene via GitGitGadget [this message]
2019-11-13 21:14 ` [PATCH 2/2] Added general variable git-p4.binary and added a default for windows of 'P4.EXE' Ben Keene via GitGitGadget
2019-11-14 2:36 ` [PATCH 0/2] Feature: New Variable git-p4.binary Junio C Hamano
2019-11-14 9:53 ` Luke Diamand
2019-11-14 20:16 ` Ben Keene
2019-11-15 9:28 ` Luke Diamand
2019-11-15 14:42 ` [PATCH v2 0/3] Feature: New Variable git-p4.p4program Ben Keene via GitGitGadget
2019-11-15 14:42 ` [PATCH v2 1/3] Cast byte strings to unicode strings in python3 Ben Keene via GitGitGadget
2019-11-16 2:40 ` Junio C Hamano
2019-11-16 3:52 ` Junio C Hamano
2019-11-15 14:42 ` [PATCH v2 2/3] Added general variable git-p4.binary and added a default for windows of 'P4.EXE' Ben Keene via GitGitGadget
2019-11-16 2:50 ` Junio C Hamano
2019-11-15 14:42 ` [PATCH v2 3/3] Changed the name of the parameter from git-p4.binary to git-p4.p4program Ben Keene via GitGitGadget
2019-11-16 2:40 ` [PATCH v2 0/3] Feature: New Variable git-p4.p4program Junio C Hamano
2019-11-18 1:15 ` Junio C Hamano
2019-12-03 15:59 ` Ben Keene
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0bca930ff82623bbef172b4cb6c36ef8e5c46098.1573679665.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=bkeene@partswatch.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=seraphire@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).