You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2013/06/03 15:37:48 UTC

[06/21] git commit: [#6235] ticket:352 Path-aware svn snapshots

[#6235] ticket:352 Path-aware svn snapshots


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

Branch: refs/heads/master
Commit: 43364b23aa54f39829dedd349406c670015850a8
Parents: d01f821
Author: Igor Bondarenko <je...@gmail.com>
Authored: Fri May 17 13:02:40 2013 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Fri May 31 22:14:07 2013 +0000

----------------------------------------------------------------------
 ForgeSVN/forgesvn/model/svn.py                   |   16 ++-
 ForgeSVN/forgesvn/tests/model/test_repository.py |  100 +++++++++--------
 2 files changed, 64 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/43364b23/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index b649dae..8c65f78 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -114,10 +114,14 @@ class SVNCalledProcessError(Exception):
             (self.cmd, self.returncode, self.stdout, self.stderr)
 
 
-def svn_path_exists(path):
+def svn_path_exists(path, rev=None):
     svn = SVNLibWrapper(pysvn.Client())
+    if rev:
+        rev = pysvn.Revision(pysvn.opt_revision_kind.number, rev)
+    else:
+        rev = pysvn.Revision(pysvn.opt_revision_kind.unspecified)
     try:
-        svn.info2(path)
+        svn.info2(path, revision=rev)
         return True
     except pysvn.ClientError:
         return False
@@ -636,7 +640,7 @@ class SVNImplementation(M.RepositoryImplementation):
                 entries[path] = self._oid(info.last_changed_rev.number)
         return entries
 
-    def _path_to_root(self, path):
+    def _path_to_root(self, path, rev=None):
         '''Return tag/branch/trunk root for given path inside svn repo'''
         if path:
             path = path.strip('/').split('/')
@@ -652,13 +656,13 @@ class SVNImplementation(M.RepositoryImplementation):
                 return '/'.join(path[:idx + 1])  # path/trunk
         # no tag/brach/trunk in path
         trunk_exists = svn_path_exists(
-            'file://%s%s/%s' % (self._repo.fs_path, self._repo.name, 'trunk'))
+            'file://%s%s/%s' % (self._repo.fs_path, self._repo.name, 'trunk'), rev)
         if trunk_exists:
             return 'trunk'
         return ''
 
     def tarball(self, commit, path=None):
-        path = self._path_to_root(path)
+        path = self._path_to_root(path, commit)
         if not os.path.exists(self._repo.tarball_path):
             os.makedirs(self._repo.tarball_path)
         archive_name = self._repo.tarball_filename(commit, path)
@@ -666,7 +670,7 @@ class SVNImplementation(M.RepositoryImplementation):
         filename = os.path.join(self._repo.tarball_path, '%s%s' % (archive_name, '.zip'))
         tmpfilename = os.path.join(self._repo.tarball_path, '%s%s' % (archive_name, '.tmp'))
         rmtree(dest, ignore_errors=True)
-        path = os.path.join(self._url, '')#path)
+        path = os.path.join(self._url, path)
         try:
             self._svn.export(path,
                              dest,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/43364b23/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 e131764..28b980b 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -310,105 +310,113 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
         assert os.path.isfile(os.path.join(tmpdir, "svn/t/te/test/testsvn/test-src-1.zip"))
         tarball_zip = ZipFile(os.path.join(tmpdir, 'svn/t/te/test/testsvn/test-src-1.zip'), 'r')
         assert_equal(tarball_zip.namelist(), ['test-src-1/', 'test-src-1/README'])
+        shutil.rmtree(self.repo.tarball_path, ignore_errors=True)
 
     @onlyif(os.path.exists(tg.config.get('scm.repos.tarball.zip_binary', '/usr/bin/zip')), 'zip binary is missing')
     def test_tarball_aware_of_tags(self):
-        tag_content = ['test-svn-tags-1-tags-tag-1.0/',
-                       'test-svn-tags-1-tags-tag-1.0/svn-commit.tmp',
-                       'test-svn-tags-1-tags-tag-1.0/README']
+        rev = '19'
+        tag_content = sorted(['test-svn-tags-19-tags-tag-1.0/',
+                              'test-svn-tags-19-tags-tag-1.0/svn-commit.tmp',
+                              'test-svn-tags-19-tags-tag-1.0/README'])
         h.set_context('test', 'svn-tags', neighborhood='Projects')
         tarball_path = '/tmp/tarball/svn/t/te/test/testsvn-trunk-tags-branches/'
-        fn = tarball_path + 'test-svn-tags-1-tags-tag-1.0.zip'
-        self.svn_tags.tarball('1', '/tags/tag-1.0/')
+        fn = tarball_path + 'test-svn-tags-19-tags-tag-1.0.zip'
+        self.svn_tags.tarball(rev, '/tags/tag-1.0/')
         assert os.path.isfile(fn), fn
         snapshot = ZipFile(fn, 'r')
-        assert_equal(snapshot.namelist(), tag_content)
+        assert_equal(sorted(snapshot.namelist()), tag_content)
         os.remove(fn)
-        self.svn_tags.tarball('1', '/tags/tag-1.0/some/path/')
+        self.svn_tags.tarball(rev, '/tags/tag-1.0/some/path/')
         assert os.path.isfile(fn), fn
         snapshot = ZipFile(fn, 'r')
-        assert_equal(snapshot.namelist(), tag_content)
+        assert_equal(sorted(snapshot.namelist()), tag_content)
         os.remove(fn)
         # if inside of tags, but no tag is specified
         # expect snapshot of trunk
-        fn = tarball_path + 'test-svn-tags-1-trunk.zip'
-        self.svn_tags.tarball('1', '/tags/')
+        fn = tarball_path + 'test-svn-tags-19-trunk.zip'
+        self.svn_tags.tarball(rev, '/tags/')
         assert os.path.isfile(fn), fn
         snapshot = ZipFile(fn, 'r')
-        assert_equal(snapshot.namelist(), ['test-svn-tags-1-trunk/',
-                                           'test-svn-tags-1-trunk/aaa.txt',
-                                           'test-svn-tags-1-trunk/bbb.txt',
-                                           'test-svn-tags-1-trunk/ccc.txt',
-                                           'test-svn-tags-1-trunk/README'])
-        os.remove(fn)
+        assert_equal(sorted(snapshot.namelist()),
+                     sorted(['test-svn-tags-19-trunk/',
+                             'test-svn-tags-19-trunk/aaa.txt',
+                             'test-svn-tags-19-trunk/bbb.txt',
+                             'test-svn-tags-19-trunk/ccc.txt',
+                             'test-svn-tags-19-trunk/README']))
+        shutil.rmtree(tarball_path, ignore_errors=True)
 
     @onlyif(os.path.exists(tg.config.get('scm.repos.tarball.zip_binary', '/usr/bin/zip')), 'zip binary is missing')
     def test_tarball_aware_of_branches(self):
-        branch_content = ['test-svn-tags-1-branches-aaa/',
-                          'test-svn-tags-1-branches-aaa/aaa.txt',
-                          'test-svn-tags-1-branches-aaa/svn-commit.tmp',
-                          'test-svn-tags-1-branches-aaa/README']
+        rev = '19'
+        branch_content = sorted(['test-svn-tags-19-branches-aaa/',
+                                 'test-svn-tags-19-branches-aaa/aaa.txt',
+                                 'test-svn-tags-19-branches-aaa/svn-commit.tmp',
+                                 'test-svn-tags-19-branches-aaa/README'])
         h.set_context('test', 'svn-tags', neighborhood='Projects')
         tarball_path = '/tmp/tarball/svn/t/te/test/testsvn-trunk-tags-branches/'
-        fn = tarball_path + 'test-svn-tags-1-branches-aaa.zip'
-        self.svn_tags.tarball('1', '/branches/aaa/')
+        fn = tarball_path + 'test-svn-tags-19-branches-aaa.zip'
+        self.svn_tags.tarball(rev, '/branches/aaa/')
         assert os.path.isfile(fn), fn
         snapshot = ZipFile(fn, 'r')
-        assert_equal(snapshot.namelist(), branch_content)
+        assert_equal(sorted(snapshot.namelist()), branch_content)
         os.remove(fn)
-        self.svn_tags.tarball('1', '/branches/aaa/some/path/')
+        self.svn_tags.tarball(rev, '/branches/aaa/some/path/')
         assert os.path.isfile(fn), fn
         snapshot = ZipFile(fn, 'r')
-        assert_equal(snapshot.namelist(), branch_content)
+        assert_equal(sorted(snapshot.namelist()), branch_content)
         os.remove(fn)
         # if inside of branches, but no branch is specified
         # expect snapshot of trunk
-        fn = tarball_path + 'test-svn-tags-1-trunk.zip'
-        self.svn_tags.tarball('1', '/branches/')
+        fn = tarball_path + 'test-svn-tags-19-trunk.zip'
+        self.svn_tags.tarball(rev, '/branches/')
         assert os.path.isfile(fn), fn
         snapshot = ZipFile(fn, 'r')
-        assert_equal(snapshot.namelist(), ['test-svn-tags-1-trunk/',
-                                           'test-svn-tags-1-trunk/aaa.txt',
-                                           'test-svn-tags-1-trunk/bbb.txt',
-                                           'test-svn-tags-1-trunk/ccc.txt',
-                                           'test-svn-tags-1-trunk/README'])
-        os.remove(fn)
+        assert_equal(sorted(snapshot.namelist()),
+                     sorted(['test-svn-tags-19-trunk/',
+                             'test-svn-tags-19-trunk/aaa.txt',
+                             'test-svn-tags-19-trunk/bbb.txt',
+                             'test-svn-tags-19-trunk/ccc.txt',
+                             'test-svn-tags-19-trunk/README']))
+        shutil.rmtree(tarball_path, ignore_errors=True)
 
     @onlyif(os.path.exists(tg.config.get('scm.repos.tarball.zip_binary', '/usr/bin/zip')), 'zip binary is missing')
     def test_tarball_aware_of_trunk(self):
-        trunk_content = ['test-svn-tags-1-trunk/',
-                        'test-svn-tags-1-trunk/aaa.txt',
-                        'test-svn-tags-1-trunk/bbb.txt',
-                        'test-svn-tags-1-trunk/ccc.txt',
-                        'test-svn-tags-1-trunk/README']
+        rev = '19'
+        trunk_content = sorted(['test-svn-tags-19-trunk/',
+                                'test-svn-tags-19-trunk/aaa.txt',
+                                'test-svn-tags-19-trunk/bbb.txt',
+                                'test-svn-tags-19-trunk/ccc.txt',
+                                'test-svn-tags-19-trunk/README'])
         h.set_context('test', 'svn-tags', neighborhood='Projects')
         tarball_path = '/tmp/tarball/svn/t/te/test/testsvn-trunk-tags-branches/'
-        fn = tarball_path + 'test-svn-tags-1-trunk.zip'
-        self.svn_tags.tarball('1', '/trunk/')
+        fn = tarball_path + 'test-svn-tags-19-trunk.zip'
+        self.svn_tags.tarball(rev, '/trunk/')
         assert os.path.isfile(fn), fn
         snapshot = ZipFile(fn, 'r')
-        assert_equal(snapshot.namelist(), trunk_content)
+        assert_equal(sorted(snapshot.namelist()), trunk_content)
         os.remove(fn)
-        self.svn_tags.tarball('1', '/trunk/some/path/')
+        self.svn_tags.tarball(rev, '/trunk/some/path/')
         assert os.path.isfile(fn), fn
         snapshot = ZipFile(fn, 'r')
-        assert_equal(snapshot.namelist(), trunk_content)
+        assert_equal(sorted(snapshot.namelist()), trunk_content)
         os.remove(fn)
         # no path, but there are trunk in the repo
         # expect snapshot of trunk
-        self.svn_tags.tarball('1')
+        self.svn_tags.tarball(rev)
         assert os.path.isfile(fn), fn
         snapshot = ZipFile(fn, 'r')
-        assert_equal(snapshot.namelist(), trunk_content)
+        assert_equal(sorted(snapshot.namelist()), trunk_content)
         os.remove(fn)
         # no path, and no trunk dir
         # expect snapshot of repo root
+        h.set_context('test', 'src', neighborhood='Projects')
         fn = '/tmp/tarball/svn/t/te/test/testsvn/test-src-1.zip'
         self.repo.tarball('1')
         assert os.path.isfile(fn), fn
         snapshot = ZipFile(fn, 'r')
         assert_equal(snapshot.namelist(), ['test-src-1/', 'test-src-1/README'])
-        os.remove(fn)
+        shutil.rmtree('/tmp/tarball/svn/t/te/test/testsvn/', ignore_errors=True)
+        shutil.rmtree(tarball_path, ignore_errors=True)
 
     def test_is_empty(self):
         assert not self.repo.is_empty()