Rev 768: Add function for changing svn revision properties. in file:///data/jelmer/bzr-svn/override-svnrevprops/

Jelmer Vernooij jelmer at samba.org
Tue Oct 30 21:10:28 GMT 2007


At file:///data/jelmer/bzr-svn/override-svnrevprops/

------------------------------------------------------------
revno: 768
revision-id:jelmer at samba.org-20071030211026-7o30l30uqivf1ei3
parent: jelmer at samba.org-20071030200343-dxkactyx4yjd140r
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: override-svnrevprops
timestamp: Tue 2007-10-30 22:10:26 +0100
message:
  Add function for changing svn revision properties.
modified:
  commit.py                      commit.py-20060607190346-qvq128wgfubhhgm2-1
  errors.py                      errors.py-20061226172623-w1sbj8ynpo0eojqp-1
  tests/__init__.py              __init__.py-20060508151940-e9f4d914801a2535
  tests/test_commit.py           test_commit.py-20060624213521-l5kcufywkh9mnilk-1
  transport.py                   transport.py-20060406231150-b3472d06b3a0818d
=== modified file 'commit.py'
--- a/commit.py	2007-10-29 13:05:13 +0000
+++ b/commit.py	2007-10-30 21:10:26 +0000
@@ -28,7 +28,7 @@
 from bzrlib.trace import mutter
 
 from copy import deepcopy
-from errors import ChangesRootLHSHistory, MissingPrefix
+from errors import ChangesRootLHSHistory, MissingPrefix, RevpropChangeFailed
 from repository import (SVN_PROP_BZR_ANCESTRY, SVN_PROP_BZR_FILEIDS,
                         SVN_PROP_SVK_MERGE, SVN_PROP_BZR_REVISION_INFO, 
                         SVN_PROP_BZR_REVISION_ID, revision_id_to_svk_feature,
@@ -54,6 +54,26 @@
     return []
 
 
+def set_svn_revprops(transport, revnum, date, author):
+    """Attempt to change the revision properties on the
+    specified revision.
+
+    :param transport: SvnRaTransport connected to target repository
+    :param revnum: Revision number of revision to change metadata of.
+    :param date: New date
+    :param author: New author
+    """
+    revprops = {
+        svn.core.SVN_PROP_REVISION_AUTHOR: author,
+        svn.core.SVN_PROP_REVISION_DATE: date
+    }
+    for (name, value) in revprops.items():
+        try:
+            transport.change_rev_prop(revnum, name, value)
+        except SubversionException, (_, svn.core.SVN_ERR_REPOS_DISABLED_FEATURE):
+            raise RevpropChangeFailed(name)
+
+
 class SvnCommitBuilder(RootCommitBuilder):
     """Commit Builder implementation wrapped around svn_delta_editor. """
 

=== modified file 'errors.py'
--- a/errors.py	2007-10-29 13:05:13 +0000
+++ b/errors.py	2007-10-30 21:10:26 +0000
@@ -54,6 +54,14 @@
         self.path = path
 
 
+class RevpropChangeFailed(BzrError):
+    _fmt = """Unable to set revision property %(name)s."""
+
+    def __init__(self, name):
+        BzrError.__init__(self)
+        self.name = name
+
+
 def convert_error(err):
     """Convert a Subversion exception to the matching BzrError.
 

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2007-10-17 10:37:19 +0000
+++ b/tests/__init__.py	2007-10-30 21:10:26 +0000
@@ -42,7 +42,7 @@
     def log_message_func(self, items, pool):
         return self.next_message
 
-    def make_repository(self, relpath):
+    def make_repository(self, relpath, allow_revprop_changes=True):
         """Create a repository.
 
         :return: Handle to the repository.
@@ -52,11 +52,10 @@
 
         svn.repos.create(abspath, '', '', None, None)
 
-        revprop_hook = os.path.join(abspath, "hooks", "pre-revprop-change")
-
-        open(revprop_hook, 'w').write("#!/bin/sh")
-
-        os.chmod(revprop_hook, os.stat(revprop_hook).st_mode | 0111)
+        if allow_revprop_changes:
+            revprop_hook = os.path.join(abspath, "hooks", "pre-revprop-change")
+            open(revprop_hook, 'w').write("#!/bin/sh")
+            os.chmod(revprop_hook, os.stat(revprop_hook).st_mode | 0111)
 
         return repos_url
 
@@ -238,14 +237,16 @@
 
         return BzrDir.open("svn+%s" % repos_url)
 
-    def make_client(self, repospath, clientpath):
+    def make_client(self, repospath, clientpath, allow_revprop_changes=True):
         """Create a repository and a checkout. Return the checkout.
 
         :param relpath: Optional relpath to check out if not the full 
             repository.
+        :param clientpath: Path to checkout
         :return: Repository URL.
         """
-        repos_url = self.make_repository(repospath)
+        repos_url = self.make_repository(repospath, 
+            allow_revprop_changes=allow_revprop_changes)
         self.make_checkout(repos_url, clientpath)
         return repos_url
 

=== modified file 'tests/test_commit.py'
--- a/tests/test_commit.py	2007-10-17 10:37:19 +0000
+++ b/tests/test_commit.py	2007-10-30 21:10:26 +0000
@@ -22,9 +22,12 @@
 from bzrlib.trace import mutter
 from bzrlib.workingtree import WorkingTree
 
+from commit import set_svn_revprops
 from copy import copy
+from errors import RevpropChangeFailed
 from repository import MAPPING_VERSION
 import os
+from remote import SvnRaTransport
 from tests import TestCaseWithSubversionRepository
 
 class TestNativeCommit(TestCaseWithSubversionRepository):
@@ -544,3 +547,27 @@
         self.assertEquals("dir\t%s\n" % dirid +
                           "dir/file\t%s\n" % fileid, 
                           self.client_get_prop(repos_url, "bzr:file-ids", 1))
+
+
+class RevpropTests(TestCaseWithSubversionRepository):
+    def test_change_revprops(self):
+        repos_url = self.make_client("d", "dc")
+        self.build_tree({"dc/foo.txt": "txt"})
+        self.client_add("dc/foo.txt")
+        self.client_commit("dc", "My commit")
+
+        transport = SvnRaTransport(repos_url)
+        set_svn_revprops(transport, 1, "2007-11-11", "Somebody")
+
+        self.assertEquals(("Somebody", "2007-11-11", "My commit"), 
+                          self.client_log("dc")[1][1:])
+
+    def test_change_revprops_disallowed(self):
+        repos_url = self.make_client("d", "dc", allow_revprop_changes=False)
+        self.build_tree({"dc/foo.txt": "txt"})
+        self.client_add("dc/foo.txt")
+        self.client_commit("dc", "My commit")
+
+        transport = SvnRaTransport(repos_url)
+        self.assertRaises(RevpropChangeFailed, 
+            lambda: set_svn_revprops(transport, 1, "2007-11-11", "Somebody"))

=== modified file 'transport.py'
--- a/transport.py	2007-10-26 16:17:28 +0000
+++ b/transport.py	2007-10-30 21:10:26 +0000
@@ -342,6 +342,10 @@
             self.reparent(self.get_repos_root())
 
     @convert_svn_error
+    def change_rev_prop(self, revnum, name, value, pool=None):
+        svn.ra.change_rev_prop(self._ra, revnum, name, value)
+
+    @convert_svn_error
     @needs_busy
     def reparent(self, url):
         url = url.rstrip("/")




More information about the bazaar-commits mailing list