Search in sources :

Example 16 with TraceTimer

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

the class ReceiveCommits method parseCreate.

private void parseCreate(ReceiveCommand cmd) throws PermissionBackendException, NoSuchProjectException, IOException {
    try (TraceTimer traceTimer = newTimer("parseCreate")) {
        if (repo.resolve(cmd.getRefName()) != null) {
            reject(cmd, String.format("Cannot create ref '%s' because it already exists.", cmd.getRefName()));
            return;
        }
        RevObject obj;
        try {
            obj = receivePack.getRevWalk().parseAny(cmd.getNewId());
        } catch (IOException e) {
            throw new StorageException(String.format("Invalid object %s for %s creation", cmd.getNewId().name(), cmd.getRefName()), e);
        }
        logger.atFine().log("Creating %s", cmd);
        if (isHead(cmd) && !isCommit(cmd)) {
            return;
        }
        BranchNameKey branch = BranchNameKey.create(project.getName(), cmd.getRefName());
        try {
            // Must pass explicit user instead of injecting a provider into CreateRefControl, since
            // Provider<CurrentUser> within ReceiveCommits will always return anonymous.
            createRefControl.checkCreateRef(Providers.of(user), receivePack.getRepository(), branch, obj);
        } catch (AuthException denied) {
            rejectProhibited(cmd, denied);
            return;
        } catch (ResourceConflictException denied) {
            reject(cmd, "prohibited by Gerrit: " + denied.getMessage());
            return;
        }
        if (validRefOperation(cmd)) {
            validateRegularPushCommits(BranchNameKey.create(project.getNameKey(), cmd.getRefName()), cmd);
        }
    }
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) RevObject(org.eclipse.jgit.revwalk.RevObject) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) AuthException(com.google.gerrit.extensions.restapi.AuthException) IOException(java.io.IOException) StorageException(com.google.gerrit.exceptions.StorageException)

Example 17 with TraceTimer

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

the class ReceiveCommits method rejectImplicitMerges.

private void rejectImplicitMerges(Set<RevCommit> mergedParents) throws IOException {
    try (TraceTimer traceTimer = newTimer("rejectImplicitMerges")) {
        if (!mergedParents.isEmpty()) {
            Ref targetRef = receivePackRefCache.exactRef(magicBranch.dest.branch());
            if (targetRef != null) {
                RevWalk rw = receivePack.getRevWalk();
                RevCommit tip = rw.parseCommit(targetRef.getObjectId());
                boolean containsImplicitMerges = true;
                for (RevCommit p : mergedParents) {
                    containsImplicitMerges &= !rw.isMergedInto(p, tip);
                }
                if (containsImplicitMerges) {
                    rw.reset();
                    for (RevCommit p : mergedParents) {
                        rw.markStart(p);
                    }
                    rw.markUninteresting(tip);
                    RevCommit c;
                    while ((c = rw.next()) != null) {
                        rw.parseBody(c);
                        messages.add(new CommitValidationMessage("Implicit Merge of " + abbreviateName(c, rw.getObjectReader()) + " " + c.getShortMessage(), ValidationMessage.Type.ERROR));
                    }
                    reject(magicBranch.cmd, "implicit merges detected");
                }
            }
        }
    }
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RefNames.isConfigRef(com.google.gerrit.entities.RefNames.isConfigRef) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) RevWalk(org.eclipse.jgit.revwalk.RevWalk) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 18 with TraceTimer

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

the class ReceiveCommits method validateConnected.

// Validate that the new commits are connected with the target
// branch.  If they aren't, we want to abort. We do this check by
// looking to see if we can compute a merge base between the new
// commits and the target branch head.
private boolean validateConnected(ReceiveCommand cmd, BranchNameKey dest, RevCommit tip) {
    try (TraceTimer traceTimer = newTimer("validateConnected", Metadata.builder().branchName(dest.branch()))) {
        RevWalk walk = receivePack.getRevWalk();
        try {
            Ref targetRef = receivePackRefCache.exactRef(dest.branch());
            if (targetRef == null || targetRef.getObjectId() == null) {
                // The destination branch does not yet exist. Assume the
                // history being sent for review will start it and thus
                // is "connected" to the branch.
                logger.atFine().log("Branch is unborn");
                // This is not an error condition.
                return true;
            }
            RevCommit h = walk.parseCommit(targetRef.getObjectId());
            logger.atFine().log("Current branch tip: %s", h.name());
            RevFilter oldRevFilter = walk.getRevFilter();
            try {
                walk.reset();
                walk.setRevFilter(RevFilter.MERGE_BASE);
                walk.markStart(tip);
                walk.markStart(h);
                if (walk.next() == null) {
                    reject(cmd, "no common ancestry");
                    return false;
                }
            } finally {
                walk.reset();
                walk.setRevFilter(oldRevFilter);
            }
        } catch (IOException e) {
            cmd.setResult(REJECTED_MISSING_OBJECT);
            logger.atSevere().withCause(e).log("Invalid pack upload; one or more objects weren't sent");
            return false;
        }
        return true;
    }
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RefNames.isConfigRef(com.google.gerrit.entities.RefNames.isConfigRef) RevFilter(org.eclipse.jgit.revwalk.filter.RevFilter) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 19 with TraceTimer

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

the class CommentPorter method portSamePatchset.

private ImmutableList<HumanComment> portSamePatchset(Project.NameKey project, Change change, PatchSet originalPatchset, PatchSet targetPatchset, ImmutableList<HumanComment> comments) {
    try (TraceTimer ignored = TraceContext.newTimer("Porting comments same patchset", Metadata.builder().projectName(project.get()).changeId(change.getChangeId()).patchSetId(originalPatchset.number()).build())) {
        Map<Short, List<HumanComment>> commentsPerSide = comments.stream().collect(groupingBy(comment -> comment.side));
        ImmutableList.Builder<HumanComment> portedComments = ImmutableList.builder();
        for (Map.Entry<Short, List<HumanComment>> sideAndComments : commentsPerSide.entrySet()) {
            portedComments.addAll(portSamePatchsetAndSide(project, change, originalPatchset, targetPatchset, sideAndComments.getValue(), sideAndComments.getKey()));
        }
        return portedComments.build();
    }
}
Also used : Patch(com.google.gerrit.entities.Patch) Inject(com.google.inject.Inject) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Mapping(com.google.gerrit.server.patch.GitPositionTransformer.Mapping) HumanComment(com.google.gerrit.entities.HumanComment) CommentsUtil(com.google.gerrit.server.CommentsUtil) Position(com.google.gerrit.server.patch.GitPositionTransformer.Position) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) Function(java.util.function.Function) BestPositionOnConflict(com.google.gerrit.server.patch.GitPositionTransformer.BestPositionOnConflict) DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException) ImmutableList(com.google.common.collect.ImmutableList) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput) Description(com.google.gerrit.metrics.Description) Map(java.util.Map) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) Metadata(com.google.gerrit.server.logging.Metadata) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TraceContext(com.google.gerrit.server.logging.TraceContext) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) DiffMappings(com.google.gerrit.server.patch.DiffMappings) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) ObjectId(org.eclipse.jgit.lib.ObjectId) DiffOptions(com.google.gerrit.server.patch.DiffOptions) TaggedEdit(com.google.gerrit.server.patch.filediff.TaggedEdit) List(java.util.List) FileEdits(com.google.gerrit.server.patch.filediff.FileEdits) Stream(java.util.stream.Stream) GitPositionTransformer(com.google.gerrit.server.patch.GitPositionTransformer) DiffOperations(com.google.gerrit.server.patch.DiffOperations) FileMapping(com.google.gerrit.server.patch.GitPositionTransformer.FileMapping) Project(com.google.gerrit.entities.Project) PositionedEntity(com.google.gerrit.server.patch.GitPositionTransformer.PositionedEntity) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Counter0(com.google.gerrit.metrics.Counter0) MetricMaker(com.google.gerrit.metrics.MetricMaker) FluentLogger(com.google.common.flogger.FluentLogger) Range(com.google.gerrit.entities.Comment.Range) Singleton(com.google.inject.Singleton) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) HumanComment(com.google.gerrit.entities.HumanComment) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 20 with TraceTimer

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

the class CommentPorter method portSamePatchsetAndSide.

private ImmutableList<HumanComment> portSamePatchsetAndSide(Project.NameKey project, Change change, PatchSet originalPatchset, PatchSet targetPatchset, List<HumanComment> comments, short side) {
    try (TraceTimer ignored = TraceContext.newTimer("Porting comments same patchset and side", Metadata.builder().projectName(project.get()).changeId(change.getChangeId()).patchSetId(originalPatchset.number()).commentSide(side).build())) {
        ImmutableSet<Mapping> mappings;
        try {
            mappings = loadMappings(project, change, originalPatchset, targetPatchset, side);
        } catch (Exception e) {
            logger.atWarning().withCause(e).log("Could not determine some necessary diff mappings for porting comments on change %s" + " from patchset %s to patchset %s. Mapping %d affected comments to the fallback" + " destination.", change.getChangeId(), originalPatchset.id().getId(), targetPatchset.id().getId(), comments.size());
            mappings = getFallbackMappings(comments);
        }
        ImmutableList<PositionedEntity<HumanComment>> positionedComments = comments.stream().map(this::toPositionedEntity).collect(toImmutableList());
        ImmutableMap<PositionedEntity<HumanComment>, HumanComment> origToPortedMap = positionTransformer.transform(positionedComments, mappings).stream().collect(ImmutableMap.toImmutableMap(Function.identity(), PositionedEntity::getEntityAtUpdatedPosition));
        collectMetrics(origToPortedMap);
        return ImmutableList.copyOf(origToPortedMap.values());
    }
}
Also used : PositionedEntity(com.google.gerrit.server.patch.GitPositionTransformer.PositionedEntity) TraceTimer(com.google.gerrit.server.logging.TraceContext.TraceTimer) Mapping(com.google.gerrit.server.patch.GitPositionTransformer.Mapping) FileMapping(com.google.gerrit.server.patch.GitPositionTransformer.FileMapping) HumanComment(com.google.gerrit.entities.HumanComment) DiffNotAvailableException(com.google.gerrit.server.patch.DiffNotAvailableException)

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