ChangeBundle: Handle leading/trailing whitespace in topic/desc

PatchSet descriptions should use the same logic as Change topics to
ignore whitespace that JGit won't accurately parse out of a NoteDb
footer. While writing this, I found that topics should actually be
trimming leading as well as trailing whitespace. Use a single
trimming implementation for both of these.

Change-Id: I564fe674d9b5970717cb3e923b0aa28522c6347a
This commit is contained in:
Dave Borowitz
2017-02-06 10:58:47 -05:00
committed by Edwin Kempin
parent 4e1f02db91
commit e96bd74cf7
2 changed files with 69 additions and 10 deletions

View File

@@ -355,9 +355,9 @@ public class ChangeBundleTest extends GerritBaseTests {
}
@Test
public void diffChangesIgnoresLeadingWhitespaceInReviewDbTopics() throws Exception {
public void diffChangesIgnoresLeadingAndTrailingWhitespaceInReviewDbTopics() throws Exception {
Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
c1.setTopic(" abc");
c1.setTopic(" abc ");
Change c2 = clone(c1);
c2.setTopic("abc");
@@ -368,7 +368,7 @@ public class ChangeBundleTest extends GerritBaseTests {
ChangeBundle b2 =
new ChangeBundle(
c2, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
assertDiffs(b1, b2, "topic differs for Change.Id " + c1.getId() + ":" + " { abc} != {abc}");
assertDiffs(b1, b2, "topic differs for Change.Id " + c1.getId() + ":" + " { abc } != {abc}");
// Leading whitespace in ReviewDb topic is ignored.
b1 =
@@ -380,7 +380,7 @@ public class ChangeBundleTest extends GerritBaseTests {
assertNoDiffs(b1, b2);
assertNoDiffs(b2, b1);
// Must match except for the leading whitespace.
// Must match except for the leading/trailing whitespace.
Change c3 = clone(c1);
c3.setTopic("cba");
b1 =
@@ -389,7 +389,7 @@ public class ChangeBundleTest extends GerritBaseTests {
b2 =
new ChangeBundle(
c3, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
assertDiffs(b1, b2, "topic differs for Change.Id " + c1.getId() + ":" + " { abc} != {cba}");
assertDiffs(b1, b2, "topic differs for Change.Id " + c1.getId() + ":" + " { abc } != {cba}");
}
@Test
@@ -1244,6 +1244,52 @@ public class ChangeBundleTest extends GerritBaseTests {
"PatchSetApproval.Key sets differ:" + " [] only in A; [" + a2.getKey() + "] only in B");
}
@Test
public void diffPatchSetsIgnoresLeadingAndTrailingWhitespaceInReviewDbDescriptions()
throws Exception {
Change c = TestChanges.newChange(project, accountId);
PatchSet ps1 = new PatchSet(new PatchSet.Id(c.getId(), 1));
ps1.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
ps1.setUploader(accountId);
ps1.setCreatedOn(TimeUtil.nowTs());
ps1.setDescription(" abc ");
PatchSet ps2 = clone(ps1);
ps2.setDescription("abc");
// Both ReviewDb, exact match required.
ChangeBundle b1 =
new ChangeBundle(
c, messages(), patchSets(ps1), approvals(), comments(), reviewers(), REVIEW_DB);
ChangeBundle b2 =
new ChangeBundle(
c, messages(), patchSets(ps2), approvals(), comments(), reviewers(), REVIEW_DB);
assertDiffs(
b1, b2, "description differs for PatchSet.Id " + ps1.getId() + ":" + " { abc } != {abc}");
// Whitespace in ReviewDb description is ignored.
b1 =
new ChangeBundle(
c, messages(), patchSets(ps1), approvals(), comments(), reviewers(), REVIEW_DB);
b2 =
new ChangeBundle(
c, messages(), patchSets(ps2), approvals(), comments(), reviewers(), NOTE_DB);
assertNoDiffs(b1, b2);
assertNoDiffs(b2, b1);
// Must match except for the leading/trailing whitespace.
PatchSet ps3 = clone(ps1);
ps3.setDescription("cba");
b1 =
new ChangeBundle(
c, messages(), patchSets(ps1), approvals(), comments(), reviewers(), REVIEW_DB);
b2 =
new ChangeBundle(
c, messages(), patchSets(ps3), approvals(), comments(), reviewers(), NOTE_DB);
assertDiffs(
b1, b2, "description differs for PatchSet.Id " + ps1.getId() + ":" + " { abc } != {cba}");
}
@Test
public void diffPatchSetApprovalKeySets() throws Exception {
Change c = TestChanges.newChange(project, accountId);