Search in sources :

Example 46 with TraceTimer

use of com.google.gerrit.server.logging.TraceContext.TraceTimer in project gerrit by GerritCodeReview.

the class DefaultRefFilter method filter.

/**
 * Filters given refs and tags by visibility.
 */
ImmutableList<Ref> filter(Collection<Ref> refs, Repository repo, RefFilterOptions opts) throws PermissionBackendException {
    visibleChangesCache = visibleChangesCacheFactory.create(projectControl, repo);
    logger.atFinest().log("Filter refs for repository %s by visibility (options = %s, refs = %s)", projectState.getNameKey(), opts, refs);
    logger.atFinest().log("Calling user: %s", user.getLoggableName());
    logger.atFinest().log("Groups: %s", lazy(() -> user.getEffectiveGroups().getKnownGroups()));
    logger.atFinest().log("auth.skipFullRefEvaluationIfAllRefsAreVisible = %s", skipFullRefEvaluationIfAllRefsAreVisible);
    logger.atFinest().log("Project state %s permits read = %s", projectState.getProject().getState(), projectState.statePermitsRead());
    // See if we can get away with a single, cheap ref evaluation.
    if (refs.size() == 1) {
        String refName = Iterables.getOnlyElement(refs).getName();
        if (opts.filterMeta() && isMetadata(refName)) {
            logger.atFinest().log("Filter out metadata ref %s", refName);
            return ImmutableList.of();
        }
        if (RefNames.isRefsChanges(refName)) {
            boolean isChangeRefVisisble = canSeeSingleChangeRef(repo, refName);
            if (isChangeRefVisisble) {
                logger.atFinest().log("Change ref %s is visible", refName);
                return ImmutableList.copyOf(refs);
            }
            logger.atFinest().log("Filter out non-visible change ref %s", refName);
            return ImmutableList.of();
        }
    }
    // Perform an initial ref filtering with all the refs the caller asked for. If we find tags that
    // we have to investigate separately (deferred tags) then perform a reachability check starting
    // from all visible branches (refs/heads/*).
    Result initialRefFilter = filterRefs(new ArrayList<>(refs), opts);
    ImmutableList.Builder<Ref> visibleRefs = ImmutableList.builder();
    visibleRefs.addAll(initialRefFilter.visibleRefs());
    if (!initialRefFilter.deferredTags().isEmpty()) {
        try (TraceTimer traceTimer = TraceContext.newTimer("Check visibility of deferred tags")) {
            Result allVisibleBranches = filterRefs(getTaggableRefs(repo), opts);
            checkState(allVisibleBranches.deferredTags().isEmpty(), "unexpected tags found when filtering refs/heads/* " + allVisibleBranches.deferredTags());
            TagMatcher tags = tagCache.get(projectState.getNameKey()).matcher(tagCache, repo, allVisibleBranches.visibleRefs());
            for (Ref tag : initialRefFilter.deferredTags()) {
                try {
                    if (tags.isReachable(tag)) {
                        logger.atFinest().log("Include reachable tag %s", tag.getName());
                        visibleRefs.add(tag);
                    } else {
                        logger.atFinest().log("Filter out non-reachable tag %s", tag.getName());
                    }
                } catch (IOException e) {
                    throw new PermissionBackendException(e);
                }
            }
        }
    }
    ImmutableList<Ref> visibleRefList = visibleRefs.build();
    logger.atFinest().log("visible refs = %s", visibleRefList);
    return visibleRefList;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) ImmutableList(com.google.common.collect.ImmutableList) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) IOException(java.io.IOException) TagMatcher(com.google.gerrit.server.git.TagMatcher)

Aggregations

TraceTimer (com.google.gerrit.server.logging.TraceContext.TraceTimer)46 StorageException (com.google.gerrit.exceptions.StorageException)17 IOException (java.io.IOException)14 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 RevWalk (org.eclipse.jgit.revwalk.RevWalk)12 AuthException (com.google.gerrit.extensions.restapi.AuthException)11 Ref (org.eclipse.jgit.lib.Ref)11 HumanComment (com.google.gerrit.entities.HumanComment)8 RefNames.isConfigRef (com.google.gerrit.entities.RefNames.isConfigRef)8 Change (com.google.gerrit.entities.Change)7 PatchSet (com.google.gerrit.entities.PatchSet)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)7 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)7 ObjectId (org.eclipse.jgit.lib.ObjectId)7 ImmutableList (com.google.common.collect.ImmutableList)6 BranchNameKey (com.google.gerrit.entities.BranchNameKey)6 Project (com.google.gerrit.entities.Project)6 InvalidDeadlineException (com.google.gerrit.server.InvalidDeadlineException)6 RequestId (com.google.gerrit.server.logging.RequestId)6 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)6