Add recursion depth control for repository search (issue-103)
| | |
| | | # 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://.
|
| | |
| | |
|
| | | #### 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
|
| | |
| | |
|
| | | // determine available repositories
|
| | | File folder = new File(params.folder);
|
| | | List<String> repoList = JGitUtils.getRepositoryList(folder, false, true);
|
| | | List<String> repoList = JGitUtils.getRepositoryList(folder, false, true, -1);
|
| | |
|
| | | int modCount = 0;
|
| | | int skipCount = 0;
|
| | |
| | | public List<String> 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));
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * 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<String> getRepositoryList(File repositoriesFolder, boolean onlyBare,
|
| | | boolean searchSubfolders) {
|
| | | boolean searchSubfolders, int depth) {
|
| | | List<String> list = new ArrayList<String>();
|
| | | if (repositoriesFolder == null || !repositoriesFolder.exists()) {
|
| | | return list;
|
| | | }
|
| | | list.addAll(getRepositoryList(repositoriesFolder.getAbsolutePath(), repositoriesFolder,
|
| | | onlyBare, searchSubfolders));
|
| | | onlyBare, searchSubfolders, depth));
|
| | | StringUtils.sortRepositorynames(list);
|
| | | return list;
|
| | | }
|
| | |
| | | * repositories are included.
|
| | | * @param searchSubfolders
|
| | | * recurse into subfolders to find grouped repositories
|
| | | * @param depth
|
| | | * recursion depth, -1 = infinite recursion
|
| | | * @return
|
| | | */
|
| | | private static List<String> getRepositoryList(String basePath, File searchFolder,
|
| | | boolean onlyBare, boolean searchSubfolders) {
|
| | | boolean onlyBare, boolean searchSubfolders, int depth) {
|
| | | File baseFile = new File(basePath);
|
| | | List<String> list = new ArrayList<String>();
|
| | | 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);
|
| | |
| | | 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));
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | @Test
|
| | | public void testFindRepositories() {
|
| | | List<String> list = JGitUtils.getRepositoryList(null, false, true);
|
| | | List<String> 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);
|
| | | }
|
| | |
|