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 2018/06/11 20:55:06 UTC
allura git commit: [#6070] make svn snapshots based on current
directory, instead of always going to a tag, branch or trunk
Repository: allura
Updated Branches:
refs/heads/master 2114a6cda -> 7335d7e55
[#6070] make svn snapshots based on current directory, instead of always going to a tag, branch or trunk
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/7335d7e5
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/7335d7e5
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/7335d7e5
Branch: refs/heads/master
Commit: 7335d7e555146d241268c6f0da783d632007a39f
Parents: 2114a6c
Author: Dave Brondsema <da...@brondsema.net>
Authored: Mon Jun 11 16:19:51 2018 -0400
Committer: Dave Brondsema <da...@brondsema.net>
Committed: Mon Jun 11 16:54:48 2018 -0400
----------------------------------------------------------------------
ForgeSVN/forgesvn/model/svn.py | 33 ++----
.../tests/functional/test_controllers.py | 30 +----
.../forgesvn/tests/model/test_repository.py | 115 +++++--------------
.../tests/model/test_svnimplementation.py | 36 ++----
4 files changed, 54 insertions(+), 160 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/7335d7e5/ForgeSVN/forgesvn/model/svn.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/model/svn.py b/ForgeSVN/forgesvn/model/svn.py
index 2aa2b40..152ecf0 100644
--- a/ForgeSVN/forgesvn/model/svn.py
+++ b/ForgeSVN/forgesvn/model/svn.py
@@ -69,8 +69,8 @@ class Repository(M.Repository):
return self._impl.commit('HEAD')
def tarball_filename(self, revision, path=None):
- fn = super(Repository, self).tarball_filename(revision, path)
- path = self._impl._path_to_root(path, revision)
+ fn = super(Repository, self).tarball_filename('r'+revision, path)
+ path = self._impl._tarball_path_clean(path, revision)
fn += ('-' + '-'.join(path.split('/'))) if path else ''
return fn
@@ -672,30 +672,17 @@ class SVNImplementation(M.RepositoryImplementation):
log_entry = Object(date='', message='', changed_paths=[])
return [p.path for p in log_entry.changed_paths]
- def _path_to_root(self, path, rev=None):
- '''Return tag/branch/trunk root for given path inside svn repo'''
+ def _tarball_path_clean(self, path, rev=None):
if path:
- path = path.strip('/').split('/')
- idx = None
- if 'tags' in path:
- idx = path.index('tags')
- elif 'branches' in path:
- idx = path.index('branches')
- # e.g. path/tags/tag-1.0/...
- if idx is not None and idx < len(path) - 1:
- 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'), rev)
- if trunk_exists:
- return 'trunk'
- return ''
+ return path.strip('/')
+ else:
+ trunk_exists = svn_path_exists('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, commit)
+ path = self._tarball_path_clean(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)
http://git-wip-us.apache.org/repos/asf/allura/blob/7335d7e5/ForgeSVN/forgesvn/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeSVN/forgesvn/tests/functional/test_controllers.py b/ForgeSVN/forgesvn/tests/functional/test_controllers.py
index 4a537f4..2154c6e 100644
--- a/ForgeSVN/forgesvn/tests/functional/test_controllers.py
+++ b/ForgeSVN/forgesvn/tests/functional/test_controllers.py
@@ -224,7 +224,7 @@ class TestRootController(SVNTestController):
assert 'Your download will begin shortly' in r
@onlyif(os.path.exists(tg.config.get('scm.repos.tarball.zip_binary', '/usr/bin/zip')), 'zip binary is missing')
- def test_tarball_tags_aware(self):
+ def test_tarball_path(self):
h.set_context('test', 'svn-tags', neighborhood='Projects')
shutil.rmtree(c.app.repo.tarball_path, ignore_errors=True)
r = self.app.get('/p/test/svn-tags/19/tree/')
@@ -236,18 +236,15 @@ class TestRootController(SVNTestController):
form = r.html.find('form', 'tarball')
assert_equal(form.button.text, ' Download Snapshot')
assert_equal(form.get('action'), '/p/test/svn-tags/19/tarball')
- assert_equal(
- form.find('input', attrs=dict(name='path')).get('value'), '/tags/tag-1.0')
+ assert_equal(form.find('input', attrs=dict(name='path')).get('value'), '/tags/tag-1.0')
- r = self.app.get(
- '/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0')
+ r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0')
assert_equal(r.json['status'], None)
r = self.app.post('/p/test/svn-tags/19/tarball',
dict(path='/tags/tag-1.0')).follow()
assert 'Generating snapshot...' in r
M.MonQTask.run_ready()
- r = self.app.get(
- '/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0')
+ r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0')
assert_equal(r.json['status'], 'complete')
r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/trunk')
@@ -259,27 +256,12 @@ class TestRootController(SVNTestController):
r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/trunk')
assert_equal(r.json['status'], 'complete')
- r = self.app.get(
- '/p/test/svn-tags/19/tarball_status?path=/branches/aaa/')
+ r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/branches/aaa/')
assert_equal(r.json['status'], None)
- # All of the following also should be ready because...
- # ...this is essentially the same as trunk snapshot
- r = self.app.get(
- '/p/test/svn-tags/19/tarball_status?path=/trunk/some/path/')
- assert_equal(r.json['status'], 'complete')
+ # this is is the same as trunk snapshot, so it's ready already
r = self.app.get('/p/test/svn-tags/19/tarball_status')
assert_equal(r.json['status'], 'complete')
- # ...the same as trunk, 'cause concrete tag isn't specified
- r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/tags/')
- assert_equal(r.json['status'], 'complete')
- # ...the same as trunk, 'cause concrete branch isn't specified
- r = self.app.get('/p/test/svn-tags/19/tarball_status?path=/branches/')
- assert_equal(r.json['status'], 'complete')
- # ...this is essentially the same as tag snapshot
- r = self.app.get(
- '/p/test/svn-tags/19/tarball_status?path=/tags/tag-1.0/dir')
- assert_equal(r.json['status'], 'complete')
class TestImportController(SVNTestController):
http://git-wip-us.apache.org/repos/asf/allura/blob/7335d7e5/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 024c585..a5634ea 100644
--- a/ForgeSVN/forgesvn/tests/model/test_repository.py
+++ b/ForgeSVN/forgesvn/tests/model/test_repository.py
@@ -431,126 +431,69 @@ class TestSVNRepo(unittest.TestCase, RepoImplTestBase):
assert_equal(self.repo.tarball_path,
os.path.join(tmpdir, 'svn/t/te/test/testsvn'))
assert_equal(self.repo.tarball_url('1'),
- 'file:///svn/t/te/test/testsvn/test-src-1.zip')
+ 'file:///svn/t/te/test/testsvn/test-src-r1.zip')
self.repo.tarball('1')
assert os.path.isfile(
- os.path.join(tmpdir, "svn/t/te/test/testsvn/test-src-1.zip"))
+ os.path.join(tmpdir, "svn/t/te/test/testsvn/test-src-r1.zip"))
tarball_zip = ZipFile(
- os.path.join(tmpdir, 'svn/t/te/test/testsvn/test-src-1.zip'), 'r')
+ os.path.join(tmpdir, 'svn/t/te/test/testsvn/test-src-r1.zip'), 'r')
assert_equal(tarball_zip.namelist(),
- ['test-src-1/', 'test-src-1/README'])
+ ['test-src-r1/', 'test-src-r1/README'])
shutil.rmtree(self.repo.tarball_path.encode('utf-8'),
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):
+ def test_tarball_paths(self):
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')
tmpdir = tg.config['scm.repos.tarball.root']
- tarball_path = os.path.join(
- tmpdir, 'svn/t/te/test/testsvn-trunk-tags-branches/')
- fn = tarball_path + 'test-svn-tags-19-tags-tag-1.0.zip'
+ tarball_path = os.path.join(tmpdir, 'svn/t/te/test/testsvn-trunk-tags-branches/')
+
+ # a tag
self.svn_tags.tarball(rev, '/tags/tag-1.0/')
+ fn = tarball_path + 'test-svn-tags-r19-tags-tag-1.0.zip'
assert os.path.isfile(fn), fn
snapshot = ZipFile(fn, 'r')
+ tag_content = sorted(['test-svn-tags-r19-tags-tag-1.0/',
+ 'test-svn-tags-r19-tags-tag-1.0/svn-commit.tmp',
+ 'test-svn-tags-r19-tags-tag-1.0/README'])
assert_equal(sorted(snapshot.namelist()), tag_content)
os.remove(fn)
- self.svn_tags.tarball(rev, '/tags/tag-1.0/some/path/')
- assert os.path.isfile(fn), fn
- snapshot = ZipFile(fn, 'r')
- 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-19-trunk.zip'
- self.svn_tags.tarball(rev, '/tags/')
- assert os.path.isfile(fn), fn
- snapshot = ZipFile(fn, 'r')
- 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):
- 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')
- tmpdir = tg.config['scm.repos.tarball.root']
- tarball_path = os.path.join(
- tmpdir, 'svn/t/te/test/testsvn-trunk-tags-branches/')
- 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(sorted(snapshot.namelist()), branch_content)
- os.remove(fn)
- self.svn_tags.tarball(rev, '/branches/aaa/some/path/')
+ # a directory (of tags)
+ self.svn_tags.tarball(rev, '/tags/')
+ fn = tarball_path + 'test-svn-tags-r19-tags.zip'
assert os.path.isfile(fn), fn
snapshot = ZipFile(fn, 'r')
- assert_equal(sorted(snapshot.namelist()), branch_content)
+ tags_content = sorted(['test-svn-tags-r19-tags/',
+ 'test-svn-tags-r19-tags/tag-1.0/',
+ 'test-svn-tags-r19-tags/tag-1.0/svn-commit.tmp',
+ 'test-svn-tags-r19-tags/tag-1.0/README'])
+ assert_equal(sorted(snapshot.namelist()), tags_content)
os.remove(fn)
- # if inside of branches, but no branch is specified
- # expect snapshot of trunk
- 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(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):
- 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')
- tmpdir = tg.config['scm.repos.tarball.root']
- tarball_path = os.path.join(
- tmpdir, 'svn/t/te/test/testsvn-trunk-tags-branches/')
- 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(sorted(snapshot.namelist()), trunk_content)
- os.remove(fn)
- self.svn_tags.tarball(rev, '/trunk/some/path/')
- assert os.path.isfile(fn), fn
- snapshot = ZipFile(fn, 'r')
- 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(rev)
+ fn = tarball_path + 'test-svn-tags-r19-trunk.zip'
assert os.path.isfile(fn), fn
snapshot = ZipFile(fn, 'r')
+ trunk_content = sorted(['test-svn-tags-r19-trunk/',
+ 'test-svn-tags-r19-trunk/aaa.txt',
+ 'test-svn-tags-r19-trunk/bbb.txt',
+ 'test-svn-tags-r19-trunk/ccc.txt',
+ 'test-svn-tags-r19-trunk/README'])
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 = os.path.join(tmpdir, 'svn/t/te/test/testsvn/test-src-1.zip')
+ fn = os.path.join(tmpdir, 'svn/t/te/test/testsvn/test-src-r1.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'])
+ assert_equal(snapshot.namelist(), ['test-src-r1/', 'test-src-r1/README'])
shutil.rmtree(os.path.join(tmpdir, 'svn/t/te/test/testsvn/'),
ignore_errors=True)
shutil.rmtree(tarball_path, ignore_errors=True)
http://git-wip-us.apache.org/repos/asf/allura/blob/7335d7e5/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 216255d..70cf129 100644
--- a/ForgeSVN/forgesvn/tests/model/test_svnimplementation.py
+++ b/ForgeSVN/forgesvn/tests/model/test_svnimplementation.py
@@ -78,41 +78,23 @@ class TestSVNImplementation(object):
[0], 'file://' + g.tmpdir + '/code/trunk')
@patch('forgesvn.model.svn.svn_path_exists')
- def test__path_to_root(self, path_exists):
+ def test__tarball_path_clean(self, path_exists):
repo = Mock(fs_path=g.tmpdir + '/')
repo.name = 'code'
repo._id = '5057636b9c1040636b81e4b1'
impl = SVNImplementation(repo)
path_exists.return_value = False
# edge cases
- assert_equal(impl._path_to_root(None), '')
- assert_equal(impl._path_to_root(''), '')
- assert_equal(impl._path_to_root('/some/path/'), '')
- assert_equal(impl._path_to_root('some/path'), '')
- # tags
- assert_equal(impl._path_to_root('/some/path/tags/1.0/some/dir'),
- 'some/path/tags/1.0')
- assert_equal(impl._path_to_root('/some/path/tags/1.0/'),
- 'some/path/tags/1.0')
- assert_equal(impl._path_to_root('/some/path/tags/'), '')
- # branches
- assert_equal(impl._path_to_root('/some/path/branches/b1/dir'),
- 'some/path/branches/b1')
- assert_equal(impl._path_to_root('/some/path/branches/b1/'),
- 'some/path/branches/b1')
- assert_equal(impl._path_to_root('/some/path/branches/'), '')
- # trunk
- assert_equal(impl._path_to_root('/some/path/trunk/some/dir/'),
- 'some/path/trunk')
- assert_equal(impl._path_to_root('/some/path/trunk'), 'some/path/trunk')
+ assert_equal(impl._tarball_path_clean(None), '')
+ assert_equal(impl._tarball_path_clean(''), '')
+ # common
+ assert_equal(impl._tarball_path_clean('/some/path/'), 'some/path')
+ assert_equal(impl._tarball_path_clean('some/path'), 'some/path')
+ assert_equal(impl._tarball_path_clean('/some/path/tags/1.0/some/dir'), 'some/path/tags/1.0/some/dir')
# with fallback to trunk
path_exists.return_value = True
- assert_equal(impl._path_to_root(''), 'trunk')
- assert_equal(impl._path_to_root('/some/path/'), 'trunk')
- assert_equal(impl._path_to_root('/tags/'), 'trunk')
- 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')
+ assert_equal(impl._tarball_path_clean(None), 'trunk')
+ assert_equal(impl._tarball_path_clean(''), 'trunk')
@patch('forgesvn.model.svn.svn_path_exists')
def test_update_checkout_url(self, svn_path_exists):