NoteDb: Support comments on multiple patch sets with same base

It is possible for multiple patch sets to share the base revision,
contrary to the previous assumption in the notes format. We were
assuming that a single note contained only comments for a single patch
set ID, with the format:

  (Base-for-)Patch-set: 1
  Revision: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
  ...

Tweak the format slightly to reflect the fact that there may be
multiple patch sets represented in a single note:

  Revision: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
  (Base-for-)Patch-set: 1
  ...

  (Base-for-)Patch-set: 2
  ...

Support this both in the parser and when building RevisionNotes, as
we can publish multiple comments on the same base with different patch
set IDs when using PUBLISH_ALL_REVISIONS.

Change-Id: I8d2995b04a926bc7c39bab7de863ba8217b0e350
This commit is contained in:
Dave Borowitz
2016-04-21 12:24:55 -04:00
parent bcbf1f8324
commit ddb2c60c63
4 changed files with 239 additions and 113 deletions

View File

@@ -932,8 +932,8 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
notes = newNotes(c);
assertThat(readNote(notes, commit)).isEqualTo(
pushCert
+ "Patch-set: 2\n"
+ "Revision: " + commit.name() + "\n"
+ "Patch-set: 2\n"
+ "File: a.txt\n"
+ "\n"
+ "1:2-3:4\n"
@@ -1314,8 +1314,9 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
walk.getObjectReader().open(
note.getData(), Constants.OBJ_BLOB).getBytes();
String noteString = new String(bytes, UTF_8);
assertThat(noteString).isEqualTo("Patch-set: 1\n"
+ "Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
assertThat(noteString).isEqualTo(
"Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
+ "Patch-set: 1\n"
+ "File: file1\n"
+ "\n"
+ "1:1-2:1\n"
@@ -1384,8 +1385,9 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
walk.getObjectReader().open(
note.getData(), Constants.OBJ_BLOB).getBytes();
String noteString = new String(bytes, UTF_8);
assertThat(noteString).isEqualTo("Base-for-patch-set: 1\n"
+ "Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
assertThat(noteString).isEqualTo(
"Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
+ "Base-for-patch-set: 1\n"
+ "File: file1\n"
+ "\n"
+ "1:1-2:1\n"
@@ -1405,6 +1407,91 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
}
}
@Test
public void patchLineCommentNotesFormatMultiplePatchSetsSameRevId()
throws Exception {
Change c = newChange();
String uuid1 = "uuid1";
String uuid2 = "uuid2";
String uuid3 = "uuid3";
String message1 = "comment 1";
String message2 = "comment 2";
String message3 = "comment 3";
CommentRange range1 = new CommentRange(1, 1, 2, 1);
CommentRange range2 = new CommentRange(2, 1, 3, 1);
Timestamp time = TimeUtil.nowTs();
RevId revId = new RevId("abcd1234abcd1234abcd1234abcd1234abcd1234");
PatchSet.Id psId1 = c.currentPatchSetId();
PatchSet.Id psId2 = new PatchSet.Id(c.getId(), psId1.get() + 1);
PatchLineComment comment1 = newPublishedComment(psId1, "file1",
uuid1, range1, range1.getEndLine(), otherUser, null, time, message1,
(short) 0, revId.get());
PatchLineComment comment2 = newPublishedComment(psId1, "file1",
uuid2, range2, range2.getEndLine(), otherUser, null, time, message2,
(short) 0, revId.get());
PatchLineComment comment3 = newPublishedComment(psId2, "file1",
uuid3, range1, range1.getEndLine(), otherUser, null, time, message3,
(short) 0, revId.get());
ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(psId2);
update.putComment(comment3);
update.putComment(comment2);
update.putComment(comment1);
update.commit();
ChangeNotes notes = newNotes(c);
try (RevWalk walk = new RevWalk(repo)) {
ArrayList<Note> notesInTree =
Lists.newArrayList(notes.revisionNoteMap.noteMap.iterator());
Note note = Iterables.getOnlyElement(notesInTree);
byte[] bytes =
walk.getObjectReader().open(
note.getData(), Constants.OBJ_BLOB).getBytes();
String noteString = new String(bytes, UTF_8);
String timeStr = ChangeNoteUtil.formatTime(serverIdent, time);
assertThat(noteString).isEqualTo(
"Revision: abcd1234abcd1234abcd1234abcd1234abcd1234\n"
+ "Base-for-patch-set: 1\n"
+ "File: file1\n"
+ "\n"
+ "1:1-2:1\n"
+ timeStr + "\n"
+ "Author: Other Account <2@gerrit>\n"
+ "UUID: uuid1\n"
+ "Bytes: 9\n"
+ "comment 1\n"
+ "\n"
+ "2:1-3:1\n"
+ timeStr + "\n"
+ "Author: Other Account <2@gerrit>\n"
+ "UUID: uuid2\n"
+ "Bytes: 9\n"
+ "comment 2\n"
+ "\n"
+ "Base-for-patch-set: 2\n"
+ "File: file1\n"
+ "\n"
+ "1:1-2:1\n"
+ timeStr + "\n"
+ "Author: Other Account <2@gerrit>\n"
+ "UUID: uuid3\n"
+ "Bytes: 9\n"
+ "comment 3\n"
+ "\n");
}
assertThat(notes.getComments()).isEqualTo(
ImmutableMultimap.of(
revId, comment1,
revId, comment2,
revId, comment3));
}
@Test
public void patchLineCommentMultipleOnePatchsetOneFileBothSides()
throws Exception {