incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [06/38] git commit: [#6235] ticket:352 tags/branches/trunk aware snapshot names
Date Mon, 03 Jun 2013 19:19:05 GMT
[#6235] ticket:352 tags/branches/trunk aware snapshot names


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

Branch: refs/heads/cj/6218
Commit: 8e25e0c03b895e39ca123441ebcdf1a0ec3df9e5
Parents: 77ae4f6
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Fri May 17 12:09:26 2013 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri May 31 22:14:05 2013 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py                |   17 +++++---
 ForgeSVN/forgesvn/model/svn.py                   |   40 +++++++++++++----
 ForgeSVN/forgesvn/tests/model/test_repository.py |   29 +++++++-----
 3 files changed, 58 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8e25e0c0/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 37b95ab..b728987 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -132,7 +132,7 @@ class RepositoryImplementation(object):
         '''Return count of the commits related to path'''
         raise NotImplementedError, 'commits_count'
 
-    def tarball(self, revision):
+    def tarball(self, revision, path=None):
         '''Create a tarball for the revision'''
         raise NotImplementedError, 'tarball'
 
@@ -266,10 +266,13 @@ class Repository(Artifact, ActivityObject):
                             self.project.shortname,
                             self.name)
 
-    def tarball_filename(self, revision):
+    def tarball_filename(self, revision, path=None):
         shortname = c.project.shortname.replace('/', '-')
         mount_point = c.app.config.options.mount_point
         filename = '%s-%s-%s' % (shortname, mount_point, revision)
+        if path:
+            path = path.strip('/')
+            filename += '-' + '-'.join(path.split('/'))
         return filename
 
     def tarball_url(self, revision):
@@ -282,8 +285,8 @@ class Repository(Artifact, ActivityObject):
                          filename)
         return urljoin(tg.config.get('scm.repos.tarball.url_prefix', '/'), r)
 
-    def get_tarball_status(self, revision):
-        pathname = os.path.join(self.tarball_path, self.tarball_filename(revision))
+    def get_tarball_status(self, revision, path=None):
+        pathname = os.path.join(self.tarball_path, self.tarball_filename(revision, path))
         filename = '%s%s' % (pathname, '.zip')
         tmpfilename = '%s%s' % (pathname, '.tmp')
 
@@ -551,8 +554,10 @@ class Repository(Artifact, ActivityObject):
     def forks(self):
         return self.query.find({'upstream_repo.name': self.url()}).all()
 
-    def tarball(self, revision):
-        self._impl.tarball(revision)
+    def tarball(self, revision, path=None):
+        if path:
+            path = path.strip('/')
+        self._impl.tarball(revision, path)
 
 class MergeRequest(VersionedArtifact, ActivityObject):
     statuses=['open', 'merged', 'rejected']

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8e25e0c0/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index 2189a7f..b649dae 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -636,23 +636,45 @@ class SVNImplementation(M.RepositoryImplementation):
                 entries[path] = self._oid(info.last_changed_rev.number)
         return entries
 
-    def tarball(self, commit):
+    def _path_to_root(self, path):
+        '''Return tag/branch/trunk root for given path inside svn repo'''
+        if path:
+            path = path.strip('/').split('/')
+            idx = None
+            if 'tags' in path:
+                idx = path.index('tags')
+            elif 'branches' in path:
+                idx = path.index('branches')
+            if idx is not None and idx < len(path) - 1:  # e.g. path/tags/tag-1.0/...
+                return '/'.join(path[:idx + 2])  # path/tags/tag-1.0
+            if 'trunk' in path:
+                idx = path.index('trunk')
+                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'))
+        if trunk_exists:
+            return 'trunk'
+        return ''
+
+    def tarball(self, commit, path=None):
+        path = self._path_to_root(path)
         if not os.path.exists(self._repo.tarball_path):
             os.makedirs(self._repo.tarball_path)
-        archive_name = self._repo.tarball_filename(commit)
-        path = os.path.join(self._repo.tarball_path, archive_name)
+        archive_name = self._repo.tarball_filename(commit, path)
+        dest = os.path.join(self._repo.tarball_path, archive_name)
         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'))
-        if os.path.exists(path):
-            rmtree(path)
+        rmtree(dest, ignore_errors=True)
+        path = os.path.join(self._url, '')#path)
         try:
-            self._svn.export(self._url,
-                             path,
+            self._svn.export(path,
+                             dest,
                              revision=pysvn.Revision(pysvn.opt_revision_kind.number, commit))
-            zipdir(path, tmpfilename)
+            zipdir(dest, tmpfilename)
             os.rename(tmpfilename, filename)
         finally:
-            rmtree(path)
+            rmtree(dest, ignore_errors=True)
             if os.path.exists(tmpfilename):
                 os.remove(tmpfilename)
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/8e25e0c0/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 c528004..9a22ae1 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -314,60 +314,63 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
     @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):
         # TODO: check zip that it actually contains only needed files
-        tarball_path = '/tmp/tarball/svn/t/te/test/svn-tags/'
+        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/')
-        assert os.path.isfile(fn)
+        assert os.path.isfile(fn), fn
         os.remove(fn)
         self.svn_tags.tarball('1', '/tags/tag-1.0/some/path/')
-        assert os.path.isfile(fn)
+        assert os.path.isfile(fn), fn
         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/')
-        assert os.path.isfile(fn)
+        assert os.path.isfile(fn), fn
         os.remove(fn)
 
     @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):
         # TODO: check zip that it actually contains only needed files
-        tarball_path = '/tmp/tarball/svn/t/te/test/svn-tags/'
+        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/')
-        assert os.path.isfile(fn)
+        assert os.path.isfile(fn), fn
         os.remove(fn)
         self.svn_tags.tarball('1', '/branches/aaa/some/path/')
-        assert os.path.isfile(fn)
+        assert os.path.isfile(fn), fn
         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/')
-        assert os.path.isfile(fn)
+        assert os.path.isfile(fn), fn
         os.remove(fn)
 
     @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):
         # TODO: check zip that it actually contains only needed files
-        tarball_path = '/tmp/tarball/svn/t/te/test/svn-tags/'
+        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/')
-        assert os.path.isfile(fn)
+        assert os.path.isfile(fn), fn
         os.remove(fn)
         self.svn_tags.tarball('1', '/trunk/some/path/')
-        assert os.path.isfile(fn)
+        assert os.path.isfile(fn), fn
         os.remove(fn)
         # no path, but there are trunk in the repo
         # expect snapshot of trunk
         self.svn_tags.tarball('1')
-        assert os.path.isfile(fn)
+        assert os.path.isfile(fn), fn
         os.remove(fn)
         # no path, and no trunk dir
         # expect snapshot of repo root
         fn = '/tmp/tarball/svn/t/te/test/testsvn/test-src-1.zip'
         self.repo.tarball('1')
-        assert os.path.isfile(fn)
+        assert os.path.isfile(fn), fn
         os.remove(fn)
 
     def test_is_empty(self):


Mime
View raw message