Support optionally overriding svn:author and svn:date (#140001)
authorJelmer Vernooij <jelmer@samba.org>
Tue, 30 Oct 2007 22:08:13 +0000 (23:08 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 30 Oct 2007 22:08:13 +0000 (23:08 +0100)
FAQ
NEWS
commit.py
config.py
tests/test_commit.py
tests/test_push.py

diff --git a/FAQ b/FAQ
index 47cfc8d692532abec3ca178256b87ace70b4c3b6..ee63b491c88c83c10bbee924c546451b8964c5ac 100644 (file)
--- a/FAQ
+++ b/FAQ
@@ -78,3 +78,14 @@ previous versions. In other words, existing bzr-svn branches created with
 0.3.x can not be used directly with 0.4.0 but will have to be upgraded to 
 work with 0.4.0 using the "bzr svn-upgrade" command. The bzr-rebase package 
 has to be installed for this command to work correctly.
+
+============================================================================
+Is it possible to keep the author name when pushing changes into Subversion?
+============================================================================
+Yes, but this requires the repository to allow revision property changes. 
+
+See hooks/pre-revprop-change in the Subversion repository for 
+more information about how to do this.
+
+You also need to enable support for this in bzr-svn by setting 
+pre-revprop-change to True in ~/.bazaar/bazaar.conf.
diff --git a/NEWS b/NEWS
index a632537b841044229398e397a0d68c9bc5569dc7..b1ee181e3825ce8fd26bff0f59c1fc78b1375433 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,8 @@ bzr-svn 0.4.4 UNRELEASED
 
    * Clearer error when prefix is missing during push.
 
+   * Support optionally overriding svn:author and svn:date (#140001)
+
   INTERNALS
 
    * Handle NULL_REVISION in SvnRepository.copy_content(). Fixes compatibility 
index d2b78572e5defccd73aea771c6d91e1fa6f22aa6..635720983c7d674eeaddbfe97d49c447f8f21d07 100644 (file)
--- a/commit.py
+++ b/commit.py
@@ -16,7 +16,7 @@
 """Committing and pushing to Subversion repositories."""
 
 import svn.delta
-from svn.core import Pool, SubversionException
+from svn.core import Pool, SubversionException, svn_time_to_cstring
 
 from bzrlib import debug, osutils, urlutils
 from bzrlib.branch import Branch
@@ -54,18 +54,19 @@ def _check_dirs_exist(transport, bp_parts, base_rev):
     return []
 
 
-def set_svn_revprops(transport, revnum, date, author):
+def set_svn_revprops(transport, revnum, author, timestamp, timezone):
     """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
+    :param timestamp: Timestamp
+    :param timezone: Timezone
     """
     revprops = {
         svn.core.SVN_PROP_REVISION_AUTHOR: author,
-        svn.core.SVN_PROP_REVISION_DATE: date
+        svn.core.SVN_PROP_REVISION_DATE: svn_time_to_cstring(1000000*(timestamp+timezone))
     }
     for (name, value) in revprops.items():
         try:
@@ -514,6 +515,11 @@ class SvnCommitBuilder(RootCommitBuilder):
         self.mutter('commit %d finished. author: %r, date: %r, revid: %r' % 
                (self.revnum, self.author, self.date, revid))
 
+        if self.repository.get_config().get_override_svn_revprops():
+            set_svn_revprops(self.repository.transport, 
+                             self.revnum, self._committer, 
+                             self._timestamp, self._timezone)
+
         return revid
 
     def _record_file_id(self, ie, path):
index 23405936bbde3077c1a6f5cbdae0e271f1c12663..e3e7af145c3d43b258cee66f4505be35294d8543 100644 (file)
--- a/config.py
+++ b/config.py
@@ -61,7 +61,10 @@ class SvnRepositoryConfig(IniBasedConfig):
 
         :return: BranchingScheme instance.
         """
-        return BranchingScheme.find_scheme(self._get_user_option("branching-scheme", use_global=False))
+        schemename = self._get_user_option("branching-scheme", use_global=False)
+        if schemename is not None:
+            return BranchingScheme.find_scheme(schemename)
+        return None
 
     def get_override_svn_revprops(self):
         """Check whether or not bzr-svn should attempt to override Subversion revision 
index f3660275fae78a091cadc84cd07094a1ec4b71f6..eeea06bd419d4c32c7028947e600a28c709c49ef 100644 (file)
@@ -557,9 +557,9 @@ class RevpropTests(TestCaseWithSubversionRepository):
         self.client_commit("dc", "My commit")
 
         transport = SvnRaTransport(repos_url)
-        set_svn_revprops(transport, 1, "2007-11-11", "Somebody")
+        set_svn_revprops(transport, 1, "Somebody", 473382000, 3600)
 
-        self.assertEquals(("Somebody", "2007-11-11", "My commit"), 
+        self.assertEquals(("Somebody", "1985-01-01T00:00:00.000000Z", "My commit"), 
                           self.client_log("dc")[1][1:])
 
     def test_change_revprops_disallowed(self):
@@ -570,4 +570,4 @@ class RevpropTests(TestCaseWithSubversionRepository):
 
         transport = SvnRaTransport(repos_url)
         self.assertRaises(RevpropChangeFailed, 
-            lambda: set_svn_revprops(transport, 1, "2007-11-11", "Somebody"))
+            lambda: set_svn_revprops(transport, 1, "Somebody", 473382000, 3600))
index 88cc64a0e175fd9b7e0879679ad9df366cd1bf72..6c6a2bc0ceedb306bb8a35794312b1ef47ee3ddf 100644 (file)
@@ -120,6 +120,18 @@ class TestPush(TestCaseWithSubversionRepository):
         self.assertEqual(repos.generate_revision_id(2, "", "none"),
                         self.svndir.open_branch().last_revision())
 
+    def test_override_revprops(self):
+        self.svndir.find_repository().get_config().set_user_option("override-svn-revprops", "True")
+        self.build_tree({'dc/file': 'data'})
+        wt = self.bzrdir.open_workingtree()
+        wt.add('file')
+        wt.commit(message="Commit from Bzr", committer="Sombody famous", timestamp=1012604400, timezone=0)
+
+        self.svndir.open_branch().pull(self.bzrdir.open_branch())
+
+        self.assertEquals(("Sombody famous", "2002-02-01T23:00:00.000000Z", "Commit from Bzr"), 
+            self.client_log(self.repos_url)[2][1:])
+
     def test_empty_file(self):
         self.build_tree({'dc/file': ''})
         wt = self.bzrdir.open_workingtree()