use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.
the class CommentDetail method orderComments.
/**
* Order the comments based on their parent_uuid parent. It is possible to do this by iterating
* over the list only once but it's probably overkill since the number of comments on a given line
* will be small most of the time.
*
* @param comments The list of comments for a given line.
* @return The comments sorted as they should appear in the UI
*/
private static List<Comment> orderComments(List<Comment> comments) {
// Map of comments keyed by their parent. The values are lists of comments since it is
// possible for several comments to have the same parent (this can happen if two reviewers
// click Reply on the same comment at the same time). Such comments will be displayed under
// their correct parent in chronological order.
Map<String, List<Comment>> parentMap = new HashMap<>();
// It's possible to have more than one root comment if two reviewers create a comment on the
// same line at the same time
List<Comment> rootComments = new ArrayList<>();
// Store all the comments in parentMap, keyed by their parent
for (Comment c : comments) {
String parentUuid = c.parentUuid;
List<Comment> l = parentMap.get(parentUuid);
if (l == null) {
l = new ArrayList<>();
parentMap.put(parentUuid, l);
}
l.add(c);
if (parentUuid == null) {
rootComments.add(c);
}
}
// Add the comments in the list, starting with the head and then going through all the
// comments that have it as a parent, and so on
List<Comment> result = new ArrayList<>();
addChildren(parentMap, rootComments, result);
return result;
}
use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.
the class AbstractParserTest method newComment.
protected static Comment newComment(String uuid, String file, String message, int line) {
Comment c = new Comment(new Comment.Key(uuid, file, 1), new Account.Id(0), new Timestamp(0L), (short) 0, message, "", false);
c.lineNbr = line;
return c;
}
use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.
the class DeleteCommentRewriter method getPutInComments.
/**
* Gets the comments put in by the current commit. The message of the target comment will be
* replaced by the new message.
*
* @param parMap the comment map of the parent commit.
* @param curMap the comment map of the current commit.
* @return The comments put in by the current commit.
*/
private List<Comment> getPutInComments(Map<String, Comment> parMap, Map<String, Comment> curMap) {
List<Comment> comments = new ArrayList<>();
for (String key : curMap.keySet()) {
if (!parMap.containsKey(key)) {
Comment comment = curMap.get(key);
if (key.equals(uuid)) {
comment.message = newMessage;
}
comments.add(comment);
}
}
return comments;
}
use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.
the class DraftCommentNotes method onLoad.
@Override
protected void onLoad(LoadHandle handle) throws IOException, ConfigInvalidException {
ObjectId rev = handle.id();
if (rev == null) {
loadDefaults();
return;
}
RevCommit tipCommit = handle.walk().parseCommit(rev);
ObjectReader reader = handle.walk().getObjectReader();
revisionNoteMap = RevisionNoteMap.parse(args.noteUtil, getChangeId(), reader, NoteMap.read(reader, tipCommit), PatchLineComment.Status.DRAFT);
ListMultimap<RevId, Comment> cs = MultimapBuilder.hashKeys().arrayListValues().build();
for (ChangeRevisionNote rn : revisionNoteMap.revisionNotes.values()) {
for (Comment c : rn.getComments()) {
cs.put(new RevId(c.revId), c);
}
}
comments = ImmutableListMultimap.copyOf(cs);
}
use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.
the class ChangeNotesParser method parseNotes.
private void parseNotes() throws IOException, ConfigInvalidException {
ObjectReader reader = walk.getObjectReader();
ChangeNotesCommit tipCommit = walk.parseCommit(tip);
revisionNoteMap = RevisionNoteMap.parse(noteUtil, id, reader, NoteMap.read(reader, tipCommit), PatchLineComment.Status.PUBLISHED);
Map<RevId, ChangeRevisionNote> rns = revisionNoteMap.revisionNotes;
for (Map.Entry<RevId, ChangeRevisionNote> e : rns.entrySet()) {
for (Comment c : e.getValue().getComments()) {
comments.put(e.getKey(), c);
}
}
for (PatchSet ps : patchSets.values()) {
ChangeRevisionNote rn = rns.get(ps.getRevision());
if (rn != null && rn.getPushCert() != null) {
ps.setPushCertificate(rn.getPushCert());
}
}
}
Aggregations