James Moger
2012-08-09 cbd0caa7f95ea331ecd7b6daf71b11854f14e4ee
src/com/gitblit/utils/JGitUtils.java
@@ -288,8 +288,14 @@
      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,22 +314,16 @@
    *            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;
@@ -332,7 +332,7 @@
            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 @@
               } 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));
            }
         }
      }
@@ -559,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());