# HG changeset patch # User Patrick Mezard # Date 1334840889 -7200 # Node ID 6ef6c413d6ded4b367e0f7be7990d5b449dace1b # Parent 6fc7f74f0cf62b367f33686a1b4ac22d3c061df2 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. diff --git a/hgsubversion/editor.py b/hgsubversion/editor.py --- 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)