From 0f43a54527845b5873f35dc80300d578bfe84bb0 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Fri, 13 Jan 2012 07:58:12 -0500
Subject: [PATCH] Branch for implementing distributed gb-issues

---
 src/com/gitblit/utils/JGitUtils.java |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java
index a540c2a..5d6011a 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -24,7 +24,6 @@
 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 @@
 	}
 
 	/**
-	 * 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<PathModel> getDocuments(Repository repository, List<String> 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<PathModel> getDocuments(Repository repository, List<String> extensions,
+			String objectId) {
 		List<PathModel> list = new ArrayList<PathModel>();
 		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<TreeFilter> suffixFilters = new ArrayList<TreeFilter>();
+				List<TreeFilter> suffixFilters = new ArrayList<TreeFilter>();
 				for (String extension : extensions) {
 					if (extension.charAt(0) == '.') {
 						suffixFilters.add(PathSuffixFilter.create("\\" + extension));
@@ -775,7 +789,12 @@
 						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);
 			}

--
Gitblit v1.9.1