incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject git commit: [#5005] Added NFS-style repo path config support
Date Thu, 11 Oct 2012 16:28:32 GMT
Updated Branches:
  refs/heads/cj/5005 [created] 43e312126


[#5005] Added NFS-style repo path config support

Signed-off-by: Cory Johns <johnsca@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/43e31212
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/43e31212
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/43e31212

Branch: refs/heads/cj/5005
Commit: 43e312126cca8f709572bc4e37bba7c26879de52
Parents: 5d253a0
Author: Cory Johns <johnsca@geek.net>
Authored: Thu Oct 11 16:28:15 2012 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Thu Oct 11 16:28:15 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/helpers.py           |   16 ++++++++++++++++
 Allura/allura/model/repository.py      |   12 ++++++++++--
 Allura/allura/tests/model/test_repo.py |   19 +++++++++++++++++++
 3 files changed, 45 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/43e31212/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/43e31212/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 3635cbe..a6bb8e4 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -175,8 +175,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/43e31212/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 2b20b44..2d33d4e 100644
--- a/Allura/allura/tests/model/test_repo.py
+++ b/Allura/allura/tests/model/test_repo.py
@@ -247,6 +247,25 @@ class TestRepo(_TestWithRepo):
         finally:
             M.Project.app_instance = old_app_instance
 
+    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 TestMergeRequest(_TestWithRepoAndCommit):
 
     def setUp(self):


Mime
View raw message