use of com.google.gerrit.reviewdb.client.RevId in project gerrit by GerritCodeReview.
the class RebaseUtil method findBaseRevision.
/**
* Find the commit onto which a patch set should be rebased.
*
* <p>This is defined as the latest patch set of the change corresponding to this commit's parent,
* or the destination branch tip in the case where the parent's change is merged.
*
* @param patchSet patch set for which the new base commit should be found.
* @param destBranch the destination branch.
* @param git the repository.
* @param rw the RevWalk.
* @return the commit onto which the patch set should be rebased.
* @throws RestApiException if rebase is not possible.
* @throws IOException if accessing the repository fails.
* @throws OrmException if accessing the database fails.
*/
ObjectId findBaseRevision(PatchSet patchSet, Branch.NameKey destBranch, Repository git, RevWalk rw) throws RestApiException, IOException, OrmException {
String baseRev = null;
RevCommit commit = rw.parseCommit(ObjectId.fromString(patchSet.getRevision().get()));
if (commit.getParentCount() > 1) {
throw new UnprocessableEntityException("Cannot rebase a change with multiple parents.");
} else if (commit.getParentCount() == 0) {
throw new UnprocessableEntityException("Cannot rebase a change without any parents (is this the initial commit?).");
}
RevId parentRev = new RevId(commit.getParent(0).name());
CHANGES: for (ChangeData cd : queryProvider.get().byBranchCommit(destBranch, parentRev.get())) {
for (PatchSet depPatchSet : cd.patchSets()) {
if (!depPatchSet.getRevision().equals(parentRev)) {
continue;
}
Change depChange = cd.change();
if (depChange.getStatus() == Status.ABANDONED) {
throw new ResourceConflictException("Cannot rebase a change with an abandoned parent: " + depChange.getKey());
}
if (depChange.getStatus().isOpen()) {
if (depPatchSet.getId().equals(depChange.currentPatchSetId())) {
throw new ResourceConflictException("Change is already based on the latest patch set of the dependent change.");
}
baseRev = cd.currentPatchSet().getRevision().get();
}
break CHANGES;
}
}
if (baseRev == null) {
// We are dependent on a merged PatchSet or have no PatchSet
// dependencies at all.
Ref destRef = git.getRefDatabase().exactRef(destBranch.get());
if (destRef == null) {
throw new UnprocessableEntityException("The destination branch does not exist: " + destBranch.get());
}
baseRev = destRef.getObjectId().getName();
if (baseRev.equals(parentRev.get())) {
throw new ResourceConflictException("Change is already up to date.");
}
}
return ObjectId.fromString(baseRev);
}
use of com.google.gerrit.reviewdb.client.RevId in project gerrit by GerritCodeReview.
the class RevisionNoteMap method parse.
static RevisionNoteMap<ChangeRevisionNote> parse(ChangeNoteUtil noteUtil, Change.Id changeId, ObjectReader reader, NoteMap noteMap, PatchLineComment.Status status) throws ConfigInvalidException, IOException {
Map<RevId, ChangeRevisionNote> result = new HashMap<>();
for (Note note : noteMap) {
ChangeRevisionNote rn = new ChangeRevisionNote(noteUtil, changeId, reader, note.getData(), status);
rn.parse();
result.put(new RevId(note.name()), rn);
}
return new RevisionNoteMap<>(noteMap, ImmutableMap.copyOf(result));
}
use of com.google.gerrit.reviewdb.client.RevId in project gerrit by GerritCodeReview.
the class RevisionNoteMap method parseRobotComments.
static RevisionNoteMap<RobotCommentsRevisionNote> parseRobotComments(ChangeNoteUtil noteUtil, ObjectReader reader, NoteMap noteMap) throws ConfigInvalidException, IOException {
Map<RevId, RobotCommentsRevisionNote> result = new HashMap<>();
for (Note note : noteMap) {
RobotCommentsRevisionNote rn = new RobotCommentsRevisionNote(noteUtil, reader, note.getData());
rn.parse();
result.put(new RevId(note.name()), rn);
}
return new RevisionNoteMap<>(noteMap, ImmutableMap.copyOf(result));
}
use of com.google.gerrit.reviewdb.client.RevId in project gerrit by GerritCodeReview.
the class DeleteCommentRewriter method rewriteCommit.
/**
* Rewrites one commit.
*
* @param originalCommit the original commit to be rewritten.
* @param parentCommit the parent of the new commit.
* @param inserter the {@code ObjectInserter} for the rewrite process.
* @param reader the {@code ObjectReader} for the rewrite process.
* @param putInComments the comments put in by this commit.
* @param deletedComments the comments deleted by this commit.
* @return the {@code objectId} of the new commit.
* @throws IOException
* @throws ConfigInvalidException
*/
private ObjectId rewriteCommit(RevCommit originalCommit, RevCommit parentCommit, ObjectInserter inserter, ObjectReader reader, List<Comment> putInComments, List<Comment> deletedComments) throws IOException, ConfigInvalidException {
RevisionNoteMap<ChangeRevisionNote> revNotesMap = RevisionNoteMap.parse(noteUtil, changeId, reader, NoteMap.read(reader, parentCommit), PUBLISHED);
RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(revNotesMap);
for (Comment c : putInComments) {
cache.get(new RevId(c.revId)).putComment(c);
}
for (Comment c : deletedComments) {
cache.get(new RevId(c.revId)).deleteComment(c.key);
}
Map<RevId, RevisionNoteBuilder> builders = cache.getBuilders();
for (Map.Entry<RevId, RevisionNoteBuilder> entry : builders.entrySet()) {
ObjectId objectId = ObjectId.fromString(entry.getKey().get());
byte[] data = entry.getValue().build(noteUtil, noteUtil.getWriteJson());
if (data.length == 0) {
revNotesMap.noteMap.remove(objectId);
} else {
revNotesMap.noteMap.set(objectId, inserter.insert(OBJ_BLOB, data));
}
}
CommitBuilder cb = new CommitBuilder();
cb.setParentId(parentCommit);
cb.setTreeId(revNotesMap.noteMap.writeTree(inserter));
cb.setMessage(originalCommit.getFullMessage());
cb.setCommitter(originalCommit.getCommitterIdent());
cb.setAuthor(originalCommit.getAuthorIdent());
cb.setEncoding(originalCommit.getEncoding());
return inserter.insert(cb);
}
use of com.google.gerrit.reviewdb.client.RevId in project gerrit by GerritCodeReview.
the class ChangeNotesTest method tagInlineCommenrts.
@Test
public void tagInlineCommenrts() throws Exception {
String tag = "jenkins";
Change c = newChange();
RevCommit commit = tr.commit().message("PS2").create();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putComment(Status.PUBLISHED, newComment(c.currentPatchSetId(), "a.txt", "uuid1", new CommentRange(1, 2, 3, 4), 1, changeOwner, null, TimeUtil.nowTs(), "Comment", (short) 1, commit.name(), false));
update.setTag(tag);
update.commit();
ChangeNotes notes = newNotes(c);
ImmutableListMultimap<RevId, Comment> comments = notes.getComments();
assertThat(comments).hasSize(1);
assertThat(comments.entries().asList().get(0).getValue().tag).isEqualTo(tag);
}
Aggregations