From 0f43a54527845b5873f35dc80300d578bfe84bb0 Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 13 Jan 2012 07:58:12 -0500 Subject: Branch for implementing distributed gb-issues --- src/com/gitblit/utils/JGitUtils.java | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/com/gitblit/utils/JGitUtils.java') diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index a540c2aa..5d6011a2 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -24,7 +24,6 @@ import java.nio.charset.Charset; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -748,25 +747,40 @@ public class JGitUtils { } /** - * Returns the list of files in the repository that match one of the - * specified extensions. This is a CASE-SENSITIVE search. If the repository - * does not exist or is empty, an empty list is returned. + * Returns the list of files in the repository on the default branch that + * match one of the specified extensions. This is a CASE-SENSITIVE search. + * If the repository does not exist or is empty, an empty list is returned. * * @param repository * @param extensions * @return list of files in repository with a matching extension */ public static List getDocuments(Repository repository, List extensions) { + return getDocuments(repository, extensions, null); + } + + /** + * Returns the list of files in the repository in the specified commit that + * match one of the specified extensions. This is a CASE-SENSITIVE search. + * If the repository does not exist or is empty, an empty list is returned. + * + * @param repository + * @param extensions + * @param objectId + * @return list of files in repository with a matching extension + */ + public static List getDocuments(Repository repository, List extensions, + String objectId) { List list = new ArrayList(); if (!hasCommits(repository)) { return list; } - RevCommit commit = getCommit(repository, null); + RevCommit commit = getCommit(repository, objectId); final TreeWalk tw = new TreeWalk(repository); try { tw.addTree(commit.getTree()); if (extensions != null && extensions.size() > 0) { - Collection suffixFilters = new ArrayList(); + List suffixFilters = new ArrayList(); for (String extension : extensions) { if (extension.charAt(0) == '.') { suffixFilters.add(PathSuffixFilter.create("\\" + extension)); @@ -775,7 +789,12 @@ public class JGitUtils { suffixFilters.add(PathSuffixFilter.create("\\." + extension)); } } - TreeFilter filter = OrTreeFilter.create(suffixFilters); + TreeFilter filter; + if (suffixFilters.size() == 1) { + filter = suffixFilters.get(0); + } else { + filter = OrTreeFilter.create(suffixFilters); + } tw.setFilter(filter); tw.setRecursive(true); } -- cgit v1.2.3