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);
}
}
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;
}
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);
}
}
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);
}
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;
}
}
Aggregations