Search in sources :

Example 1 with R_HEADS

use of org.eclipse.jgit.lib.Constants.R_HEADS in project gitiles by GerritCodeReview.

the class VisibilityCache method isVisible.

private boolean isVisible(Repository repo, RevWalk walk, ObjectId id, Collection<ObjectId> knownReachable) throws IOException {
    RevCommit commit;
    try {
        commit = walk.parseCommit(id);
    } catch (IncorrectObjectTypeException e) {
        return false;
    }
    // If any reference directly points at the requested object, permit display. Common for displays
    // of pending patch sets in Gerrit Code Review, or bookmarks to the commit a tag points at.
    Collection<Ref> all = repo.getRefDatabase().getRefs(RefDatabase.ALL).values();
    for (Ref ref : all) {
        ref = repo.getRefDatabase().peel(ref);
        if (id.equals(ref.getObjectId()) || id.equals(ref.getPeeledObjectId())) {
            return true;
        }
    }
    // case.
    return isReachableFrom(walk, commit, knownReachable) || isReachableFromRefs(walk, commit, all.stream().filter(r -> refStartsWith(r, R_HEADS))) || isReachableFromRefs(walk, commit, all.stream().filter(r -> refStartsWith(r, R_TAGS))) || isReachableFromRefs(walk, commit, all.stream().filter(r -> otherRefs(r)));
}
Also used : Arrays(java.util.Arrays) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Objects.hash(java.util.Objects.hash) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) ExecutionError(com.google.common.util.concurrent.ExecutionError) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RefDatabase(org.eclipse.jgit.lib.RefDatabase) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Throwables(com.google.common.base.Throwables) RevSort(org.eclipse.jgit.revwalk.RevSort) IOException(java.io.IOException) ObjectId(org.eclipse.jgit.lib.ObjectId) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) R_HEADS(org.eclipse.jgit.lib.Constants.R_HEADS) Stream(java.util.stream.Stream) Ref(org.eclipse.jgit.lib.Ref) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) CacheBuilder(com.google.common.cache.CacheBuilder) R_TAGS(org.eclipse.jgit.lib.Constants.R_TAGS) Cache(com.google.common.cache.Cache) Repository(org.eclipse.jgit.lib.Repository) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Ref(org.eclipse.jgit.lib.Ref) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Throwables (com.google.common.base.Throwables)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 ExecutionError (com.google.common.util.concurrent.ExecutionError)1 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Objects (java.util.Objects)1 Objects.hash (java.util.Objects.hash)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)1 MissingObjectException (org.eclipse.jgit.errors.MissingObjectException)1 R_HEADS (org.eclipse.jgit.lib.Constants.R_HEADS)1 R_TAGS (org.eclipse.jgit.lib.Constants.R_TAGS)1