]> source.dussan.org Git - gitblit.git/commitdiff
Add recursion depth control for repository search (issue 103)
authorJames Moger <james.moger@gitblit.com>
Wed, 1 Aug 2012 13:48:06 +0000 (09:48 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 1 Aug 2012 13:48:06 +0000 (09:48 -0400)
distrib/gitblit.properties
docs/04_releases.mkd
src/com/gitblit/AddIndexedBranch.java
src/com/gitblit/GitBlit.java
src/com/gitblit/utils/JGitUtils.java
tests/com/gitblit/tests/JGitUtilsTest.java

index 4c4372ea88593f6e3f03e70403e15c60dbc50bd7..f06aaef42a15364fc587a3b8b676410e925dab9f 100644 (file)
@@ -21,6 +21,12 @@ git.repositoriesFolder = git
 # SINCE 0.5.0\r
 git.searchRepositoriesSubfolders = true\r
 \r
+# Maximum number of folders to recurse into when searching for repositories.\r
+# The default value, -1, disables depth limits.\r
+#\r
+# SINCE 1.0.1\r
+git.searchRecursionDepth = -1\r
+\r
 # Allow push/pull over http/https with JGit servlet.\r
 # If you do NOT want to allow Git clients to clone/push to Gitblit set this\r
 # to false.  You might want to do this if you are only using ssh:// or git://.\r
index 13b31ab767bedf1f870a4790658c3e52febcb161..8a084355efd97d4528b09ecaf271247e34ab1e02 100644 (file)
@@ -18,6 +18,7 @@ If you are updating from an 0.9.x release AND you have indexed branches with the
 \r
 #### changes\r
 \r
+- Added *git.searchRecursionDepth=-1* to control how deep Gitblit will recurse into *git.repositoriesFolder* looking for repositories (issue 103)\r
 - Blob page now supports displaying images (issue 6)\r
 - Non-image binary files can now be downloaded using the RAW link\r
 - Updated Polish translation\r
index 1eb93891b2ec3bfb21a22bca84c99311ac7b48f3..8ead17e0f36061282e4081525d810fe67435b56b 100644 (file)
@@ -63,7 +63,7 @@ public class AddIndexedBranch {
                \r
                // determine available repositories\r
                File folder = new File(params.folder);\r
-               List<String> repoList = JGitUtils.getRepositoryList(folder, false, true);\r
+               List<String> repoList = JGitUtils.getRepositoryList(folder, false, true, -1);\r
                \r
                int modCount = 0;\r
                int skipCount = 0;\r
index 10b1253451385eda8097a7104ec63b8da1c4d67e..d4a59d5a5333c7a57ad75571578413774da352bb 100644 (file)
@@ -742,7 +742,8 @@ public class GitBlit implements ServletContextListener {
        public List<String> getRepositoryList() {\r
                return JGitUtils.getRepositoryList(repositoriesFolder, \r
                                settings.getBoolean(Keys.git.onlyAccessBareRepositories, false),\r
-                               settings.getBoolean(Keys.git.searchRepositoriesSubfolders, true));\r
+                               settings.getBoolean(Keys.git.searchRepositoriesSubfolders, true),\r
+                               settings.getInteger(Keys.git.searchRecursionDepth, -1));\r
        }\r
 \r
        /**\r
index 62d27da83faad1d63e7dc79639016115162e73c7..ff701b3941eec6607e8e64f19ef63a4117b6f34e 100644 (file)
@@ -275,16 +275,18 @@ public class JGitUtils {
         *            false all repositories are included.\r
         * @param searchSubfolders\r
         *            recurse into subfolders to find grouped repositories\r
+        * @param depth\r
+        *            optional recursion depth, -1 = infinite recursion\r
         * @return list of repository names\r
         */\r
        public static List<String> getRepositoryList(File repositoriesFolder, boolean onlyBare,\r
-                       boolean searchSubfolders) {\r
+                       boolean searchSubfolders, int depth) {\r
                List<String> list = new ArrayList<String>();\r
                if (repositoriesFolder == null || !repositoriesFolder.exists()) {\r
                        return list;\r
                }\r
                list.addAll(getRepositoryList(repositoriesFolder.getAbsolutePath(), repositoriesFolder,\r
-                               onlyBare, searchSubfolders));\r
+                               onlyBare, searchSubfolders, depth));\r
                StringUtils.sortRepositorynames(list);\r
                return list;\r
        }\r
@@ -301,12 +303,18 @@ public class JGitUtils {
         *            repositories are included.\r
         * @param searchSubfolders\r
         *            recurse into subfolders to find grouped repositories\r
+        * @param depth\r
+        *            recursion depth, -1 = infinite recursion\r
         * @return\r
         */\r
        private static List<String> getRepositoryList(String basePath, File searchFolder,\r
-                       boolean onlyBare, boolean searchSubfolders) {\r
+                       boolean onlyBare, boolean searchSubfolders, int depth) {\r
                File baseFile = new File(basePath);\r
                List<String> list = new ArrayList<String>();\r
+               if (depth == 0) {\r
+                       return list;\r
+               }\r
+               int nextDepth = (depth == -1) ? -1 : depth - 1;\r
                for (File file : searchFolder.listFiles()) {\r
                        if (file.isDirectory()) {\r
                                File gitDir = FileKey.resolve(new File(searchFolder, file.getName()), FS.DETECTED);\r
@@ -320,11 +328,11 @@ public class JGitUtils {
                                                list.add(repository);\r
                                        } else if (searchSubfolders && file.canRead()) {\r
                                                // look for repositories in subfolders\r
-                                               list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders));\r
+                                               list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders, nextDepth));\r
                                        }\r
                                } else if (searchSubfolders && file.canRead()) {\r
                                        // look for repositories in subfolders\r
-                                       list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders));\r
+                                       list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders, nextDepth));\r
                                }\r
                        }\r
                }\r
index 316d136872e84a40df27e982b326df78650f7835..addc9347661d6049bc4368cb8469e5948eec6be1 100644 (file)
@@ -67,11 +67,11 @@ public class JGitUtilsTest {
 \r
        @Test\r
        public void testFindRepositories() {\r
-               List<String> list = JGitUtils.getRepositoryList(null, false, true);\r
+               List<String> list = JGitUtils.getRepositoryList(null, false, true, -1);\r
                assertEquals(0, list.size());\r
-               list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true));\r
+               list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true, -1));\r
                assertEquals(0, list.size());\r
-               list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true));\r
+               list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1));\r
                assertTrue("No repositories found in " + GitBlitSuite.REPOSITORIES, list.size() > 0);\r
        }\r
 \r