scmutil: clean up bytes/string cache decorator mess on Python 3 again
authorAugie Fackler <augie@google.com>
Thu, 26 Apr 2018 21:38:49 -0400
changeset 37869 73a74f29eb87
parent 37868 69de3c3de036
child 37870 39c17718f311
scmutil: clean up bytes/string cache decorator mess on Python 3 again The previous fix to this area worked, but was dropping bytes in __dict__ on Python 3. This was causing subtle breakage in test-check-interfaces.py, and probably other things too. Fixed now. Differential Revision: https://phab.mercurial-scm.org/D3464
mercurial/scmutil.py
--- a/mercurial/scmutil.py	Mon May 07 12:18:09 2018 -0700
+++ b/mercurial/scmutil.py	Thu Apr 26 21:38:49 2018 -0400
@@ -1142,7 +1142,8 @@
 
     def __call__(self, func):
         self.func = func
-        self.name = func.__name__.encode('ascii')
+        self.sname = func.__name__
+        self.name = pycompat.sysbytes(self.sname)
         return self
 
     def __get__(self, obj, type=None):
@@ -1150,9 +1151,9 @@
         if obj is None:
             return self
         # do we need to check if the file changed?
-        if self.name in obj.__dict__:
+        if self.sname in obj.__dict__:
             assert self.name in obj._filecache, self.name
-            return obj.__dict__[self.name]
+            return obj.__dict__[self.sname]
 
         entry = obj._filecache.get(self.name)
 
@@ -1169,7 +1170,7 @@
 
             obj._filecache[self.name] = entry
 
-        obj.__dict__[self.name] = entry.obj
+        obj.__dict__[self.sname] = entry.obj
         return entry.obj
 
     def __set__(self, obj, value):
@@ -1183,13 +1184,13 @@
             ce = obj._filecache[self.name]
 
         ce.obj = value # update cached copy
-        obj.__dict__[self.name] = value # update copy returned by obj.x
+        obj.__dict__[self.sname] = value # update copy returned by obj.x
 
     def __delete__(self, obj):
         try:
-            del obj.__dict__[self.name]
+            del obj.__dict__[self.sname]
         except KeyError:
-            raise AttributeError(self.name)
+            raise AttributeError(self.sname)
 
 def extdatasource(repo, source):
     """Gather a map of rev -> value dict from the specified source