Modify PatchLineComment parser to incorporate status

In anticipation of the ability to write draft PatchLineComments to
NoteMaps, I modified some of the parsing code for reading comments out
of NoteMaps to take status as a parameter so that when it parses a
List of PatchLineComments out of the notes, they have the correct
status. This is valid to do because all comments in the same note
will all have the same status.

Additionally, I had to modify the ChangeNotesTest class in combination
with this to make sure that the comments being created for testing
purposes had the status flag set correctly.

Change-Id: If32e7075427abd2e6f02721824e8099243806243
This commit is contained in:
Yacob Yonas
2014-07-14 14:09:48 -07:00
parent 9733ae83b3
commit 2ef433bc92
3 changed files with 51 additions and 37 deletions

View File

@@ -44,6 +44,7 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.PatchLineComment.Status;
import com.google.gerrit.reviewdb.client.PatchSet.Id;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import com.google.gerrit.reviewdb.client.PatchSetApproval.LabelId;
@@ -323,7 +324,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
throws IOException, ConfigInvalidException, ParseException {
commentNoteMap = CommentsInNotesUtil.parseCommentsFromNotes(repo,
ChangeNoteUtil.changeRefName(changeId), walk, changeId,
commentsForBase, commentsForPs);
commentsForBase, commentsForPs, Status.PUBLISHED);
}
private void parseApproval(PatchSet.Id psId, Account.Id accountId,

View File

@@ -28,6 +28,7 @@ import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.CommentRange;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchLineComment;
import com.google.gerrit.reviewdb.client.PatchLineComment.Status;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.server.GerritPersonIdent;
@@ -82,7 +83,8 @@ public class CommentsInNotesUtil {
public static NoteMap parseCommentsFromNotes(Repository repo, String refName,
RevWalk walk, Change.Id changeId,
Multimap<PatchSet.Id, PatchLineComment> commentsForBase,
Multimap<PatchSet.Id, PatchLineComment> commentsForPs)
Multimap<PatchSet.Id, PatchLineComment> commentsForPs,
Status status)
throws IOException, ConfigInvalidException {
Ref ref = repo.getRef(refName);
if (ref == null) {
@@ -94,7 +96,7 @@ public class CommentsInNotesUtil {
for (Note note: noteMap) {
byte[] bytes = walk.getObjectReader().open(
note.getData(), Constants.OBJ_BLOB).getBytes();
List<PatchLineComment> result = parseNote(bytes, changeId);
List<PatchLineComment> result = parseNote(bytes, changeId, status);
if ((result == null) || (result.isEmpty())) {
continue;
}
@@ -110,7 +112,7 @@ public class CommentsInNotesUtil {
}
public static List<PatchLineComment> parseNote(byte[] note,
Change.Id changeId) throws ConfigInvalidException {
Change.Id changeId, Status status) throws ConfigInvalidException {
List<PatchLineComment> result = Lists.newArrayList();
int sizeOfNote = note.length;
Charset enc = RawParseUtils.parseEncoding(note);
@@ -131,7 +133,7 @@ public class CommentsInNotesUtil {
String previousFileName = c == null ?
null : c.getKey().getParentKey().getFileName();
c = parseComment(note, curr, previousFileName, psId, revId,
isForBase, enc);
isForBase, enc, status);
result.add(c);
}
return result;
@@ -150,7 +152,7 @@ public class CommentsInNotesUtil {
private static PatchLineComment parseComment(byte[] note, MutableInteger curr,
String currentFileName, PatchSet.Id psId, RevId revId, boolean isForBase,
Charset enc)
Charset enc, Status status)
throws ConfigInvalidException {
Change.Id changeId = psId.getParentKey();
@@ -195,6 +197,7 @@ public class CommentsInNotesUtil {
plc.setRange(range);
}
plc.setRevId(revId);
plc.setStatus(status);
curr.value = RawParseUtils.nextLF(note, curr.value + commentLength);
curr.value = RawParseUtils.nextLF(note, curr.value);