summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2012-08-02 15:53:51 -0400
committerJames Moger <james.moger@gitblit.com>2012-08-02 15:53:51 -0400
commitbb55f5aec092b22ee4b86152c0e0111df48eb34e (patch)
tree6a006180354dd77eac0782250ff52961d5dad815 /src/com
parent6adf56bb13227afac2c37871b3443fb5354d132c (diff)
downloadgitblit-bb55f5aec092b22ee4b86152c0e0111df48eb34e.tar.gz
gitblit-bb55f5aec092b22ee4b86152c0e0111df48eb34e.zip
Compile regex patterns once and use matches instead of find (issue 103)
Diffstat (limited to 'src/com')
-rw-r--r--src/com/gitblit/utils/JGitUtils.java26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java
index 9d2e471a..4415982a 100644
--- a/src/com/gitblit/utils/JGitUtils.java
+++ b/src/com/gitblit/utils/JGitUtils.java
@@ -288,8 +288,14 @@ public class JGitUtils {
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, exclusions));
+ onlyBare, searchSubfolders, depth, patterns));
StringUtils.sortRepositorynames(list);
return list;
}
@@ -308,23 +314,17 @@ public class JGitUtils {
* recurse into subfolders to find grouped repositories
* @param depth
* recursion depth, -1 = infinite recursion
- * @param exclusions
- * list of regex exclusions for matching to folder names
+ * @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, List<String> exclusions) {
+ 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;
}
- List<Pattern> patterns = new ArrayList<Pattern>();
- if (!ArrayUtils.isEmpty(exclusions)) {
- for (String regex : exclusions) {
- patterns.add(Pattern.compile(regex));
- }
- }
int nextDepth = (depth == -1) ? -1 : depth - 1;
for (File file : searchFolder.listFiles()) {
@@ -332,7 +332,7 @@ public class JGitUtils {
boolean exclude = false;
for (Pattern pattern : patterns) {
String path = FileUtils.getRelativePath(baseFile, file).replace('\\', '/');
- if (pattern.matcher(path).find()) {
+ if (pattern.matcher(path).matches()) {
LOGGER.debug(MessageFormat.format("excluding {0} because of rule {1}", path, pattern.pattern()));
exclude = true;
break;
@@ -355,12 +355,12 @@ public class JGitUtils {
} else if (searchSubfolders && file.canRead()) {
// look for repositories in subfolders
list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders,
- nextDepth, exclusions));
+ nextDepth, patterns));
}
} else if (searchSubfolders && file.canRead()) {
// look for repositories in subfolders
list.addAll(getRepositoryList(basePath, file, onlyBare, searchSubfolders,
- nextDepth, exclusions));
+ nextDepth, patterns));
}
}
}