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);
}
}
}
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");
}
}
}
}
}
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;
}
}
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();
}
}
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());
}
}
Aggregations