From 629162ad350b7e478173dcacfd88683aa687f3dd Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 09 Aug 2012 09:57:21 -0400
Subject: [PATCH] Documentation
---
src/com/gitblit/utils/JGitUtils.java | 62 +++++++++++++++++++++++--------
1 files changed, 46 insertions(+), 16 deletions(-)
diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java
index ff701b3..90e6a76 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -29,6 +29,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@@ -277,16 +278,24 @@
* recurse into subfolders to find grouped repositories
* @param depth
* optional recursion depth, -1 = infinite recursion
+ * @param exclusions
+ * list of regex exclusions for matching to folder names
* @return list of repository names
*/
public static List<String> getRepositoryList(File repositoriesFolder, boolean onlyBare,
- boolean searchSubfolders, int depth) {
+ boolean searchSubfolders, int depth, List<String> exclusions) {
List<String> list = new ArrayList<String>();
if (repositoriesFolder == null || !repositoriesFolder.exists()) {
return list;
}
+ List<Pattern> patterns = new ArrayList<Pattern>();
+ if (!ArrayUtils.isEmpty(exclusions)) {
+ for (String regex : exclusions) {
+ patterns.add(Pattern.compile(regex));
+ }
+ }
list.addAll(getRepositoryList(repositoriesFolder.getAbsolutePath(), repositoriesFolder,
- onlyBare, searchSubfolders, depth));
+ onlyBare, searchSubfolders, depth, patterns));
StringUtils.sortRepositorynames(list);
return list;
}
@@ -305,18 +314,35 @@
* recurse into subfolders to find grouped repositories
* @param depth
* recursion depth, -1 = infinite recursion
+ * @param patterns
+ * list of regex patterns for matching to folder names
* @return
*/
private static List<String> getRepositoryList(String basePath, File searchFolder,
- boolean onlyBare, boolean searchSubfolders, int depth) {
+ boolean onlyBare, boolean searchSubfolders, int depth, List<Pattern> patterns) {
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()) {
+ boolean exclude = false;
+ for (Pattern pattern : patterns) {
+ String path = FileUtils.getRelativePath(baseFile, file).replace('\\', '/');
+ if (pattern.matcher(path).matches()) {
+ LOGGER.debug(MessageFormat.format("excluding {0} because of rule {1}", path, pattern.pattern()));
+ exclude = true;
+ break;
+ }
+ }
+ if (exclude) {
+ // skip to next file
+ continue;
+ }
+
File gitDir = FileKey.resolve(new File(searchFolder, file.getName()), FS.DETECTED);
if (gitDir != null) {
if (onlyBare && gitDir.getName().equals(".git")) {
@@ -328,11 +354,13 @@
list.add(repository);
} else if (searchSubfolders && file.canRead()) {
// look for repositories in subfolders
- list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders, nextDepth));
+ list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders,
+ nextDepth, patterns));
}
} else if (searchSubfolders && file.canRead()) {
// look for repositories in subfolders
- list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders, nextDepth));
+ list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders,
+ nextDepth, patterns));
}
}
}
@@ -531,18 +559,20 @@
}
ObjectId entid = tw.getObjectId(0);
FileMode entmode = tw.getFileMode(0);
- RevObject ro = rw.lookupAny(entid, entmode.getObjectType());
- rw.parseBody(ro);
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- ObjectLoader ldr = repository.open(ro.getId(), Constants.OBJ_BLOB);
- byte[] tmp = new byte[4096];
- InputStream in = ldr.openStream();
- int n;
- while ((n = in.read(tmp)) > 0) {
- os.write(tmp, 0, n);
+ if (entmode != FileMode.GITLINK) {
+ RevObject ro = rw.lookupAny(entid, entmode.getObjectType());
+ rw.parseBody(ro);
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ ObjectLoader ldr = repository.open(ro.getId(), Constants.OBJ_BLOB);
+ byte[] tmp = new byte[4096];
+ InputStream in = ldr.openStream();
+ int n;
+ while ((n = in.read(tmp)) > 0) {
+ os.write(tmp, 0, n);
+ }
+ in.close();
+ content = os.toByteArray();
}
- in.close();
- content = os.toByteArray();
}
} catch (Throwable t) {
error(t, repository, "{0} can't find {1} in tree {2}", path, tree.name());
--
Gitblit v1.9.1