From 65f55eee1c41a9cdfec96dc4310efcc6e57df97f Mon Sep 17 00:00:00 2001 From: James Moger Date: Wed, 1 Aug 2012 09:48:06 -0400 Subject: [PATCH] Add recursion depth control for repository search (issue 103) --- distrib/gitblit.properties | 6 ++++++ docs/04_releases.mkd | 1 + src/com/gitblit/AddIndexedBranch.java | 2 +- src/com/gitblit/GitBlit.java | 3 ++- src/com/gitblit/utils/JGitUtils.java | 18 +++++++++++++----- tests/com/gitblit/tests/JGitUtilsTest.java | 6 +++--- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/distrib/gitblit.properties b/distrib/gitblit.properties index 4c4372ea..f06aaef4 100644 --- a/distrib/gitblit.properties +++ b/distrib/gitblit.properties @@ -21,6 +21,12 @@ git.repositoriesFolder = git # SINCE 0.5.0 git.searchRepositoriesSubfolders = true +# Maximum number of folders to recurse into when searching for repositories. +# The default value, -1, disables depth limits. +# +# SINCE 1.0.1 +git.searchRecursionDepth = -1 + # Allow push/pull over http/https with JGit servlet. # If you do NOT want to allow Git clients to clone/push to Gitblit set this # to false. You might want to do this if you are only using ssh:// or git://. diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd index 13b31ab7..8a084355 100644 --- a/docs/04_releases.mkd +++ b/docs/04_releases.mkd @@ -18,6 +18,7 @@ If you are updating from an 0.9.x release AND you have indexed branches with the #### changes +- Added *git.searchRecursionDepth=-1* to control how deep Gitblit will recurse into *git.repositoriesFolder* looking for repositories (issue 103) - Blob page now supports displaying images (issue 6) - Non-image binary files can now be downloaded using the RAW link - Updated Polish translation diff --git a/src/com/gitblit/AddIndexedBranch.java b/src/com/gitblit/AddIndexedBranch.java index 1eb93891..8ead17e0 100644 --- a/src/com/gitblit/AddIndexedBranch.java +++ b/src/com/gitblit/AddIndexedBranch.java @@ -63,7 +63,7 @@ public class AddIndexedBranch { // determine available repositories File folder = new File(params.folder); - List repoList = JGitUtils.getRepositoryList(folder, false, true); + List repoList = JGitUtils.getRepositoryList(folder, false, true, -1); int modCount = 0; int skipCount = 0; diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 10b12534..d4a59d5a 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -742,7 +742,8 @@ public class GitBlit implements ServletContextListener { public List getRepositoryList() { return JGitUtils.getRepositoryList(repositoriesFolder, settings.getBoolean(Keys.git.onlyAccessBareRepositories, false), - settings.getBoolean(Keys.git.searchRepositoriesSubfolders, true)); + settings.getBoolean(Keys.git.searchRepositoriesSubfolders, true), + settings.getInteger(Keys.git.searchRecursionDepth, -1)); } /** diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index 62d27da8..ff701b39 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -275,16 +275,18 @@ public class JGitUtils { * false all repositories are included. * @param searchSubfolders * recurse into subfolders to find grouped repositories + * @param depth + * optional recursion depth, -1 = infinite recursion * @return list of repository names */ public static List getRepositoryList(File repositoriesFolder, boolean onlyBare, - boolean searchSubfolders) { + boolean searchSubfolders, int depth) { List list = new ArrayList(); if (repositoriesFolder == null || !repositoriesFolder.exists()) { return list; } list.addAll(getRepositoryList(repositoriesFolder.getAbsolutePath(), repositoriesFolder, - onlyBare, searchSubfolders)); + onlyBare, searchSubfolders, depth)); StringUtils.sortRepositorynames(list); return list; } @@ -301,12 +303,18 @@ public class JGitUtils { * repositories are included. * @param searchSubfolders * recurse into subfolders to find grouped repositories + * @param depth + * recursion depth, -1 = infinite recursion * @return */ private static List getRepositoryList(String basePath, File searchFolder, - boolean onlyBare, boolean searchSubfolders) { + boolean onlyBare, boolean searchSubfolders, int depth) { File baseFile = new File(basePath); List list = new ArrayList(); + if (depth == 0) { + return list; + } + int nextDepth = (depth == -1) ? -1 : depth - 1; for (File file : searchFolder.listFiles()) { if (file.isDirectory()) { File gitDir = FileKey.resolve(new File(searchFolder, file.getName()), FS.DETECTED); @@ -320,11 +328,11 @@ public class JGitUtils { list.add(repository); } else if (searchSubfolders && file.canRead()) { // look for repositories in subfolders - list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders)); + list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders, nextDepth)); } } else if (searchSubfolders && file.canRead()) { // look for repositories in subfolders - list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders)); + list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders, nextDepth)); } } } diff --git a/tests/com/gitblit/tests/JGitUtilsTest.java b/tests/com/gitblit/tests/JGitUtilsTest.java index 316d1368..addc9347 100644 --- a/tests/com/gitblit/tests/JGitUtilsTest.java +++ b/tests/com/gitblit/tests/JGitUtilsTest.java @@ -67,11 +67,11 @@ public class JGitUtilsTest { @Test public void testFindRepositories() { - List list = JGitUtils.getRepositoryList(null, false, true); + List list = JGitUtils.getRepositoryList(null, false, true, -1); assertEquals(0, list.size()); - list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true)); + list.addAll(JGitUtils.getRepositoryList(new File("DoesNotExist"), true, true, -1)); assertEquals(0, list.size()); - list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true)); + list.addAll(JGitUtils.getRepositoryList(GitBlitSuite.REPOSITORIES, false, true, -1)); assertTrue("No repositories found in " + GitBlitSuite.REPOSITORIES, list.size() > 0); } -- 2.39.5