use of com.google.gerrit.server.patch.GitPositionTransformer.PositionedEntity 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());
}
}
use of com.google.gerrit.server.patch.GitPositionTransformer.PositionedEntity in project gerrit by GerritCodeReview.
the class CommentPorter method collectMetrics.
/**
* Collect metrics from the original and ported comments.
*
* @param portMap map of the ported comments. The keys contain a {@link PositionedEntity} of the
* original comment, and the values contain the transformed comments.
*/
private void collectMetrics(ImmutableMap<PositionedEntity<HumanComment>, HumanComment> portMap) {
for (Map.Entry<PositionedEntity<HumanComment>, HumanComment> entry : portMap.entrySet()) {
HumanComment original = entry.getKey().getEntity();
HumanComment transformed = entry.getValue();
if (!Patch.isMagic(original.key.filename)) {
if (Patch.PATCHSET_LEVEL.equals(transformed.key.filename)) {
metrics.portedAsPatchsetLevel.increment();
} else if (extractLineRange(original).isPresent()) {
if (extractLineRange(transformed).isPresent()) {
metrics.portedAsRangeComments.increment();
} else {
// line range was present in the original comment, but the ported comment is a file
// level comment.
metrics.portedAsFileLevel.increment();
}
}
}
}
}
Aggregations