use of org.eclipse.jgit.errors.RepositoryNotFoundException 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.errors.RepositoryNotFoundException in project gitiles by GerritCodeReview.
the class DefaultAccess method scanRepositories.
private Collection<Repository> scanRepositories(File basePath, String prefix, HttpServletRequest req) throws IOException {
List<Repository> repos = Lists.newArrayList();
Queue<File> todo = initScan(basePath, prefix);
while (!todo.isEmpty()) {
File file = todo.remove();
try {
repos.add(resolver.open(req, getRelativePath(file.getPath())));
} catch (RepositoryNotFoundException e) {
File[] children = file.listFiles();
if (children != null) {
Collections.addAll(todo, children);
}
} catch (ServiceNotEnabledException e) {
throw new IOException(e);
}
}
return repos;
}
use of org.eclipse.jgit.errors.RepositoryNotFoundException 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;
}
}
use of org.eclipse.jgit.errors.RepositoryNotFoundException in project gerrit by GerritCodeReview.
the class LocalDiskRepositoryManager method createRepository.
@Override
public Repository createRepository(Project.NameKey name) throws RepositoryNotFoundException, RepositoryCaseMismatchException, IOException {
Path path = getBasePath(name);
if (isUnreasonableName(name)) {
throw new RepositoryNotFoundException("Invalid name: " + name);
}
File dir = FileKey.resolve(path.resolve(name.get()).toFile(), FS.DETECTED);
FileKey loc;
if (dir != null) {
// Already exists on disk, use the repository we found.
//
Project.NameKey onDiskName = getProjectName(path, dir.getCanonicalFile().toPath());
onCreateProject(onDiskName);
loc = FileKey.exact(dir, FS.DETECTED);
if (!names.contains(name)) {
throw new RepositoryCaseMismatchException(name);
}
} else {
// It doesn't exist under any of the standard permutations
// of the repository name, so prefer the standard bare name.
//
String n = name.get() + Constants.DOT_GIT_EXT;
loc = FileKey.exact(path.resolve(n).toFile(), FS.DETECTED);
}
try {
Repository db = RepositoryCache.open(loc, false);
db.create(true);
StoredConfig config = db.getConfig();
config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true);
config.save();
// JGit only writes to the reflog for refs/meta/config if the log file
// already exists.
//
File metaConfigLog = new File(db.getDirectory(), "logs/" + RefNames.REFS_CONFIG);
if (!metaConfigLog.getParentFile().mkdirs() || !metaConfigLog.createNewFile()) {
log.error(String.format("Failed to create ref log for %s in repository %s", RefNames.REFS_CONFIG, name));
}
onCreateProject(name);
return db;
} catch (IOException e1) {
final RepositoryNotFoundException e2;
e2 = new RepositoryNotFoundException("Cannot create repository " + name);
e2.initCause(e1);
throw e2;
}
}
use of org.eclipse.jgit.errors.RepositoryNotFoundException in project gerrit by GerritCodeReview.
the class GarbageCollection method run.
public GarbageCollectionResult run(List<Project.NameKey> projectNames, boolean aggressive, PrintWriter writer) {
GarbageCollectionResult result = new GarbageCollectionResult();
Set<Project.NameKey> projectsToGc = gcQueue.addAll(projectNames);
for (Project.NameKey projectName : Sets.difference(Sets.newHashSet(projectNames), projectsToGc)) {
result.addError(new GarbageCollectionResult.Error(GarbageCollectionResult.Error.Type.GC_ALREADY_SCHEDULED, projectName));
}
for (Project.NameKey p : projectsToGc) {
try (Repository repo = repoManager.openRepository(p)) {
logGcConfiguration(p, repo, aggressive);
print(writer, "collecting garbage for \"" + p + "\":\n");
GarbageCollectCommand gc = Git.wrap(repo).gc();
gc.setAggressive(aggressive);
logGcInfo(p, "before:", gc.getStatistics());
gc.setProgressMonitor(writer != null ? new TextProgressMonitor(writer) : NullProgressMonitor.INSTANCE);
Properties statistics = gc.call();
logGcInfo(p, "after: ", statistics);
print(writer, "done.\n\n");
fire(p, statistics);
} catch (RepositoryNotFoundException e) {
logGcError(writer, p, e);
result.addError(new GarbageCollectionResult.Error(GarbageCollectionResult.Error.Type.REPOSITORY_NOT_FOUND, p));
} catch (Exception e) {
logGcError(writer, p, e);
result.addError(new GarbageCollectionResult.Error(GarbageCollectionResult.Error.Type.GC_FAILED, p));
} finally {
gcQueue.gcFinished(p);
}
}
return result;
}
Aggregations