From: "David Racine via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Luke Diamand <luke@diamand.org>,
David Racine <bass_dr@hotmail.com>,
David Racine <bass_dr@hotmail.com>
Subject: [PATCH] Support having non-utf-8 characters returned by p4
Date: Fri, 04 Dec 2020 23:19:21 +0000 [thread overview]
Message-ID: <pull.928.git.git.1607123962304.gitgitgadget@gmail.com> (raw)
From: David Racine <bass_dr@hotmail.com>
When perforce server is not configured for Unicode, and commands like
`p4 users` returns a string with non-ascii characters (eg. one of the
user's FullName has a french `é` in it), git-p4 was giving
`Exception: failure accessing depot: could not connect`.
With this patch, if such character is encountered, it will honor the new
`git-p4.textEncoding` config option, or silently replace the erronous
character and continue.
Signed-off-by: David Racine <bass_dr@hotmail.com>
---
git-p4: Support having non-utf-8 characters returned by p4
When perforce server is not configured for Unicode, and commands like p4
users returns a string with non-ascii characters (eg. one of the user's
FullName has a french é in it), git-p4 was giving Exception: failure
accessing depot: could not connect. With this patch, if such character
is encountered, it will honor the new git-p4.textEncoding config option,
or silently replace the erronous character and continue.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-928%2Fbassdr%2Fpatch-1-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-928/bassdr/patch-1-v1
Pull-Request: https://github.com/git/git/pull/928
git-p4.py | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 6ae5bbfe99..6cbd153419 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -195,16 +195,27 @@ def decode_path(path):
"""Decode a given string (bytes or otherwise) using configured path encoding options
"""
encoding = gitConfig('git-p4.pathEncoding') or 'utf_8'
+ return p4_decode_stream(path, encoding)
+
+def p4_decode_text(user):
+ """Decode a given string (bytes or otherwise) using configured text encoding options
+ """
+ encoding = gitConfig('git-p4.textEncoding') or 'utf-8'
+ return p4_decode_stream(s, encoding)
+
+def p4_decode_stream(s, encoding):
+ """Decode a given string (bytes or otherwise) using encoding argument
+ """
if bytes is not str:
- return path.decode(encoding, errors='replace') if isinstance(path, bytes) else path
+ return s.decode(encoding, errors='replace') if isinstance(s, bytes) else s
else:
try:
- path.decode('ascii')
+ s.decode('ascii')
except:
- path = path.decode(encoding, errors='replace')
+ s = s.decode(encoding, errors='replace')
if verbose:
- print('Path with non-ASCII characters detected. Used {} to decode: {}'.format(encoding, path))
- return path
+ print('Text with non-ASCII characters detected. Used {} to decode: {}'.format(encoding, s))
+ return s
def run_git_hook(cmd, param=[]):
"""Execute a hook if the hook exists."""
@@ -771,7 +782,7 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
for key, value in entry.items():
key = key.decode()
if isinstance(value, bytes) and not (key in ('data', 'path', 'clientFile') or key.startswith('depotFile')):
- value = value.decode()
+ value = p4_decode_text(value)
decoded_entry[key] = value
# Parse out data if it's an error response
if decoded_entry.get('code') == 'error' and 'data' in decoded_entry:
base-commit: 3a0b884caba2752da0af626fb2de7d597c844e8b
--
gitgitgadget
reply other threads:[~2020-12-04 23:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.928.git.git.1607123962304.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=bass_dr@hotmail.com \
--cc=git@vger.kernel.org \
--cc=luke@diamand.org \
/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.
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 NNTP newsgroup(s).