use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ChangeBundleTest method diffPatchSetsIgnoresLeadingAndTrailingWhitespaceInReviewDbDescriptions.
@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}");
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class AbstractSubmitByRebase method repairChangeStateAfterFailure.
@Test
public void repairChangeStateAfterFailure() throws Exception {
// In NoteDb-only mode, repo and meta updates are atomic (at least in InMemoryRepository).
assume().that(notesMigration.disableChangeReviewDb()).isFalse();
RevCommit initialHead = getRemoteHead();
PushOneCommit.Result change = createChange("Change 1", "a.txt", "content");
submit(change.getChangeId());
RevCommit headAfterFirstSubmit = getRemoteHead();
testRepo.reset(initialHead);
PushOneCommit.Result change2 = createChange("Change 2", "b.txt", "other content");
Change.Id id2 = change2.getChange().getId();
SubmitInput failAfterRefUpdates = new TestSubmitInput(new SubmitInput(), true);
submit(change2.getChangeId(), failAfterRefUpdates, ResourceConflictException.class, "Failing after ref updates");
RevCommit headAfterFailedSubmit = getRemoteHead();
// Bad: ref advanced but change wasn't updated.
PatchSet.Id psId1 = new PatchSet.Id(id2, 1);
PatchSet.Id psId2 = new PatchSet.Id(id2, 2);
ChangeInfo info = gApi.changes().id(id2.get()).get();
assertThat(info.status).isEqualTo(ChangeStatus.NEW);
assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(1);
assertThat(getPatchSet(psId2)).isNull();
ObjectId rev2;
try (Repository repo = repoManager.openRepository(project);
RevWalk rw = new RevWalk(repo)) {
ObjectId rev1 = repo.exactRef(psId1.toRefName()).getObjectId();
assertThat(rev1).isNotNull();
rev2 = repo.exactRef(psId2.toRefName()).getObjectId();
assertThat(rev2).isNotNull();
assertThat(rev2).isNotEqualTo(rev1);
assertThat(rw.parseCommit(rev2).getParent(0)).isEqualTo(headAfterFirstSubmit);
assertThat(repo.exactRef("refs/heads/master").getObjectId()).isEqualTo(rev2);
}
submit(change2.getChangeId());
RevCommit headAfterSecondSubmit = getRemoteHead();
assertThat(headAfterSecondSubmit).isEqualTo(headAfterFailedSubmit);
// Change status and patch set entities were updated, and branch tip stayed
// the same.
info = gApi.changes().id(id2.get()).get();
assertThat(info.status).isEqualTo(ChangeStatus.MERGED);
assertThat(info.revisions.get(info.currentRevision)._number).isEqualTo(2);
PatchSet ps2 = getPatchSet(psId2);
assertThat(ps2).isNotNull();
assertThat(ps2.getRevision().get()).isEqualTo(rev2.name());
assertThat(Iterables.getLast(info.messages).message).isEqualTo("Change has been successfully rebased and submitted as " + rev2.name() + " by Administrator");
try (Repository repo = repoManager.openRepository(project)) {
assertThat(repo.exactRef("refs/heads/master").getObjectId()).isEqualTo(rev2);
}
assertRefUpdatedEvents(initialHead, headAfterFirstSubmit);
assertChangeMergedEvents(change.getChangeId(), headAfterFirstSubmit.name(), change2.getChangeId(), headAfterSecondSubmit.name());
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ConsistencyCheckerIT method insertMissingPatchSet.
private PatchSet insertMissingPatchSet(ChangeControl ctl, String rev) throws Exception {
// Don't use BatchUpdate since we're manually updating the meta ref rather
// than using ChangeUpdate.
String subject = "Subject for missing commit";
Change c = new Change(ctl.getChange());
PatchSet.Id psId = nextPatchSetId(ctl);
c.setCurrentPatchSet(psId, subject, c.getOriginalSubject());
PatchSet ps = newPatchSet(psId, rev, adminId);
if (PrimaryStorage.of(c) == PrimaryStorage.REVIEW_DB) {
db.patchSets().insert(singleton(ps));
db.changes().update(singleton(c));
}
addNoteDbCommit(c.getId(), "Update patch set " + psId.get() + "\n" + "\n" + "Patch-set: " + psId.get() + "\n" + "Commit: " + rev + "\n" + "Subject: " + subject + "\n");
indexer.index(db, c.getProject(), c.getId());
return ps;
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class ConsistencyCheckerIT method expectedMergedCommitIsDanglingPatchSetNewerThanCurrent.
@Test
public void expectedMergedCommitIsDanglingPatchSetNewerThanCurrent() throws Exception {
ChangeControl ctl = insertChange();
PatchSet ps1 = psUtil.current(db, ctl.getNotes());
// Create dangling ref with no patch set.
PatchSet.Id psId2 = new PatchSet.Id(ctl.getId(), 2);
RevCommit commit2 = patchSetCommit(psId2);
String rev2 = commit2.name();
testRepo.branch(psId2.toRefName()).update(commit2);
testRepo.branch(ctl.getChange().getDest().get()).update(testRepo.getRevWalk().parseCommit(ObjectId.fromString(rev2)));
FixInput fix = new FixInput();
fix.expectMergedAs = rev2;
assertProblems(ctl, fix, problem("No patch set found for merged commit " + rev2, FIXED, "Marked change as merged"), problem("Expected merge commit " + rev2 + " corresponds to patch set 2," + " not the current patch set 1", FIXED, "Inserted as patch set 2"));
ctl = reload(ctl);
assertThat(ctl.getChange().currentPatchSetId()).isEqualTo(psId2);
assertThat(ctl.getChange().getStatus()).isEqualTo(Change.Status.MERGED);
assertThat(psUtil.byChangeAsMap(db, ctl.getNotes()).keySet()).containsExactly(ps1.getId(), psId2);
assertThat(psUtil.get(db, ctl.getNotes(), psId2).getRevision().get()).isEqualTo(rev2);
}
use of com.google.gerrit.reviewdb.client.PatchSet in project gerrit by GerritCodeReview.
the class CatServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse rsp) throws IOException {
String keyStr = req.getPathInfo();
// We shouldn't have to do this extra decode pass, but somehow we
// are now receiving our "^1" suffix as "%5E1", which confuses us
// downstream. Other times we get our embedded "," as "%2C", which
// is equally bad. And yet when these happen a "%2F" is left as-is,
// rather than escaped as "%252F", which makes me feel really really
// uncomfortable with a blind decode right here.
//
keyStr = Url.decode(keyStr);
if (!keyStr.startsWith("/")) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
keyStr = keyStr.substring(1);
final Patch.Key patchKey;
final int side;
{
final int c = keyStr.lastIndexOf('^');
if (c == 0) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
if (c < 0) {
side = 0;
} else {
try {
side = Integer.parseInt(keyStr.substring(c + 1));
keyStr = keyStr.substring(0, c);
} catch (NumberFormatException e) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
try {
patchKey = Patch.Key.parse(keyStr);
} catch (NumberFormatException e) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
}
final Change.Id changeId = patchKey.getParentKey().getParentKey();
String revision;
try {
final ReviewDb db = requestDb.get();
final ChangeControl control = changeControl.validateFor(db, changeId, userProvider.get());
if (patchKey.getParentKey().get() == 0) {
// change edit
try {
Optional<ChangeEdit> edit = changeEditUtil.byChange(control.getChange());
if (edit.isPresent()) {
revision = ObjectId.toString(edit.get().getEditCommit());
} else {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
} catch (AuthException e) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
} else {
PatchSet patchSet = psUtil.get(db, control.getNotes(), patchKey.getParentKey());
if (patchSet == null) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
revision = patchSet.getRevision().get();
}
} catch (NoSuchChangeException e) {
rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
} catch (OrmException e) {
getServletContext().log("Cannot query database", e);
rsp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
String path = patchKey.getFileName();
String restUrl = String.format("%s/changes/%d/revisions/%s/files/%s/download?parent=%d", req.getContextPath(), changeId.get(), revision, Url.encode(path), side);
rsp.sendRedirect(restUrl);
}
Aggregations