Class CommentPorter

java.lang.Object
com.google.gerrit.server.restapi.change.CommentPorter

public class CommentPorter extends Object
Container for all logic necessary to port comments to a target patchset.

A ported comment is a comment which was left on an earlier patchset and is shown on a later patchset. If a comment eligible for porting (e.g. before target patchset) can't be matched to its exact position in the target patchset, we'll map it to its next best location. This can also include a transformation of a line comment into a file comment.

  • Constructor Details

    • CommentPorter

      @Inject public CommentPorter(DiffOperations diffOperations, CommentsUtil commentsUtil, com.google.gerrit.server.restapi.change.CommentPorter.Metrics metrics)
  • Method Details

    • portComments

      public com.google.common.collect.ImmutableList<HumanComment> portComments(ChangeNotes changeNotes, PatchSet targetPatchset, List<HumanComment> comments, List<HumanCommentFilter> filters)
      Ports the given comments to the target patchset.

      Not all given comments are ported. Only those fulfilling some criteria (e.g. before target patchset) are considered eligible for porting.

      The returned comments represent the ported version. They don't bear any indication to which patchset they were ported. This is intentional as the target patchset should be obvious from the API or the used REST resources. The returned comments still have the patchset field filled. It contains the reference to the patchset on which the comment was originally left. That patchset number can vary among the returned comments as all comments before the target patchset are potentially eligible for porting.

      The number of returned comments can be smaller (-> only eligible ones are ported!) or larger compared to the provided comments. The latter happens when files appear as copied in the target patchset. In such a situation, the same comment UUID will occur more than once in the returned comments.

      Parameters:
      changeNotes - the ChangeNotes of the change to which the comments belong
      targetPatchset - the patchset to which the comments should be ported
      comments - the original comments
      filters - additional filters to apply to the comments before porting. Only the remaining comments will be ported.
      Returns:
      the ported comments, in no particular order