changeset 831:be5bbb2f2d68

svnrepo: kludge to work around hash changes between stupid and replay in hg 1.9 This causes every commit to get a new manifest, just like hg 1.8 and earlier. It also fixes some problems where stupid and replay produced different hashes under 1.9, which is the primary motivation for preserving the old behavior. Hopefully some day we can back this out and be smarter about stupid mode, or can stupid mode entirely in favor of some smarter validations in 'hg svn verify'.
author Augie Fackler <durin42@gmail.com>
date Mon, 10 Oct 2011 22:03:13 -0500
parents d4b3b8370b3c
children e9af7eba88db
files hgsubversion/replay.py hgsubversion/stupid.py hgsubversion/svnmeta.py hgsubversion/svnrepo.py
diffstat 4 files changed, 31 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgsubversion/replay.py
+++ b/hgsubversion/replay.py
@@ -174,7 +174,7 @@ def convert_rev(ui, meta, svn, r, tbdelt
                                      date,
                                      extra)
 
-        new_hash = meta.repo.commitctx(current_ctx)
+        new_hash = meta.repo.svn_commitctx(current_ctx)
         util.describe_commit(ui, new_hash, branch)
         if (rev.revnum, branch) not in meta.revmap and not tag:
             meta.revmap[rev.revnum, branch] = new_hash
@@ -209,7 +209,7 @@ def convert_rev(ui, meta, svn, r, tbdelt
                                      meta.authors[rev.author],
                                      date,
                                      extra)
-        new_hash = meta.repo.commitctx(current_ctx)
+        new_hash = meta.repo.svn_commitctx(current_ctx)
         util.describe_commit(ui, new_hash, branch)
         if (rev.revnum, branch) not in meta.revmap:
             meta.revmap[rev.revnum, branch] = new_hash
--- a/hgsubversion/stupid.py
+++ b/hgsubversion/stupid.py
@@ -713,7 +713,7 @@ def convert_rev(ui, meta, svn, r, tbdelt
                                      meta.authors[r.author],
                                      date,
                                      extra)
-        ha = meta.repo.commitctx(current_ctx)
+        ha = meta.repo.svn_commitctx(current_ctx)
 
         if not tag:
             if (not origbranch in meta.branches
--- a/hgsubversion/svnmeta.py
+++ b/hgsubversion/svnmeta.py
@@ -639,7 +639,7 @@ class SVNMeta(object):
                              self.authors[rev.author],
                              date,
                              parentctx.extra())
-        new_hash = self.repo.commitctx(ctx)
+        new_hash = self.repo.svn_commitctx(ctx)
         if not newparent:
             assert self.revmap[revnum, branch] == parentctx.node()
             self.revmap[revnum, branch] = new_hash
@@ -704,7 +704,7 @@ class SVNMeta(object):
                                  self.authors[rev.author],
                                  date,
                                  extra)
-            new = self.repo.commitctx(ctx)
+            new = self.repo.svn_commitctx(ctx)
 
             if not fromtag and (rev.revnum, b) not in self.revmap:
                 self.revmap[rev.revnum, b] = new
@@ -726,5 +726,5 @@ class SVNMeta(object):
                              self.authors[rev.author],
                              self.fixdate(rev.date),
                              extra)
-        new = self.repo.commitctx(ctx)
+        new = self.repo.svn_commitctx(ctx)
         self.ui.status('Marked branch %s as closed.\n' % (branch or 'default'))
--- a/hgsubversion/svnrepo.py
+++ b/hgsubversion/svnrepo.py
@@ -14,6 +14,8 @@ subclass: pull() is called on the instan
   are used to distinguish and filter these operations from others.
 """
 
+import errno
+
 from mercurial import error
 from mercurial import util as hgutil
 from mercurial import httprepo
@@ -26,6 +28,25 @@ import svnmeta
 
 propertycache = hgutil.propertycache
 
+class ctxctx(object):
+    """Proxies a ctx object and ensures files is never empty."""
+    def __init__(self, ctx):
+        self._ctx = ctx
+
+    def files(self):
+        return self._ctx.files() or ['.svn']
+
+    def filectx(self, path, filelog=None):
+        if path == '.svn':
+            raise IOError(errno.ENOENT, '.svn is a fake file')
+        return self._ctx.filectx(path, filelog=filelog)
+
+    def __getattr__(self, name):
+        return getattr(self._ctx, name)
+
+    def __getitem__(self, key):
+        return self._ctx[key]
+
 def generate_repo_class(ui, repo):
     """ This function generates the local repository wrapper. """
 
@@ -53,6 +74,10 @@ def generate_repo_class(ui, repo):
         return wrapper
 
     class svnlocalrepo(superclass):
+        def svn_commitctx(self, ctx):
+            """Commits a ctx, but defeats manifest recycling introduced in hg 1.9."""
+            return self.commitctx(ctxctx(ctx))
+
         # TODO use newbranch to allow branch creation in Subversion?
         @remotesvn
         def push(self, remote, force=False, revs=None, newbranch=None):