Do not filter out comments on A side of commit messages
We assumed that comments can never exist on the A side of the diff of
commit messages but it turns out that this is not true (see comment in
[1] as example).
[1] https://gerrit-review.googlesource.com/c/gitiles/+/37820/comment/238bd6f1_ecca3c3a/
Google-Bug-Id: b/318012735
Release-Notes: skip
Change-Id: I689d54efa23d281207e9746e9d5af8133a5999a5
diff --git a/java/com/google/gerrit/server/CommentsUtil.java b/java/com/google/gerrit/server/CommentsUtil.java
index deaff4b..f0e3183 100644
--- a/java/com/google/gerrit/server/CommentsUtil.java
+++ b/java/com/google/gerrit/server/CommentsUtil.java
@@ -18,7 +18,6 @@
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Comparator.comparing;
import static java.util.stream.Collectors.toCollection;
-import static java.util.stream.Collectors.toList;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Lists;
@@ -28,7 +27,6 @@
import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
-import com.google.gerrit.entities.Patch;
import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.RobotComment;
@@ -209,13 +207,8 @@
return robotCommentsByChange(notes).stream().filter(c -> c.key.uuid.equals(uuid)).findFirst();
}
- public List<HumanComment> publishedByChangeFile(ChangeNotes notes, String file) {
- return commentsOnFile(notes.load().getHumanComments().values(), file);
- }
-
public List<HumanComment> publishedByPatchSet(ChangeNotes notes, PatchSet.Id psId) {
- return removeCommentsOnAncestorOfCommitMessage(
- commentsOnPatchSet(notes.load().getHumanComments().values(), psId));
+ return commentsOnPatchSet(notes.load().getHumanComments().values(), psId);
}
public List<RobotComment> robotCommentsByPatchSet(ChangeNotes notes, PatchSet.Id psId) {
@@ -287,18 +280,6 @@
Optional.ofNullable(cm.getAuthor()).map(a -> a.get()),
Optional.ofNullable(comment.author).map(a -> a._accountId));
}
- /**
- * For the commit message the A side in a diff view is always empty when a comparison against an
- * ancestor is done, so there can't be any comments on this ancestor. However earlier we showed
- * the auto-merge commit message on side A when for a merge commit a comparison against the
- * auto-merge was done. From that time there may still be comments on the auto-merge commit
- * message and those we want to filter out.
- */
- private List<HumanComment> removeCommentsOnAncestorOfCommitMessage(List<HumanComment> list) {
- return list.stream()
- .filter(c -> c.side != 0 || !Patch.COMMIT_MSG.equals(c.key.filename))
- .collect(toList());
- }
public void putHumanComments(
ChangeUpdate update, Comment.Status status, Iterable<HumanComment> comments) {
@@ -324,18 +305,6 @@
update.deleteCommentByRewritingHistory(commentKey.uuid, newMessage);
}
- private static List<HumanComment> commentsOnFile(
- Collection<HumanComment> allComments, String file) {
- List<HumanComment> result = new ArrayList<>(allComments.size());
- for (HumanComment c : allComments) {
- String currentFilename = c.key.filename;
- if (currentFilename.equals(file)) {
- result.add(c);
- }
- }
- return sort(result);
- }
-
private static <T extends Comment> List<T> commentsOnPatchSet(
Collection<T> allComments, PatchSet.Id psId) {
List<T> result = new ArrayList<>(allComments.size());