Search in sources :

Example 1 with FileKey

use of org.eclipse.jgit.lib.RepositoryCache.FileKey in project gerrit by GerritCodeReview.

the class LocalDiskRepositoryManagerTest method createRepository.

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);
    }
}
Also used : FileKey(org.eclipse.jgit.lib.RepositoryCache.FileKey) Repository(org.eclipse.jgit.lib.Repository)

Example 2 with FileKey

use of org.eclipse.jgit.lib.RepositoryCache.FileKey in project gitblit by gitblit.

the class RepositoryManager method getRepository.

/**
	 * Returns the JGit repository for the specified name.
	 *
	 * @param name
	 * @param logError
	 * @return repository or null
	 */
@Override
public Repository getRepository(String name, boolean logError) {
    String repositoryName = fixRepositoryName(name);
    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;
}
Also used : FileKey(org.eclipse.jgit.lib.RepositoryCache.FileKey) Repository(org.eclipse.jgit.lib.Repository) IOException(java.io.IOException) File(java.io.File)

Example 3 with FileKey

use of org.eclipse.jgit.lib.RepositoryCache.FileKey in project gerrit by GerritCodeReview.

the class MultiBaseLocalDiskRepositoryManagerTest method createRepository.

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);
    }
}
Also used : FileKey(org.eclipse.jgit.lib.RepositoryCache.FileKey) Repository(org.eclipse.jgit.lib.Repository)

Example 4 with FileKey

use of org.eclipse.jgit.lib.RepositoryCache.FileKey in project gitiles by GerritCodeReview.

the class DevServer method createRootedDocServlet.

private Servlet createRootedDocServlet(DebugRenderer renderer, String docRoot) {
    File docRepo = new File(docRoot);
    FileKey repoKey = FileKey.exact(docRepo, FS.DETECTED);
    RepositoryResolver<HttpServletRequest> resolver = (req, name) -> {
        try {
            return RepositoryCache.open(repoKey, true);
        } catch (IOException e) {
            throw new RepositoryNotFoundException(repoKey.getFile(), e);
        }
    };
    return new RootedDocServlet(resolver, new RootedDocAccess(docRepo), renderer);
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Handler(org.eclipse.jetty.server.Handler) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) PathResource(org.eclipse.jetty.util.resource.PathResource) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) URISyntaxException(java.net.URISyntaxException) GitilesAccess(com.google.gitiles.GitilesAccess) LoggerFactory(org.slf4j.LoggerFactory) InetAddress(java.net.InetAddress) Strings(com.google.common.base.Strings) Config(org.eclipse.jgit.lib.Config) HttpServletRequest(javax.servlet.http.HttpServletRequest) Map(java.util.Map) RepositoryDescription(com.google.gitiles.RepositoryDescription) Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) GitilesServlet(com.google.gitiles.GitilesServlet) RepositoryCache(org.eclipse.jgit.lib.RepositoryCache) Logger(org.slf4j.Logger) Servlet(javax.servlet.Servlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) PathServlet(com.google.gitiles.PathServlet) Set(java.util.Set) IOException(java.io.IOException) Constants(org.eclipse.jgit.lib.Constants) RepositoryResolver(org.eclipse.jgit.transport.resolver.RepositoryResolver) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) STATIC_PREFIX(com.google.gitiles.GitilesServlet.STATIC_PREFIX) UnknownHostException(java.net.UnknownHostException) FileKey(org.eclipse.jgit.lib.RepositoryCache.FileKey) File(java.io.File) RootedDocServlet(com.google.gitiles.RootedDocServlet) FileBasedConfig(org.eclipse.jgit.storage.file.FileBasedConfig) Paths(java.nio.file.Paths) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) FS(org.eclipse.jgit.util.FS) DebugRenderer(com.google.gitiles.DebugRenderer) Collections(java.util.Collections) HttpServletRequest(javax.servlet.http.HttpServletRequest) FileKey(org.eclipse.jgit.lib.RepositoryCache.FileKey) IOException(java.io.IOException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) File(java.io.File) RootedDocServlet(com.google.gitiles.RootedDocServlet)

Example 5 with FileKey

use of org.eclipse.jgit.lib.RepositoryCache.FileKey in project gerrit by GerritCodeReview.

the class LocalDiskRepositoryManager method openRepository.

private Repository openRepository(Path path, Project.NameKey name) throws RepositoryNotFoundException {
    if (isUnreasonableName(name)) {
        throw new RepositoryNotFoundException("Invalid name: " + name);
    }
    File gitDir = path.resolve(name.get()).toFile();
    if (!names.contains(name)) {
        //
        if (!name.get().endsWith(Constants.DOT_GIT_EXT)) {
            if (FileKey.resolve(gitDir, FS.DETECTED) != null) {
                onCreateProject(name);
            } else {
                throw new RepositoryNotFoundException(gitDir);
            }
        } else {
            final File directory = gitDir;
            if (FileKey.isGitRepository(new File(directory, Constants.DOT_GIT), FS.DETECTED)) {
                onCreateProject(name);
            } else if (FileKey.isGitRepository(new File(directory.getParentFile(), directory.getName() + Constants.DOT_GIT_EXT), FS.DETECTED)) {
                onCreateProject(name);
            } else {
                throw new RepositoryNotFoundException(gitDir);
            }
        }
    }
    final FileKey loc = FileKey.lenient(gitDir, FS.DETECTED);
    try {
        return RepositoryCache.open(loc);
    } catch (IOException e1) {
        final RepositoryNotFoundException e2;
        e2 = new RepositoryNotFoundException("Cannot open repository " + name);
        e2.initCause(e1);
        throw e2;
    }
}
Also used : FileKey(org.eclipse.jgit.lib.RepositoryCache.FileKey) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException) File(java.io.File)

Aggregations

FileKey (org.eclipse.jgit.lib.RepositoryCache.FileKey)6 File (java.io.File)4 IOException (java.io.IOException)4 Repository (org.eclipse.jgit.lib.Repository)4 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)3 Path (java.nio.file.Path)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Strings (com.google.common.base.Strings)1 Project (com.google.gerrit.reviewdb.client.Project)1 DebugRenderer (com.google.gitiles.DebugRenderer)1 GitilesAccess (com.google.gitiles.GitilesAccess)1 GitilesServlet (com.google.gitiles.GitilesServlet)1 STATIC_PREFIX (com.google.gitiles.GitilesServlet.STATIC_PREFIX)1 PathServlet (com.google.gitiles.PathServlet)1 RepositoryDescription (com.google.gitiles.RepositoryDescription)1 RootedDocServlet (com.google.gitiles.RootedDocServlet)1 InetAddress (java.net.InetAddress)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1