use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class GetContent method getMessage.
private String getMessage(ChangeNotes notes) throws IOException {
Change.Id changeId = notes.getChangeId();
PatchSet ps = psUtil.current(notes);
if (ps == null) {
throw new NoSuchChangeException(changeId);
}
try (Repository git = gitManager.openRepository(notes.getProjectName());
RevWalk revWalk = new RevWalk(git)) {
RevCommit commit = revWalk.parseCommit(ps.commitId());
return commit.getFullMessage();
} catch (RepositoryNotFoundException e) {
throw new NoSuchChangeException(changeId, e);
}
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class GetRelated method getRelated.
public ImmutableList<RelatedChangeAndCommitInfo> getRelated(RevisionResource rsrc) throws IOException, PermissionBackendException {
boolean isEdit = rsrc.getEdit().isPresent();
PatchSet basePs = isEdit ? rsrc.getEdit().get().getBasePatchSet() : rsrc.getPatchSet();
logger.atFine().log("isEdit = %s, basePs = %s", isEdit, basePs);
List<RelatedChangesSorter.PatchSetData> sortedResult = getRelatedChangesUtil.getRelated(changeDataFactory.create(rsrc.getNotes()), basePs);
List<RelatedChangeAndCommitInfo> result = new ArrayList<>(sortedResult.size());
for (RelatedChangesSorter.PatchSetData d : sortedResult) {
PatchSet ps = d.patchSet();
RevCommit commit;
if (isEdit && ps.id().equals(basePs.id())) {
// Replace base of an edit with the edit itself.
ps = rsrc.getPatchSet();
commit = rsrc.getEdit().get().getEditCommit();
logger.atFine().log("Replaced base of edit (patch set %s, commit %s) with edit (patch set %s, commit %s)", d.patchSet().id(), d.commit(), ps.id(), commit);
} else {
commit = d.commit();
}
result.add(newChangeAndCommit(rsrc.getProject(), d.data().change(), ps, commit));
}
if (result.size() == 1) {
RelatedChangeAndCommitInfo r = result.get(0);
if (r.commit != null && r.commit.commit.equals(rsrc.getPatchSet().commitId().name())) {
return ImmutableList.of();
}
}
return ImmutableList.copyOf(result);
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class ConsistencyCheckerIT method insertMissingPatchSet.
private PatchSet insertMissingPatchSet(ChangeNotes notes, 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(notes.getChange());
PatchSet.Id psId = nextPatchSetId(notes);
c.setCurrentPatchSet(psId, subject, c.getOriginalSubject());
PatchSet ps = newPatchSet(psId, rev, adminId);
addNoteDbCommit(c.getId(), "Update patch set " + psId.get() + "\n" + "\n" + "Patch-set: " + psId.get() + "\n" + "Commit: " + rev + "\n" + "Subject: " + subject + "\n");
return ps;
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class ConsistencyCheckerIT method expectedMergedCommitIsDanglingPatchSetNewerThanCurrent.
@Test
public void expectedMergedCommitIsDanglingPatchSetNewerThanCurrent() throws Exception {
ChangeNotes notes = insertChange();
PatchSet ps1 = psUtil.current(notes);
// Create dangling ref with no patch set.
PatchSet.Id psId2 = PatchSet.id(notes.getChangeId(), 2);
RevCommit commit2 = patchSetCommit(psId2);
serverSideTestRepo.branch(psId2.toRefName()).update(commit2);
serverSideTestRepo.branch(notes.getChange().getDest().branch()).update(commit2);
FixInput fix = new FixInput();
fix.expectMergedAs = commit2.name();
assertProblems(notes, fix, problem("No patch set found for merged commit " + commit2.name(), FIXED, "Marked change as merged"), problem("Expected merge commit " + commit2.name() + " corresponds to patch set 2," + " not the current patch set 1", FIXED, "Inserted as patch set 2"));
notes = reload(notes);
assertThat(notes.getChange().currentPatchSetId()).isEqualTo(psId2);
assertThat(notes.getChange().isMerged()).isTrue();
assertThat(psUtil.byChangeAsMap(notes).keySet()).containsExactly(ps1.id(), psId2);
assertThat(psUtil.get(notes, psId2).commitId()).isEqualTo(commit2);
}
use of com.google.gerrit.entities.PatchSet in project gerrit by GerritCodeReview.
the class CommentPorterTest method commentsAreNotDroppedWhenRetrievingCommitSha1sHasUnexpectedError.
@Test
public void commentsAreNotDroppedWhenRetrievingCommitSha1sHasUnexpectedError() {
Project.NameKey project = Project.nameKey("myProject");
Change.Id changeId = Change.id(1);
Change change = createChange(project, changeId);
PatchSet patchset1 = createPatchset(PatchSet.id(changeId, 1));
PatchSet patchset2 = createPatchset(PatchSet.id(changeId, 2));
ChangeNotes changeNotes = mockChangeNotes(project, change, patchset1, patchset2);
CommentPorter commentPorter = new CommentPorter(diffOperations, commentsUtil, metrics);
HumanComment comment = createComment(patchset1.id(), "myFile");
when(commentsUtil.determineCommitId(any(), any(), anyShort())).thenThrow(IllegalStateException.class);
ImmutableList<HumanComment> portedComments = commentPorter.portComments(changeNotes, patchset2, ImmutableList.of(comment), ImmutableList.of());
assertThat(portedComments).isNotEmpty();
}
Aggregations