use of org.eclipse.jgit.lib.CommitBuilder in project gerrit by GerritCodeReview.
the class PublicKeyStoreTest method newCommitBuilder.
private CommitBuilder newCommitBuilder() {
CommitBuilder cb = new CommitBuilder();
PersonIdent ident = new PersonIdent("A U Thor", "author@example.com");
cb.setAuthor(ident);
cb.setCommitter(ident);
return cb;
}
use of org.eclipse.jgit.lib.CommitBuilder in project gerrit by GerritCodeReview.
the class CreateChange method newCommit.
private static RevCommit newCommit(ObjectInserter oi, RevWalk rw, PersonIdent authorIdent, RevCommit mergeTip, String commitMessage) throws IOException {
CommitBuilder commit = new CommitBuilder();
if (mergeTip == null) {
commit.setTreeId(emptyTreeId(oi));
} else {
commit.setTreeId(mergeTip.getTree().getId());
commit.setParentId(mergeTip);
}
commit.setAuthor(authorIdent);
commit.setCommitter(authorIdent);
commit.setMessage(commitMessage);
return rw.parseCommit(insert(oi, commit));
}
use of org.eclipse.jgit.lib.CommitBuilder in project gerrit by GerritCodeReview.
the class ChangeDraftUpdate method applyImpl.
@Override
protected CommitBuilder applyImpl(RevWalk rw, ObjectInserter ins, ObjectId curr) throws OrmException, IOException {
CommitBuilder cb = new CommitBuilder();
cb.setMessage("Update draft comments");
try {
return storeCommentsInNotes(rw, ins, curr, cb);
} catch (ConfigInvalidException e) {
throw new OrmException(e);
}
}
use of org.eclipse.jgit.lib.CommitBuilder in project gerrit by GerritCodeReview.
the class Revert method revert.
private Change.Id revert(BatchUpdate.Factory updateFactory, ChangeControl ctl, String message) throws OrmException, IOException, RestApiException, UpdateException {
Change.Id changeIdToRevert = ctl.getChange().getId();
PatchSet.Id patchSetId = ctl.getChange().currentPatchSetId();
PatchSet patch = psUtil.get(db.get(), ctl.getNotes(), patchSetId);
if (patch == null) {
throw new ResourceNotFoundException(changeIdToRevert.toString());
}
Project.NameKey project = ctl.getProject().getNameKey();
CurrentUser user = ctl.getUser();
try (Repository git = repoManager.openRepository(project);
ObjectInserter oi = git.newObjectInserter();
ObjectReader reader = oi.newReader();
RevWalk revWalk = new RevWalk(reader)) {
RevCommit commitToRevert = revWalk.parseCommit(ObjectId.fromString(patch.getRevision().get()));
if (commitToRevert.getParentCount() == 0) {
throw new ResourceConflictException("Cannot revert initial commit");
}
Timestamp now = TimeUtil.nowTs();
PersonIdent committerIdent = new PersonIdent(serverIdent, now);
PersonIdent authorIdent = user.asIdentifiedUser().newCommitterIdent(now, committerIdent.getTimeZone());
RevCommit parentToCommitToRevert = commitToRevert.getParent(0);
revWalk.parseHeaders(parentToCommitToRevert);
CommitBuilder revertCommitBuilder = new CommitBuilder();
revertCommitBuilder.addParentId(commitToRevert);
revertCommitBuilder.setTreeId(parentToCommitToRevert.getTree());
revertCommitBuilder.setAuthor(authorIdent);
revertCommitBuilder.setCommitter(authorIdent);
Change changeToRevert = ctl.getChange();
if (message == null) {
message = MessageFormat.format(ChangeMessages.get().revertChangeDefaultMessage, changeToRevert.getSubject(), patch.getRevision().get());
}
ObjectId computedChangeId = ChangeIdUtil.computeChangeId(parentToCommitToRevert.getTree(), commitToRevert, authorIdent, committerIdent, message);
revertCommitBuilder.setMessage(ChangeIdUtil.insertId(message, computedChangeId, true));
Change.Id changeId = new Change.Id(seq.nextChangeId());
ObjectId id = oi.insert(revertCommitBuilder);
RevCommit revertCommit = revWalk.parseCommit(id);
ChangeInserter ins = changeInserterFactory.create(changeId, revertCommit, ctl.getChange().getDest().get()).setTopic(changeToRevert.getTopic());
ins.setMessage("Uploaded patch set 1.");
Set<Account.Id> reviewers = new HashSet<>();
reviewers.add(changeToRevert.getOwner());
reviewers.addAll(approvalsUtil.getReviewers(db.get(), ctl.getNotes()).all());
reviewers.remove(user.getAccountId());
ins.setReviewers(reviewers);
try (BatchUpdate bu = updateFactory.create(db.get(), project, user, now)) {
bu.setRepository(git, revWalk, oi);
bu.insertChange(ins);
bu.addOp(changeId, new NotifyOp(ctl.getChange(), ins));
bu.addOp(changeToRevert.getId(), new PostRevertedMessageOp(computedChangeId));
bu.execute();
}
return changeId;
} catch (RepositoryNotFoundException e) {
throw new ResourceNotFoundException(changeIdToRevert.toString(), e);
}
}
use of org.eclipse.jgit.lib.CommitBuilder in project gerrit by GerritCodeReview.
the class Schema_146 method createInitialEmptyCommit.
private ObjectId createInitialEmptyCommit(ObjectInserter oi, ObjectId emptyTree, Timestamp registrationDate) throws IOException {
PersonIdent ident = new PersonIdent(serverIdent, registrationDate);
CommitBuilder cb = new CommitBuilder();
cb.setTreeId(emptyTree);
cb.setCommitter(ident);
cb.setAuthor(ident);
cb.setMessage(CREATE_ACCOUNT_MSG);
return oi.insert(cb);
}
Aggregations