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

[RFC PATCH 3/4] git-p4: open .gitp4-usercache.txt in text mode

From
Yang Zhao <yang.zhao@skyboxlabs.com>
Date
Nov 28, 2019, 01:28 UTC
Message-ID
<20191128012807.3103-4-yang.zhao@skyboxlabs.com>
In-Reply-To
<20191128012807.3103-1-yang.zhao@skyboxlabs.com>

Opening .gitp4-usercache.txt in text mode makes python 3 happy without explicitly adding encoding and decoding.

Signed-off-by: Yang Zhao <yang.zhao@skyboxlabs.com>
---
 git-p4.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/git-p4.py b/git-p4.py
index d79cbf7005..6821d6aafd 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -1387,14 +1387,14 @@ def getUserMapFromPerforceServer(self):
         for (key, val) in self.users.items():
             s += "%s\t%s\n" % (key.expandtabs(1), val.expandtabs(1))
 
-        open(self.getUserCacheFilename(), "wb").write(s)
+        open(self.getUserCacheFilename(), 'w', encoding='utf-8').write(s)
         self.userMapFromPerforceServer = True
 
     def loadUserMapFromCache(self):
         self.users = {}
         self.userMapFromPerforceServer = False
         try:
-            cache = open(self.getUserCacheFilename(), "rb")
+            cache = open(self.getUserCacheFilename(), 'r', encoding='utf-8')
             lines = cache.readlines()
             cache.close()
             for line in lines:
-- 
2.24.0.windows.2
Previous: Yang ZhaoNext: Yang Zhao
Message 4 of 7 in “git-p4: python 3 compatability”
  1. 0/4 git-p4: python 3 compatabilityYang Zhao, Nov 28, 2019
  2. 2/4 git-p4: properly encode/decode communication with git for python 3Yang Zhao, Nov 28, 2019
  3. 1/4 git-p4: decode response from p4 to str for python3Yang Zhao, Nov 28, 2019
  4. 3/4 git-p4: open .gitp4-usercache.txt in text modeYang Zhao, Nov 28, 2019
  5. 4/4 git-p4: use utf-8 encoding for file paths throughoutYang Zhao, Nov 28, 2019
  6. Elijah NewrenNov 28, 2019
  7. Johannes SchindelinNov 28, 2019

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.