[PATCH 1 of 3] changelog: eliminate reference cycle

Simon Heimberg simohe at besonet.ch
Mon Jul 13 09:14:59 CDT 2009


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1247138607 -7200
# Node ID a9ab0e06c244d08c1308b843d8b3385e9051788e
# Parent  2d414039f83ab6bd81c96cc609ec9fcc624f13c6
changelog: eliminate reference cycle

override method instead of passing a bound method

diff -r 2d414039f83a -r a9ab0e06c244 contrib/dumprevlog
--- a/contrib/dumprevlog	Mit Mai 27 14:16:10 2009 +0200
+++ b/contrib/dumprevlog	Don Jul 09 13:23:27 2009 +0200
@@ -9,7 +9,7 @@
     util.set_binary(fp)
 
 for f in sys.argv[1:]:
-    binopen = lambda fn: open(fn, 'rb')
+    binopen = lambda fn, *args: open(fn, 'rb')
     r = revlog.revlog(binopen, f)
     print "file:", f
     for i in r:
diff -r 2d414039f83a -r a9ab0e06c244 mercurial/changelog.py
--- a/mercurial/changelog.py	Mit Mai 27 14:16:10 2009 +0200
+++ b/mercurial/changelog.py	Don Jul 09 13:23:27 2009 +0200
@@ -89,9 +89,8 @@
 
 class changelog(revlog.revlog):
     def __init__(self, opener):
-        self._realopener = opener
         self._delayed = False
-        revlog.revlog.__init__(self, self._delayopener, "00changelog.i")
+        revlog.revlog.__init__(self, opener, "00changelog.i")
 
     def delayupdate(self):
         "delay visibility of index updates to other readers"
@@ -114,8 +113,8 @@
         # split when we're done
         self.checkinlinesize(tr)
 
-    def _delayopener(self, name, mode='r'):
-        fp = self._realopener(name, mode)
+    def opener(self, name, mode='r', text=False, atomictemp=False):
+        fp = self._opener(name, mode)
         # only divert the index
         if not self._delayed or not name == self.indexfile:
             return fp
@@ -125,7 +124,7 @@
             if not len(self):
                 # make sure to truncate the file
                 mode = mode.replace('a', 'w')
-            return self._realopener(name + ".a", mode)
+            return self._opener(name + ".a", mode)
         # otherwise, divert to memory
         return appender(fp, self._delaybuf)
 
@@ -139,8 +138,8 @@
         "create a file containing the unfinalized state for pretxnchangegroup"
         if self._delaybuf:
             # make a temporary copy of the index
-            fp1 = self._realopener(self.indexfile)
-            fp2 = self._realopener(self.indexfile + ".a", "w")
+            fp1 = self._opener(self.indexfile)
+            fp2 = self._opener(self.indexfile + ".a", "w")
             fp2.write(fp1.read())
             # add pending data
             fp2.write("".join(self._delaybuf))
@@ -155,7 +154,7 @@
         return False
 
     def checkinlinesize(self, tr, fp=None):
-        if self.opener == self._delayopener:
+        if self.opener.im_func == changelog.opener.im_func:
             return
         return revlog.revlog.checkinlinesize(self, tr, fp)
 
diff -r 2d414039f83a -r a9ab0e06c244 mercurial/revlog.py
--- a/mercurial/revlog.py	Mit Mai 27 14:16:10 2009 +0200
+++ b/mercurial/revlog.py	Don Jul 09 13:23:27 2009 +0200
@@ -424,7 +424,7 @@
         """
         self.indexfile = indexfile
         self.datafile = indexfile[:-2] + ".d"
-        self.opener = opener
+        self._opener = opener
         self._cache = None
         self._chunkcache = (0, '')
         self.nodemap = {nullid: nullrev}
@@ -477,6 +477,9 @@
             self.index[-1][7] != nullid) :
             self.index.append((0, 0, 0, -1, -1, -1, -1, nullid))
 
+    def opener(self, name, mode='r', text=False, atomictemp=False):
+        return self._opener(name, mode, text, atomictemp)
+
     def _loadindex(self, start, end):
         """load a block of indexes all at once from the lazy parser"""
         if isinstance(self.index, lazyindex):
diff -r 2d414039f83a -r a9ab0e06c244 mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py	Mit Mai 27 14:16:10 2009 +0200
+++ b/mercurial/statichttprepo.py	Don Jul 09 13:23:27 2009 +0200
@@ -65,7 +65,7 @@
     def opener(base):
         """return a function that opens files over http"""
         p = base
-        def o(path, mode="r"):
+        def o(path, mode="r", text=False, atomictemp=False):
             f = "/".join((p, urllib.quote(path)))
             return httprangereader(f, urlopener)
         return o


More information about the Mercurial-devel mailing list