use of org.eclipse.jgit.errors.RepositoryNotFoundException in project gerrit by GerritCodeReview.
the class AllChangesIndexer method reindexProject.
public Callable<Void> reindexProject(final ChangeIndexer indexer, final Project.NameKey project, final Task done, final Task failed, final PrintWriter verboseWriter) {
return new Callable<Void>() {
@Override
public Void call() throws Exception {
ListMultimap<ObjectId, ChangeData> byId = MultimapBuilder.hashKeys().arrayListValues().build();
// with RepositoryCache.close(repo).
try (Repository repo = repoManager.openRepository(project);
ReviewDb db = schemaFactory.open()) {
Map<String, Ref> refs = repo.getRefDatabase().getRefs(ALL);
// change IDs.
for (ChangeNotes cn : notesFactory.scan(repo, db, project)) {
Ref r = refs.get(cn.getChange().currentPatchSetId().toRefName());
if (r != null) {
byId.put(r.getObjectId(), changeDataFactory.create(db, cn));
}
}
new ProjectIndexer(indexer, byId, repo, done, failed, verboseWriter).call();
} catch (RepositoryNotFoundException rnfe) {
log.error(rnfe.getMessage());
}
return null;
}
@Override
public String toString() {
return "Index all changes of project " + project.get();
}
};
}
use of org.eclipse.jgit.errors.RepositoryNotFoundException in project gerrit by GerritCodeReview.
the class LsUserRefs method run.
@Override
protected void run() throws Failure {
Account userAccount;
try {
userAccount = accountResolver.find(db, userName);
} catch (OrmException e) {
throw die(e);
}
if (userAccount == null) {
stdout.print("No single user could be found when searching for: " + userName + '\n');
stdout.flush();
return;
}
IdentifiedUser user = userFactory.create(userAccount.getId());
ProjectControl userProjectControl = projectControl.forUser(user);
try (Repository repo = repoManager.openRepository(userProjectControl.getProject().getNameKey())) {
try {
Map<String, Ref> refsMap = new VisibleRefFilter(tagCache, changeNotesFactory, changeCache, repo, userProjectControl, db, true).filter(repo.getRefDatabase().getRefs(ALL), false);
for (final String ref : refsMap.keySet()) {
if (!onlyRefsHeads || ref.startsWith(RefNames.REFS_HEADS)) {
stdout.println(ref);
}
}
} catch (IOException e) {
throw new Failure(1, "fatal: Error reading refs: '" + projectControl.getProject().getNameKey(), e);
}
} catch (RepositoryNotFoundException e) {
throw die("'" + projectControl.getProject().getNameKey() + "': not a git archive");
} catch (IOException e) {
throw die("Error opening: '" + projectControl.getProject().getNameKey());
}
}
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;
}
}
Aggregations