You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2012/10/30 18:30:04 UTC
[1/48] git commit: [#5005] Added NFS-style repo path config support
Updated Branches:
refs/heads/cj/5005 43e312126 -> f6606f035 (forced update)
[#5005] Added NFS-style repo path config support
Signed-off-by: Cory Johns <jo...@geek.net>
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/f6606f03
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/f6606f03
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/f6606f03
Branch: refs/heads/cj/5005
Commit: f6606f035e61604374398534b4e0735a0f8e6904
Parents: 2350045
Author: Cory Johns <jo...@geek.net>
Authored: Thu Oct 11 16:28:15 2012 +0000
Committer: Cory Johns <jo...@geek.net>
Committed: Tue Oct 30 17:29:13 2012 +0000
----------------------------------------------------------------------
Allura/allura/lib/helpers.py | 16 ++++++++++++++++
Allura/allura/model/repository.py | 12 ++++++++++--
Allura/allura/tests/model/test_repo.py | 26 ++++++++++++++++++++++++++
3 files changed, 52 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f6606f03/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 4cf3fbc..d023153 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -164,6 +164,22 @@ def push_config(obj, **kw):
for k in new_attrs:
delattr(obj, k)
+@contextmanager
+def pop_config(obj, *keys):
+ saved_attrs = {}
+ new_attrs = []
+ for k in keys:
+ try:
+ saved_attrs[k] = getattr(obj, k)
+ delattr(obj, k)
+ except AttributeError:
+ pass
+ try:
+ yield obj
+ finally:
+ for k, v in saved_attrs.iteritems():
+ setattr(obj, k, v)
+
def sharded_path(name, num_parts=2):
parts = [
name[:i + 1]
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f6606f03/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 2f2328a..f10770e 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -179,8 +179,16 @@ class Repository(Artifact, ActivityObject):
@classmethod
def default_fs_path(cls, project, tool):
- repos_root = tg.config.get('scm.repos.root', '/')
- return os.path.join(repos_root, tool, project.url()[1:])
+ repos_root = tg.config.get('scm.repos.root.%s' % tool)
+ if repos_root:
+ return os.path.join(
+ repos_root,
+ project.shortname[:1],
+ project.shortname[:2],
+ project.shortname)
+ else:
+ repos_root = tg.config.get('scm.repos.root', '/')
+ return os.path.join(repos_root, tool, project.url()[1:])
@classmethod
def default_url_path(cls, project, tool):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/f6606f03/Allura/allura/tests/model/test_repo.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/model/test_repo.py b/Allura/allura/tests/model/test_repo.py
index 90eaac1..d3fd8d0 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -1,9 +1,35 @@
+import unittest
+
from nose.tools import assert_equal
from pylons import c
+import tg
+import mock
+from allura.lib import helpers as h
from alluratest.controller import setup_basic_test, setup_global_objects
from allura import model as M
+class TestRepoFileSystemPath(unittest.TestCase):
+ def test_fs_path(self):
+ with h.push_config(tg.config, **{'scm.repos.root.git': '/foo/bar'}):
+ fs_path = M.Repository.default_fs_path(mock.Mock(shortname='grundel'), 'git')
+ assert_equal(fs_path, '/foo/bar/g/gr/grundel')
+
+ def test_fs_path_fallback(self):
+ with h.push_config(tg.config, **{'scm.repos.root': '/foo/bar'}):
+ project = mock.Mock(shortname='hanzel')
+ project.url.return_value = '/p/grettel'
+ fs_path = M.Repository.default_fs_path(project, 'git')
+ assert_equal(fs_path, '/foo/bar/git/p/grettel')
+
+ def test_fs_path_fallback_fallback(self):
+ with h.pop_config(tg.config, 'scm.repos.root', 'scm.repos.root.git'):
+ project = mock.Mock(shortname='hanzel')
+ project.url.return_value = '/p/grettel'
+ fs_path = M.Repository.default_fs_path(project, 'git')
+ assert_equal(fs_path, '/git/p/grettel')
+
+
class TestGitLikeTree(object):
def test_set_blob(self):