[PATCH 13 of 13] compat: initial attempt to fix some bytes/unicode issues. Work on progress

Alejandro Santos alejolp at alejolp.com
Wed Aug 5 15:55:47 CDT 2009


# HG changeset patch
# User Alejandro Santos <alejolp at alejolp.com>
# Date 1249505636 10800
# Node ID ae0d81082058e5df94f06c50c849d744d77b6f67
# Parent  3352f2de360abad11763c242e9835d1fb195c3c5
compat: initial attempt to fix some bytes/unicode issues. Work on progress.

diff -r 3352f2de360a -r ae0d81082058 mercurial/dirstate.py
--- a/mercurial/dirstate.py	Wed Aug 05 17:53:56 2009 -0300
+++ b/mercurial/dirstate.py	Wed Aug 05 17:53:56 2009 -0300
@@ -117,6 +117,8 @@
     def _join(self, f):
         # much faster than os.path.join()
         # it's safe because f is always a relative path
+        if type(f) is not str:
+            f = f.decode()
         return self._rootdir + f
 
     def flagfunc(self, fallback):
diff -r 3352f2de360a -r ae0d81082058 mercurial/node.py
--- a/mercurial/node.py	Wed Aug 05 17:53:56 2009 -0300
+++ b/mercurial/node.py	Wed Aug 05 17:53:56 2009 -0300
@@ -6,9 +6,10 @@
 # GNU General Public License version 2, incorporated herein by reference.
 
 import binascii
+import util
 
 nullrev = -1
-nullid = "\0" * 20
+nullid = util.nullid
 
 # This ugly style has a noticeable effect in manifest parsing
 hex = binascii.hexlify
diff -r 3352f2de360a -r ae0d81082058 mercurial/pure/parsers.py
--- a/mercurial/pure/parsers.py	Wed Aug 05 17:53:56 2009 -0300
+++ b/mercurial/pure/parsers.py	Wed Aug 05 17:53:56 2009 -0300
@@ -76,6 +76,7 @@
     e_size = struct.calcsize(format)
     pos1 = 40
     l = len(st)
+    nullchr = '\0'.encode() # bytes on Py3k
 
     # the inner loop
     while pos1 < l:
@@ -83,7 +84,7 @@
         e = _unpack(">cllll", st[pos1:pos2]) # a literal here is faster
         pos1 = pos2 + e[4]
         f = st[pos2:pos1]
-        if '\0' in f:
+        if nullchr in f:
             f, c = f.split('\0')
             copymap[f] = c
         dmap[f] = e[:4]
diff -r 3352f2de360a -r ae0d81082058 mercurial/py2compat.py
--- a/mercurial/py2compat.py	Wed Aug 05 17:53:56 2009 -0300
+++ b/mercurial/py2compat.py	Wed Aug 05 17:53:56 2009 -0300
@@ -11,6 +11,8 @@
 
 import __builtin__
 
+nullid = "\0" * 20
+
 buffer = __builtin__.buffer
 posixfiletype = file
 
diff -r 3352f2de360a -r ae0d81082058 mercurial/py3compat.py
--- a/mercurial/py3compat.py	Wed Aug 05 17:53:56 2009 -0300
+++ b/mercurial/py3compat.py	Wed Aug 05 17:53:56 2009 -0300
@@ -9,6 +9,8 @@
 This file contains helper functions for Python 3 (see py2compat.py)
 """
 
+nullid = b"\0" * 20
+
 class posixfiletype:
     """
     Wrapper for the io class to replicate the classic 'file' type. This class


More information about the Mercurial-devel mailing list