changeset 862:6ef6c413d6de

editor: work around svn 1.7 closing the output fp in apply_textdelta() Calling close() on the output cStringIO when done with patching prevents us to retrieve the result with getvalue(). Note: I found this bug has been fixed already by 794f3e41ec1e. I feel ignoring the close() call is a little cleaner than storing the value before the handler() call for there is no guarantee the handler does not modify the value in its last call. Looking at text_delta.c, it does not in 1.7.1. So, do what you want with this patch.
author Patrick Mezard <patrick@mezard.eu>
date Thu, 19 Apr 2012 15:08:09 +0200
parents 6fc7f74f0cf6
children 39d45f2190ee
files hgsubversion/editor.py
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/editor.py
+++ b/hgsubversion/editor.py
@@ -10,6 +10,18 @@ import svnwrap
 import util
 import svnexternals
 
+class NeverClosingStringIO(object):
+    def __init__(self):
+        self._fp = cStringIO.StringIO()
+
+    def __getattr__(self, name):
+        return getattr(self._fp, name)
+
+    def close(self):
+        # svn 1.7 apply_delta driver now calls close() on passed file
+        # object which prevent us from calling getvalue() afterwards.
+        pass
+
 class RevisionData(object):
 
     __slots__ = [
@@ -331,7 +343,7 @@ class HgEditor(svnwrap.Editor):
         if self.current.file in self.current.missing:
             return lambda x: None
         base = self.current.files[self.current.file]
-        target = cStringIO.StringIO()
+        target = NeverClosingStringIO()
         self.stream = target
 
         handler = svnwrap.apply_txdelta(base, target)
@@ -342,13 +354,10 @@ class HgEditor(svnwrap.Editor):
             try:
                 if not self.meta.is_path_valid(self.current.file):
                     return
-                # Already get and store the value here, because calling
-                # handler(window) seems to close the target in Subversion 1.7.
-                val = target.getvalue()
                 handler(window)
                 # window being None means commit this file
                 if not window:
-                    self.current.files[self.current.file] = val
+                    self.current.files[self.current.file] = target.getvalue()
             except svnwrap.SubversionException, e: # pragma: no cover
                 if e.args[1] == svnwrap.ERR_INCOMPLETE_DATA:
                     self.current.missing.add(self.current.file)