You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/06/24 20:05:54 UTC

git commit: [#6364] Set SVN checkout_url on clone

Updated Branches:
  refs/heads/tv/6364 [created] f533e64b0


[#6364] Set SVN checkout_url on clone

- If the cloned repo has a top-level 'trunk' dir,
  point the checkout_url at it.
- Script to set checkout_url for existing repos
  with top-level trunk dir.

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/f533e64b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/f533e64b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/f533e64b

Branch: refs/heads/tv/6364
Commit: f533e64b0dc0493c57c4b688406d9b12807e6d58
Parents: 0c5787e
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Mon Jun 24 18:05:18 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Mon Jun 24 18:05:18 2013 +0000

----------------------------------------------------------------------
 Allura/allura/scripts/update_checkout_url.py    | 52 ++++++++++++++++++++
 ForgeSVN/forgesvn/model/svn.py                  | 27 ++++++++--
 .../tests/model/test_svnimplementation.py       | 20 ++++++--
 3 files changed, 91 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f533e64b/Allura/allura/scripts/update_checkout_url.py
----------------------------------------------------------------------
diff --git a/Allura/allura/scripts/update_checkout_url.py b/Allura/allura/scripts/update_checkout_url.py
new file mode 100644
index 0000000..7420dab
--- /dev/null
+++ b/Allura/allura/scripts/update_checkout_url.py
@@ -0,0 +1,52 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+"""
+Find repos with blank checkout url and top-level "trunk" dir,
+and point checkout_url at trunk.
+"""
+
+import logging
+
+from ming.orm import ThreadLocalORMSession
+
+from allura import model as M
+from allura.lib import utils
+from allura.scripts import ScriptTask
+
+from forgesvn.model.svn import Repository, svn_path_exists
+
+log = logging.getLogger(__name__)
+
+
+class UpdateCheckoutUrl(ScriptTask):
+    @classmethod
+    def execute(cls, options):
+        query = {'tool_name': {'$regex': '^svn$', '$options': 'i'},
+                 'options.checkout_url': ''}
+        for chunk in utils.chunked_find(M.AppConfig, query):
+            for config in chunk:
+                repo = Repository.query.get(app_config_id=config._id)
+                trunk_path = "file://{0}{1}/trunk".format(repo.fs_path, repo.name)
+                if svn_path_exists(trunk_path):
+                    config.options['checkout_url'] = "trunk"
+                    log.info("Update checkout_url for: %s", trunk_path)
+            ThreadLocalORMSession.flush_all()
+
+if __name__ == '__main__':
+    UpdateCheckoutUrl.main()
+

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f533e64b/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index 23c1887..15ef82a 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -291,13 +291,30 @@ class SVNImplementation(M.RepositoryImplementation):
             clear_hook('pre-revprop-change')
 
         log.info('... %r cloned', self._repo)
-        if not svn_path_exists("file://%s%s/%s" %
-                         (self._repo.fs_path,
-                          self._repo.name,
-                          c.app.config.options['checkout_url'])):
-            c.app.config.options['checkout_url'] = ""
+        self.update_checkout_url()
         self._setup_special_files(source_url)
 
+    def update_checkout_url(self):
+        """Validate the current ``checkout_url`` against the on-disk repo,
+        and change it if necessary.
+
+        If ``checkout_url`` is valid, no changes are made.
+        If ``checkout_url`` is invalid:
+
+            - Set it to 'trunk' if repo has a top-level trunk directory
+            - Else, set it to ''
+
+        """
+        opts = self._repo.app.config.options
+        if not svn_path_exists('file://{0}{1}/{2}'.format(self._repo.fs_path,
+                self._repo.name, opts['checkout_url'])):
+            opts['checkout_url'] = ''
+
+        if (not opts['checkout_url'] and
+                svn_path_exists('file://{0}{1}/trunk'.format(self._repo.fs_path,
+                    self._repo.name))):
+            opts['checkout_url'] = 'trunk'
+
     def commit(self, rev):
         if rev in ('HEAD', None):
             oid = self._oid(self.head)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f533e64b/ForgeSVN/forgesvn/tests/model/test_svnimplementation.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_svnimplementation.py b/ForgeSVN/forgesvn/tests/model/test_svnimplementation.py
index c23c6b3..4e4e57a 100644
--- a/ForgeSVN/forgesvn/tests/model/test_svnimplementation.py
+++ b/ForgeSVN/forgesvn/tests/model/test_svnimplementation.py
@@ -15,13 +15,12 @@
 #       specific language governing permissions and limitations
 #       under the License.
 
-from mock import Mock, MagicMock, patch
-import pysvn
+from mock import Mock, patch
 from nose.tools import assert_equal
 from pylons import app_globals as g
 
 from allura.model.repo import Commit
-from forgesvn.model.svn import Repository, SVNImplementation
+from forgesvn.model.svn import SVNImplementation
 
 
 class TestSVNImplementation(object):
@@ -106,3 +105,18 @@ class TestSVNImplementation(object):
         assert_equal(impl._path_to_root('/branches/'), 'trunk')
         assert_equal(impl._path_to_root('/tags/1.0'), 'tags/1.0')
         assert_equal(impl._path_to_root('/branches/branch'), 'branches/branch')
+
+    @patch('forgesvn.model.svn.svn_path_exists')
+    def test_update_checkout_url(self, svn_path_exists):
+        impl = SVNImplementation(Mock())
+        opts = impl._repo.app.config.options = {}
+
+        svn_path_exists.side_effect = lambda path: False
+        opts['checkout_url'] = 'invalid'
+        impl.update_checkout_url()
+        assert_equal(opts['checkout_url'], '')
+
+        svn_path_exists.side_effect = lambda path: path.endswith('trunk')
+        opts['checkout_url'] = 'invalid'
+        impl.update_checkout_url()
+        assert_equal(opts['checkout_url'], 'trunk')