git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] git-p4: do not decode data from perforce by default

From
Andrew Oakley <andrew@adoakley.name>
Date
Apr 12, 2021, 08:52 UTC
Message-ID
<20210412085251.51475-3-andrew@adoakley.name>
In-Reply-To
<20210412085251.51475-1-andrew@adoakley.name>
This commit is not intended to change behaviour, any we still attempt to
decode values that might not be valid unicode.  It's not clear that all
of these values are safe to decode, but it's now more obvious which data
is decoded.
---
 git-p4.py | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index 8407ec5c7a..8a97ff3dd2 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -764,15 +764,19 @@ def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
         while True:
             entry = marshal.load(p4.stdout)
             if bytes is not str:
-                # Decode unmarshalled dict to use str keys and values, except
-                # for cases where the values may not be valid UTF-8.
-                binary_keys = ('data', 'path', 'clientFile', 'Description',
-                               'desc', 'Email', 'FullName', 'Owner', 'time',
-                               'user', 'User')
+                # Decode unmarshalled dict to use str keys and values where it
+                # is expected that the data is always valid UTF-8.
+                text_keys = ('action', 'change', 'Change', 'Client', 'code',
+                             'fileSize', 'headAction', 'headRev', 'headType',
+                             'Jobs', 'label', 'options', 'perm', 'rev', 'Root',
+                             'Status', 'type', 'Update')
+                text_key_prefixes = ('action', 'File', 'job', 'rev', 'type',
+                                     'View')
                 decoded_entry = {}
                 for key, value in entry.items():
                     key = key.decode()
-                    if isinstance(value, bytes) and not (key in binary_keys or key.startswith('depotFile')):
+                    if isinstance(value, bytes) and (key in text_keys or
+                            any(filter(key.startswith, text_key_prefixes))):
                         value = value.decode()
                     decoded_entry[key] = value
                 # Parse out data if it's an error response
-- 
2.26.3
Previous: Andrew OakleyNext: Tzadik Vanderhoof
Message 2 of 13 in “git-p4: encoding of data from perforce”
  1. 0/2 git-p4: encoding of data from perforceAndrew Oakley, Apr 12, 2021
  2. 2/2 git-p4: do not decode data from perforce by defaultAndrew Oakley, Apr 12, 2021
  3. Tzadik VanderhoofApr 29, 2021
  4. Andrew OakleyApr 30, 2021
  5. Luke DiamandApr 30, 2021
  6. Tzadik VanderhoofApr 30, 2021
  7. Andrew OakleyMay 4, 2021
  8. Tzadik VanderhoofMay 4, 2021
  9. Junio C HamanoMay 5, 2021
  10. Tzadik VanderhoofMay 5, 2021
  11. Tzadik VanderhoofMay 5, 2021
  12. Junio C HamanoMay 5, 2021
  13. 1/2 git-p4: avoid decoding more data from perforceAndrew Oakley, Apr 12, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.