use of org.eclipse.jgit.revwalk.ReachabilityChecker in project gerrit by GerritCodeReview.
the class Reachable method fromRefs.
boolean fromRefs(Project.NameKey project, Repository repo, RevCommit commit, List<Ref> refs, Optional<CurrentUser> optionalUserProvider) {
try (RevWalk rw = new RevWalk(repo)) {
Collection<Ref> filtered = optionalUserProvider.map(permissionBackend::user).orElse(permissionBackend.currentUser()).project(project).filter(refs, repo, RefFilterOptions.defaults());
Collection<RevCommit> visible = new ArrayList<>();
for (Ref r : filtered) {
try {
visible.add(rw.parseCommit(r.getObjectId()));
} catch (IncorrectObjectTypeException notCommit) {
// is common in the Linux kernel or git.git repository.
continue;
} catch (MissingObjectException notHere) {
// Log the problem with this branch, but keep processing.
logger.atWarning().log("Reference %s in %s points to dangling object %s", r.getName(), repo.getDirectory(), r.getObjectId());
continue;
}
}
// from the reachability check, do the trace here:
try (TraceTimer timer = TraceContext.newTimer("ReachabilityChecker.areAllReachable", Metadata.builder().projectName(project.get()).resourceCount(refs.size()).build())) {
ReachabilityChecker checker = rw.getObjectReader().createReachabilityChecker(rw);
Optional<RevCommit> unreachable = checker.areAllReachable(ImmutableList.of(rw.parseCommit(commit)), visible.stream());
return !unreachable.isPresent();
}
} catch (IOException | PermissionBackendException e) {
logger.atSevere().withCause(e).log("Cannot verify permissions to commit object %s in repository %s", commit.name(), project);
return false;
}
}
Aggregations