Java 类org.eclipse.jgit.lib.RepositoryCache.FileKey 实例源码

项目:team-explorer-everywhere    文件:FindEclipseProjectsCommand.java   
@Override
public boolean accept(final File folder) {
    if (!folder.isDirectory()) {
        return false;
    }

    final String path = folder.getName();

    if (path.equals(METADATA_FOLDER)) {
        return false;
    }

    if (!path.equals(Constants.DOT_GIT)) {
        return true;
    }

    return !FileKey.isGitRepository(folder, FS.DETECTED);
}
项目:ninja_chic-    文件:Repos.java   
public static List<File> reposInDefaultRepoDir() {
    File reposDir = new File(getExternalStorageDirectory(), "git-repos");

    List<File> repos = newArrayList();
    if (!reposDir.exists() && !reposDir.mkdirs()) {
        Log.d(TAG, "Could not create default repos dir  " + reposDir);
        return repos;
    }
    for (File repoDir : reposDir.listFiles()) {
        File gitdir = RepositoryCache.FileKey.resolve(repoDir, FS.detect());
        if (gitdir != null) {
            repos.add(gitdir);
        }
    }
    Log.d(TAG, "Found " + repos.size() + " repos in " + reposDir);
    return repos;
}
项目:gerrit-gitblit-plugin    文件:LuceneService.java   
/**
 * Deletes the Lucene index for the specified repository.
 * 
 * @param repositoryName
 * @return true, if successful
 */
public boolean deleteIndex(String repositoryName) {
    try {
        // close any open writer/searcher
        close(repositoryName);

        // delete the index folder
        File repositoryFolder = FileKey.resolve(new File(repositoriesFolder, repositoryName), FS.DETECTED);
        File luceneIndex = new File(repositoryFolder, LUCENE_DIR);
        if (luceneIndex.exists()) {
            org.eclipse.jgit.util.FileUtils.delete(luceneIndex, org.eclipse.jgit.util.FileUtils.RECURSIVE);
        }
        // delete the config file
        File luceneConfig = new File(repositoryFolder, CONF_FILE);
        if (luceneConfig.exists()) {
            luceneConfig.delete();
        }
        return true;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:gerrit-gitblit-plugin    文件:LuceneService.java   
/**
 * Gets an index writer for the repository. The index will be created if it does not already exist or if forceCreate is specified.
 * 
 * @param repository
 * @return an IndexWriter
 * @throws IOException
 */
private IndexWriter getIndexWriter(String repository) throws IOException {
    IndexWriter indexWriter = writers.get(repository);
    File repositoryFolder = FileKey.resolve(new File(repositoriesFolder, repository), FS.DETECTED);
    File indexFolder = new File(repositoryFolder, LUCENE_DIR);
    Directory directory = FSDirectory.open(indexFolder.toPath());

    if (indexWriter == null) {
        if (!indexFolder.exists()) {
            indexFolder.mkdirs();
        }
        StandardAnalyzer analyzer = new StandardAnalyzer();
        IndexWriterConfig config = new IndexWriterConfig(analyzer);
        config.setOpenMode(OpenMode.CREATE_OR_APPEND);
        indexWriter = new IndexWriter(directory, config);
        writers.put(repository, indexWriter);
    }
    return indexWriter;
}
项目:gitblit    文件:GitBlit.java   
/**
 * Returns the JGit repository for the specified name.
 * 
 * @param repositoryName
 * @param logError
 * @return repository or null
 */
public Repository getRepository(String repositoryName, boolean logError) {
    if (isCollectingGarbage(repositoryName)) {
        logger.warn(MessageFormat.format("Rejecting request for {0}, busy collecting garbage!", repositoryName));
        return null;
    }

    File dir = FileKey.resolve(new File(repositoriesFolder, repositoryName), FS.DETECTED);
    if (dir == null)
        return null;

    Repository r = null;
    try {
        FileKey key = FileKey.exact(dir, FS.DETECTED);
        r = RepositoryCache.open(key, true);
    } catch (IOException e) {
        if (logError) {
            logger.error("GitBlit.getRepository(String) failed to find "
                    + new File(repositoriesFolder, repositoryName).getAbsolutePath());
        }
    }
    return r;
}
项目:gitblit    文件:LuceneExecutor.java   
/**
 * Deletes the Lucene index for the specified repository.
 * 
 * @param repositoryName
 * @return true, if successful
 */
public boolean deleteIndex(String repositoryName) {
    try {
        // close any open writer/searcher
        close(repositoryName);

        // delete the index folder
        File repositoryFolder = FileKey.resolve(new File(repositoriesFolder, repositoryName), FS.DETECTED);
        File luceneIndex = new File(repositoryFolder, LUCENE_DIR);
        if (luceneIndex.exists()) {
            org.eclipse.jgit.util.FileUtils.delete(luceneIndex,
                    org.eclipse.jgit.util.FileUtils.RECURSIVE);
        }
        // delete the config file
        File luceneConfig = new File(repositoryFolder, CONF_FILE);
        if (luceneConfig.exists()) {
            luceneConfig.delete();
        }
        return true;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:gitblit    文件:LuceneExecutor.java   
/**
 * Gets an index writer for the repository. The index will be created if it
 * does not already exist or if forceCreate is specified.
 * 
 * @param repository
 * @return an IndexWriter
 * @throws IOException
 */
private IndexWriter getIndexWriter(String repository) throws IOException {
    IndexWriter indexWriter = writers.get(repository);              
    File repositoryFolder = FileKey.resolve(new File(repositoriesFolder, repository), FS.DETECTED);
    File indexFolder = new File(repositoryFolder, LUCENE_DIR);
    Directory directory = FSDirectory.open(indexFolder);        

    if (indexWriter == null) {
        if (!indexFolder.exists()) {
            indexFolder.mkdirs();
        }
        StandardAnalyzer analyzer = new StandardAnalyzer(LUCENE_VERSION);
        IndexWriterConfig config = new IndexWriterConfig(LUCENE_VERSION, analyzer);
        config.setOpenMode(OpenMode.CREATE_OR_APPEND);
        indexWriter = new IndexWriter(directory, config);
        writers.put(repository, indexWriter);
    }
    return indexWriter;
}
项目:gitblit    文件:JGitUtilsTest.java   
@Test
public void testCreateRepository() throws Exception {
    String[] repositories = { "NewTestRepository.git", "NewTestRepository" };
    for (String repositoryName : repositories) {
        Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES,
                repositoryName);
        File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),
                FS.DETECTED);
        assertNotNull(repository);
        assertFalse(JGitUtils.hasCommits(repository));
        assertNull(JGitUtils.getFirstCommit(repository, null));
        assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null)
                .getTime());
        assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository).getTime());
        assertNull(JGitUtils.getCommit(repository, null));
        repository.close();
        RepositoryCache.close(repository);
        FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
    }
}
项目:IRCBlit    文件:GitBlit.java   
/**
 * Returns the JGit repository for the specified name.
 * 
 * @param repositoryName
 * @param logError
 * @return repository or null
 */
public Repository getRepository(String repositoryName, boolean logError) {
    if (isCollectingGarbage(repositoryName)) {
        logger.warn(MessageFormat.format("Rejecting request for {0}, busy collecting garbage!", repositoryName));
        return null;
    }

    File dir = FileKey.resolve(new File(repositoriesFolder, repositoryName), FS.DETECTED);
    if (dir == null)
        return null;

    Repository r = null;
    try {
        FileKey key = FileKey.exact(dir, FS.DETECTED);
        r = RepositoryCache.open(key, true);
    } catch (IOException e) {
        if (logError) {
            logger.error("GitBlit.getRepository(String) failed to find "
                    + new File(repositoriesFolder, repositoryName).getAbsolutePath());
        }
    }
    return r;
}
项目:IRCBlit    文件:LuceneExecutor.java   
/**
 * Deletes the Lucene index for the specified repository.
 * 
 * @param repositoryName
 * @return true, if successful
 */
public boolean deleteIndex(String repositoryName) {
    try {
        // close any open writer/searcher
        close(repositoryName);

        // delete the index folder
        File repositoryFolder = FileKey.resolve(new File(repositoriesFolder, repositoryName), FS.DETECTED);
        File luceneIndex = new File(repositoryFolder, LUCENE_DIR);
        if (luceneIndex.exists()) {
            org.eclipse.jgit.util.FileUtils.delete(luceneIndex,
                    org.eclipse.jgit.util.FileUtils.RECURSIVE);
        }
        // delete the config file
        File luceneConfig = new File(repositoryFolder, CONF_FILE);
        if (luceneConfig.exists()) {
            luceneConfig.delete();
        }
        return true;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:IRCBlit    文件:LuceneExecutor.java   
/**
 * Gets an index writer for the repository. The index will be created if it
 * does not already exist or if forceCreate is specified.
 * 
 * @param repository
 * @return an IndexWriter
 * @throws IOException
 */
private IndexWriter getIndexWriter(String repository) throws IOException {
    IndexWriter indexWriter = writers.get(repository);              
    File repositoryFolder = FileKey.resolve(new File(repositoriesFolder, repository), FS.DETECTED);
    File indexFolder = new File(repositoryFolder, LUCENE_DIR);
    Directory directory = FSDirectory.open(indexFolder);        

    if (indexWriter == null) {
        if (!indexFolder.exists()) {
            indexFolder.mkdirs();
        }
        StandardAnalyzer analyzer = new StandardAnalyzer(LUCENE_VERSION);
        IndexWriterConfig config = new IndexWriterConfig(LUCENE_VERSION, analyzer);
        config.setOpenMode(OpenMode.CREATE_OR_APPEND);
        indexWriter = new IndexWriter(directory, config);
        writers.put(repository, indexWriter);
    }
    return indexWriter;
}
项目:IRCBlit    文件:JGitUtilsTest.java   
@Test
public void testCreateRepository() throws Exception {
    String[] repositories = { "NewTestRepository.git", "NewTestRepository" };
    for (String repositoryName : repositories) {
        Repository repository = JGitUtils.createRepository(GitBlitSuite.REPOSITORIES,
                repositoryName);
        File folder = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, repositoryName),
                FS.DETECTED);
        assertNotNull(repository);
        assertFalse(JGitUtils.hasCommits(repository));
        assertNull(JGitUtils.getFirstCommit(repository, null));
        assertEquals(folder.lastModified(), JGitUtils.getFirstChange(repository, null)
                .getTime());
        assertEquals(folder.lastModified(), JGitUtils.getLastChange(repository).getTime());
        assertNull(JGitUtils.getCommit(repository, null));
        repository.close();
        RepositoryCache.close(repository);
        FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE);
    }
}
项目:team-explorer-everywhere    文件:GitRepositoriesMap.java   
private List<Repository> findRegisteredRepositories() {
    final RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
    final List<String> repositoryFolders = util.getConfiguredRepositories();

    final List<Repository> repositories = new ArrayList<Repository>();

    for (final String repositoryFolder : repositoryFolders) {
        final File folder = new File(repositoryFolder);
        if (!folder.exists() || !folder.isDirectory()) {
            continue;
        }

        if (!folder.getName().equals(Constants.DOT_GIT) || !FileKey.isGitRepository(folder, FS.DETECTED)) {
            continue;
        }

        final RepositoryBuilder rb = new RepositoryBuilder().setGitDir(folder).setMustExist(true);

        try {
            repositories.add(rb.build());
        } catch (final Exception e) {
            log.error("Error loading Git repository " + repositoryFolder, e); //$NON-NLS-1$
            continue;
        }
    }

    return repositories;
}
项目:team-explorer-everywhere    文件:TeamExplorerGitRepositoriesSection.java   
private void loadRegisteredRepositories() {
    repositoryMap = new TreeMap<String, Repository>();
    final List<String> repositoryFolders = Activator.getDefault().getRepositoryUtil().getConfiguredRepositories();

    for (final String repositoryFolder : repositoryFolders) {
        final File folder = new File(repositoryFolder);
        if (!folder.exists() || !folder.isDirectory()) {
            continue;
        }

        if (!folder.getName().equals(Constants.DOT_GIT) || !FileKey.isGitRepository(folder, FS.DETECTED)) {
            continue;
        }

        final RepositoryBuilder rb = new RepositoryBuilder().setGitDir(folder).setMustExist(true);

        try {
            final Repository repo = rb.build();
            final StoredConfig repositoryConfig = repo.getConfig();
            final Set<String> remotes = repositoryConfig.getSubsections(REMOTES_SECTION_NAME);

            for (final String remoteName : remotes) {
                final String remoteURL =
                    repositoryConfig.getString(REMOTES_SECTION_NAME, remoteName, URL_VALUE_NAME);
                repositoryMap.put(remoteURL, repo);
            }
        } catch (final Exception e) {
            log.error("Error loading local Git repository " + repositoryFolder, e); //$NON-NLS-1$
            continue;
        }
    }
}
项目:gerrit    文件:GitRepositoryManagerOnInit.java   
private File getPath(Project.NameKey name) {
  Path basePath = site.resolve(flags.cfg.getString("gerrit", null, "basePath"));
  if (basePath == null) {
    throw new IllegalStateException("gerrit.basePath must be configured");
  }
  return FileKey.resolve(basePath.resolve(name.get()).toFile(), FS.DETECTED);
}
项目:gerrit    文件:VersionedMetaDataOnInit.java   
private File getPath() {
  Path basePath = site.resolve(flags.cfg.getString("gerrit", null, "basePath"));
  if (basePath == null) {
    throw new IllegalStateException("gerrit.basePath must be configured");
  }
  return FileKey.resolve(basePath.resolve(project).toFile(), FS.DETECTED);
}
项目:gerrit    文件:ExternalIdsOnInit.java   
private File getPath() {
  Path basePath = site.resolve(flags.cfg.getString("gerrit", null, "basePath"));
  if (basePath == null) {
    throw new IllegalStateException("gerrit.basePath must be configured");
  }
  return FileKey.resolve(basePath.resolve(allUsers).toFile(), FS.DETECTED);
}
项目:gerrit    文件:MultiBaseLocalDiskRepositoryManagerTest.java   
private void createRepository(Path directory, Project.NameKey projectName) throws IOException {
  String n = projectName.get() + Constants.DOT_GIT_EXT;
  FileKey loc = FileKey.exact(directory.resolve(n).toFile(), FS.DETECTED);
  try (Repository db = RepositoryCache.open(loc, false)) {
    db.create(true /* bare */);
  }
}
项目:gerrit    文件:LocalDiskRepositoryManagerTest.java   
private void createRepository(Path directory, String projectName) throws IOException {
  String n = projectName + Constants.DOT_GIT_EXT;
  FileKey loc = FileKey.exact(directory.resolve(n).toFile(), FS.DETECTED);
  try (Repository db = RepositoryCache.open(loc, false)) {
    db.create(true /* bare */);
  }
}
项目:ninja_chic-    文件:Repos.java   
public static Repository openRepoFor(File gitdir) {
    try {
        Repository repo = RepositoryCache.open(FileKey.lenient(gitdir, FS.DETECTED), false);
        Log.d("REPO", "Opened " + describe(repo));
        return repo;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:spring-cloud-config    文件:ConfigServerTestUtils.java   
public static Repository prepareBareRemote() throws IOException {
    // Create a folder in the temp folder that will act as the remote repository
    File remoteDir = File.createTempFile("remote", "");
    remoteDir.delete();
    remoteDir.mkdirs();

    // Create a bare repository
    FileKey fileKey = FileKey.exact(remoteDir, FS.DETECTED);
    Repository remoteRepo = fileKey.open(false);
    remoteRepo.create(true);

    return remoteRepo;
}
项目:gitblit    文件:GitBlit.java   
/**
 * Returns the size in bytes of the repository. Gitblit caches the
 * repository sizes to reduce the performance penalty of recursive
 * calculation. The cache is updated if the repository has been changed
 * since the last calculation.
 * 
 * @param model
 * @return size in bytes
 */
public long calculateSize(RepositoryModel model) {
    if (repositorySizeCache.hasCurrent(model.name, model.lastChange)) {
        return repositorySizeCache.getObject(model.name);
    }
    File gitDir = FileKey.resolve(new File(repositoriesFolder, model.name), FS.DETECTED);
    long size = com.gitblit.utils.FileUtils.folderSize(gitDir);
    repositorySizeCache.updateObject(model.name, model.lastChange, size);
    return size;
}
项目:gitblit    文件:GitBlitSuite.java   
public static void close(File repository) {
    try {
        File gitDir = FileKey.resolve(repository, FS.detect());
        if (gitDir != null && gitDir.exists()) {
            close(RepositoryCache.open(FileKey.exact(gitDir, FS.detect())));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:gitblit    文件:PushLogTest.java   
@Test
public void testPushLog() throws IOException {
    String name = "~james/helloworld.git";
    File gitDir = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, name), FS.DETECTED);
    Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
    List<PushLogEntry> pushes = PushLogUtils.getPushLog(name, repository);
    GitBlitSuite.close(repository);
}
项目:IRCBlit    文件:GitBlit.java   
/**
 * Returns the size in bytes of the repository. Gitblit caches the
 * repository sizes to reduce the performance penalty of recursive
 * calculation. The cache is updated if the repository has been changed
 * since the last calculation.
 * 
 * @param model
 * @return size in bytes
 */
public long calculateSize(RepositoryModel model) {
    if (repositorySizeCache.hasCurrent(model.name, model.lastChange)) {
        return repositorySizeCache.getObject(model.name);
    }
    File gitDir = FileKey.resolve(new File(repositoriesFolder, model.name), FS.DETECTED);
    long size = com.gitblit.utils.FileUtils.folderSize(gitDir);
    repositorySizeCache.updateObject(model.name, model.lastChange, size);
    return size;
}
项目:IRCBlit    文件:GitBlitSuite.java   
public static void close(File repository) {
    try {
        File gitDir = FileKey.resolve(repository, FS.detect());
        if (gitDir != null && gitDir.exists()) {
            close(RepositoryCache.open(FileKey.exact(gitDir, FS.detect())));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:IRCBlit    文件:PushLogTest.java   
@Test
public void testPushLog() throws IOException {
    String name = "~james/helloworld.git";
    File gitDir = FileKey.resolve(new File(GitBlitSuite.REPOSITORIES, name), FS.DETECTED);
    Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
    List<PushLogEntry> pushes = PushLogUtils.getPushLog(name, repository);
    GitBlitSuite.close(repository);
}
项目:gerrit    文件:AccountsOnInit.java   
private File getPath() {
  Path basePath = site.resolve(flags.cfg.getString("gerrit", null, "basePath"));
  checkArgument(basePath != null, "gerrit.basePath must be configured");
  return FileKey.resolve(basePath.resolve(allUsers).toFile(), FS.DETECTED);
}
项目:gerrit    文件:LocalDiskRepositoryManager.java   
private boolean isRepo(Path p) {
  String name = p.getFileName().toString();
  return !name.equals(Constants.DOT_GIT)
      && (name.endsWith(Constants.DOT_GIT_EXT)
          || FileKey.isGitRepository(p.toFile(), FS.DETECTED));
}
项目:gerrit-gitblit-plugin    文件:JGitUtils.java   
/**
 * Recursive function to find git repositories.
 * 
 * @param basePath
 *            basePath is stripped from the repository name as repositories are relative to this path
 * @param searchFolder
 * @param onlyBare
 *            if true only bare repositories will be listed. if false all repositories are included.
 * @param searchSubfolders
 *            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,
        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")) {
                    continue;
                }
                if (gitDir.equals(file) || gitDir.getParentFile().equals(file)) {
                    // determine repository name relative to base path
                    String repository = FileUtils.getRelativePath(baseFile, file);
                    list.add(repository);
                } else if (searchSubfolders && file.canRead()) {
                    // look for repositories in subfolders
                    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, patterns));
            }
        }
    }
    return list;
}
项目:gitblit    文件:JGitUtils.java   
/**
 * Recursive function to find git repositories.
 * 
 * @param basePath
 *            basePath is stripped from the repository name as repositories
 *            are relative to this path
 * @param searchFolder
 * @param onlyBare
 *            if true only bare repositories will be listed. if false all
 *            repositories are included.
 * @param searchSubfolders
 *            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, 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")) {
                    continue;
                }
                if (gitDir.equals(file) || gitDir.getParentFile().equals(file)) {
                    // determine repository name relative to base path
                    String repository = FileUtils.getRelativePath(baseFile, file);
                    list.add(repository);
                } else if (searchSubfolders && file.canRead()) {
                    // look for repositories in subfolders
                    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, patterns));
            }
        }
    }
    return list;
}
项目:gitblit    文件:GitBlitSuite.java   
private static Repository getRepository(String name) throws Exception {
    File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED);
    Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
    return repository;
}
项目:IRCBlit    文件:JGitUtils.java   
/**
 * Recursive function to find git repositories.
 * 
 * @param basePath
 *            basePath is stripped from the repository name as repositories
 *            are relative to this path
 * @param searchFolder
 * @param onlyBare
 *            if true only bare repositories will be listed. if false all
 *            repositories are included.
 * @param searchSubfolders
 *            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, 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")) {
                    continue;
                }
                if (gitDir.equals(file) || gitDir.getParentFile().equals(file)) {
                    // determine repository name relative to base path
                    String repository = FileUtils.getRelativePath(baseFile, file);
                    list.add(repository);
                } else if (searchSubfolders && file.canRead()) {
                    // look for repositories in subfolders
                    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, patterns));
            }
        }
    }
    return list;
}
项目:IRCBlit    文件:GitBlitSuite.java   
private static Repository getRepository(String name) throws Exception {
    File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED);
    Repository repository = new FileRepositoryBuilder().setGitDir(gitDir).build();
    return repository;
}