Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3E4D5C42F for ; Mon, 3 Jun 2013 14:37:48 +0000 (UTC) Received: (qmail 14003 invoked by uid 500); 3 Jun 2013 13:37:47 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 13920 invoked by uid 500); 3 Jun 2013 13:37:47 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 13659 invoked by uid 99); 3 Jun 2013 13:37:43 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Jun 2013 13:37:43 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A0E3F89FC76; Mon, 3 Jun 2013 13:37:43 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: brondsem@apache.org To: allura-commits@incubator.apache.org Date: Mon, 03 Jun 2013 13:37:48 -0000 Message-Id: <98c3e1078a0b4b7bb7ea29e183094664@git.apache.org> In-Reply-To: <5d7115ad9b314c2b9a7e8591476d9f90@git.apache.org> References: <5d7115ad9b314c2b9a7e8591476d9f90@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Fri May 17 13:02:40 2013 +0000 Committer: Dave Brondsema 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()