incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/3] git commit: [#4961] Added hotcopy guard
Date Wed, 02 Jan 2013 17:37:31 GMT
[#4961] Added hotcopy guard


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

Branch: refs/heads/master
Commit: 7662a9f603be256e99a43a0ee026d0333844f0d4
Parents: 4d66c18
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Thu Dec 13 21:01:13 2012 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Wed Jan 2 16:58:21 2013 +0000

----------------------------------------------------------------------
 ForgeSVN/forgesvn/model/svn.py                   |   36 ++++++++++------
 ForgeSVN/forgesvn/tests/model/test_repository.py |   25 +++++++++--
 2 files changed, 42 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7662a9f6/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index 900f288..63deb88 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -13,6 +13,7 @@ import tempfile
 
 import tg
 import pysvn
+from paste.deploy.converters import asbool
 from pymongo.errors import DuplicateKeyError
 from pylons import tmpl_context as c, app_globals as g
 
@@ -22,7 +23,6 @@ from ming.utils import LazyProperty
 
 from allura import model as M
 from allura.lib import helpers as h
-from allura.model.repository import GitLikeTree
 from allura.model.auth import User
 from allura.lib.utils import svn_path_exists
 
@@ -162,6 +162,22 @@ class SVNImplementation(M.RepositoryImplementation):
             shutil.rmtree(tmp_working_dir)
             log.info('deleted %s', tmp_working_dir)
 
+    def can_hotcopy(self, source_url):
+        if not (asbool(tg.config.get('scm.svn.hotcopy', True)) and
+                source_url.startswith('file://')):
+            return False
+        stdout, stderr = self.check_call(['svn', '--version'])
+        return bool(re.search('version 1.7', stdout))
+
+    def check_call(self, cmd):
+        p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
+        stdout, stderr = p.communicate(input='p\n')
+        if p.returncode != 0:
+            self._repo.status = 'ready'
+            session(self._repo).flush(self._repo)
+            raise SVNCalledProcessError(cmd, p.returncode, stdout, stderr)
+        return stdout, stderr
+
     def clone_from(self, source_url):
         '''Initialize a repo as a clone of another using svnsync'''
         self.init(default_dirs=False, skip_special_files=True)
@@ -173,36 +189,28 @@ class SVNImplementation(M.RepositoryImplementation):
                 fp.write('#!/bin/sh\n')
             os.chmod(fn, 0755)
 
-        def check_call(cmd):
-            p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
-            stdout, stderr = p.communicate(input='p\n')
-            if p.returncode != 0:
-                self._repo.status = 'ready'
-                session(self._repo).flush(self._repo)
-                raise SVNCalledProcessError(cmd, p.returncode, stdout, stderr)
-
         self._repo.status = 'importing'
         session(self._repo).flush(self._repo)
         log.info('Initialize %r as a clone of %s',
                  self._repo, source_url)
 
-        if source_url.startswith('file://'):
+        if self.can_hotcopy(source_url):
             # src repo is on the local filesystem - use hotcopy (faster)
             source_path, dest_path = source_url[7:], self._url[7:]
             fullname = os.path.join(self._repo.fs_path, self._repo.name)
             # hotcopy expects dest dir to not exist yet
             if os.path.exists(fullname):
                 shutil.rmtree(fullname)
-            check_call(['svnadmin', 'hotcopy', source_path, dest_path])
+            self.check_call(['svnadmin', 'hotcopy', source_path, dest_path])
             # make sure new repo has a pre-revprop-change hook,
             # otherwise the sync will fail
             set_hook('pre-revprop-change')
-            check_call(['svnsync', '--non-interactive', '--allow-non-empty',
+            self.check_call(['svnsync', '--non-interactive', '--allow-non-empty',
               'initialize', self._url, source_url])
         else:
             set_hook('pre-revprop-change')
-            check_call(['svnsync', 'init', self._url, source_url])
-            check_call(['svnsync', '--non-interactive', 'sync', self._url])
+            self.check_call(['svnsync', 'init', self._url, source_url])
+            self.check_call(['svnsync', '--non-interactive', 'sync', self._url])
 
         log.info('... %r cloned', self._repo)
         if not svn_path_exists("file://%s%s/%s" %

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7662a9f6/ForgeSVN/forgesvn/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/model/test_repository.py b/ForgeSVN/forgesvn/tests/model/test_repository.py
index d4f8f6c..2922c90 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -2,7 +2,7 @@ import os
 import shutil
 import unittest
 import pkg_resources
-from itertools import count
+from itertools import count, product
 from datetime import datetime
 
 from pylons import c
@@ -134,8 +134,6 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
         assert os.access('/tmp/testsvn/hooks/pre-revprop-change', os.X_OK)
         with open('/tmp/testsvn/hooks/pre-revprop-change') as f: c = f.read()
         self.assertEqual(c, '#!/bin/sh\n')
-        # assert not os.path.exists('/tmp/testsvn/hooks/post-revprop-change')
-        # assert not os.path.exists('/tmp/testsvn/hooks/post-commit-user')
         assert os.path.exists('/tmp/testsvn/hooks/post-commit')
         assert os.access('/tmp/testsvn/hooks/post-commit', os.X_OK)
         with open('/tmp/testsvn/hooks/post-commit') as f: c = f.read()
@@ -147,6 +145,25 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
 
         shutil.rmtree(dirname)
 
+    @mock.patch('forgesvn.model.svn.tg')
+    def test_can_hotcopy(self, tg):
+        from forgesvn.model.svn import SVNImplementation
+        func = SVNImplementation.can_hotcopy
+        obj = mock.Mock(spec=SVNImplementation)
+        for combo in product(
+                ['file:///myfile', 'http://myfile'],
+                [True, False],
+                ['version 1.7', 'version 1.6']):
+            source_url = combo[0]
+            tg.config = {'scm.svn.hotcopy': combo[1]}
+            stdout = combo[2]
+            obj.check_call.return_value = stdout, ''
+            expected = (source_url.startswith('file://') and
+                    tg.config['scm.svn.hotcopy'] and
+                    stdout == 'version 1.7')
+            result = func(obj, source_url)
+            assert result == expected
+
     @mock.patch('forgesvn.model.svn.g.post_event')
     def test_clone(self, post_event):
         repo = SM.Repository(
@@ -166,8 +183,6 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
         assert os.access('/tmp/testsvn/hooks/pre-revprop-change', os.X_OK)
         with open('/tmp/testsvn/hooks/pre-revprop-change') as f: c = f.read()
         self.assertEqual(c, '#!/bin/sh\n')
-        # assert not os.path.exists('/tmp/testsvn/hooks/post-revprop-change')
-        # assert not os.path.exists('/tmp/testsvn/hooks/post-commit-user')
         assert os.path.exists('/tmp/testsvn/hooks/post-commit')
         assert os.access('/tmp/testsvn/hooks/post-commit', os.X_OK)
         with open('/tmp/testsvn/hooks/post-commit') as f: c = f.read()


Mime
View raw message