use of com.google.gerrit.server.git.CodeReviewCommit in project gerrit by GerritCodeReview.
the class SubmitDryRun method run.
public boolean run(@Nullable CurrentUser caller, SubmitType submitType, Repository repo, CodeReviewRevWalk rw, BranchNameKey destBranch, ObjectId tip, ObjectId toMerge, Set<RevCommit> alreadyAccepted) throws NoSuchProjectException, IOException {
CodeReviewCommit tipCommit = rw.parseCommit(tip);
CodeReviewCommit toMergeCommit = rw.parseCommit(toMerge);
RevFlag canMerge = rw.newFlag("CAN_MERGE");
toMergeCommit.add(canMerge);
Arguments args = new Arguments(repo, rw, mergeUtilFactory.create(getProject(destBranch)), new MergeSorter(caller, rw, alreadyAccepted, canMerge, queryProvider, ImmutableSet.of(toMergeCommit)));
switch(submitType) {
case CHERRY_PICK:
return CherryPick.dryRun(args, tipCommit, toMergeCommit);
case FAST_FORWARD_ONLY:
return FastForwardOnly.dryRun(args, tipCommit, toMergeCommit);
case MERGE_ALWAYS:
return MergeAlways.dryRun(args, tipCommit, toMergeCommit);
case MERGE_IF_NECESSARY:
return MergeIfNecessary.dryRun(args, tipCommit, toMergeCommit);
case REBASE_IF_NECESSARY:
return RebaseIfNecessary.dryRun(args, repo, tipCommit, toMergeCommit);
case REBASE_ALWAYS:
return RebaseAlways.dryRun(args, repo, tipCommit, toMergeCommit);
case INHERIT:
default:
String errorMsg = "No submit strategy for: " + submitType;
logger.atSevere().log("%s", errorMsg);
throw new StorageException(errorMsg);
}
}
use of com.google.gerrit.server.git.CodeReviewCommit in project gerrit by GerritCodeReview.
the class BranchTips method getTip.
/**
* Returns current tip of the branch, taking into account commits created during the submit
* process or submodule updates.
*
* @param branch branch
* @param repo repository to look for the branch if not cached
* @return the current tip. Empty if the branch doesn't exist in the repository
* @throws IOException Cannot access the underlying storage
*/
Optional<CodeReviewCommit> getTip(BranchNameKey branch, OpenRepo repo) throws IOException {
CodeReviewCommit currentCommit;
if (branchTips.containsKey(branch)) {
currentCommit = branchTips.get(branch);
} else {
Ref r = repo.repo.exactRef(branch.branch());
if (r == null) {
return Optional.empty();
}
currentCommit = repo.rw.parseCommit(r.getObjectId());
branchTips.put(branch, currentCommit);
}
return Optional.of(currentCommit);
}
use of com.google.gerrit.server.git.CodeReviewCommit in project gerrit by GerritCodeReview.
the class SubmoduleCommits method amendGitlinksCommit.
/**
* Amend an existing commit with gitlink updates
*/
CodeReviewCommit amendGitlinksCommit(BranchNameKey subscriber, CodeReviewCommit currentCommit, Collection<SubmoduleSubscription> subscriptions) throws IOException, SubmoduleConflictException {
OpenRepo or;
try {
or = orm.getRepo(subscriber.project());
} catch (NoSuchProjectException | IOException e) {
throw new StorageException("Cannot access superproject", e);
}
StringBuilder msgbuf = new StringBuilder();
DirCache dc = readTree(or.rw, currentCommit);
DirCacheEditor ed = dc.editor();
for (SubmoduleSubscription s : sortByPath(subscriptions)) {
updateSubmodule(dc, ed, msgbuf, s);
}
ed.finish();
ObjectId newTreeId = dc.writeTree(or.ins);
// Gitlinks are already updated, just return the commit
if (newTreeId.equals(currentCommit.getTree())) {
return currentCommit;
}
or.rw.parseBody(currentCommit);
CommitBuilder commit = new CommitBuilder();
commit.setTreeId(newTreeId);
commit.setParentIds(currentCommit.getParents());
if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
// TODO(czhen): handle cherrypick footer
commit.setMessage(currentCommit.getFullMessage() + "\n\n* submodules:\n" + msgbuf.toString());
} else {
commit.setMessage(currentCommit.getFullMessage());
}
commit.setAuthor(currentCommit.getAuthorIdent());
commit.setCommitter(myIdent);
ObjectId id = or.ins.insert(commit);
CodeReviewCommit newCommit = or.getCodeReviewRevWalk().parseCommit(id);
newCommit.copyFrom(currentCommit);
return newCommit;
}
use of com.google.gerrit.server.git.CodeReviewCommit in project gerrit by GerritCodeReview.
the class SubmoduleOp method forceRefTips.
private void forceRefTips(Map<BranchNameKey, ReceiveCommand> updatedBranches, SubmoduleCommits submoduleCommits) {
// This is dryrun, all commands succeeded (no need to filter success).
for (Map.Entry<BranchNameKey, ReceiveCommand> updateBranch : updatedBranches.entrySet()) {
try {
ReceiveCommand command = updateBranch.getValue();
if (command.getType() == ReceiveCommand.Type.DELETE) {
continue;
}
BranchNameKey branchNameKey = updateBranch.getKey();
OpenRepo openRepo = orm.getRepo(branchNameKey.project());
CodeReviewCommit fakeTip = openRepo.rw.parseCommit(command.getNewId());
submoduleCommits.addBranchTip(branchNameKey, fakeTip);
} catch (NoSuchProjectException | IOException e) {
throw new StorageException("Cannot find branch tip target in dryrun", e);
}
}
}
use of com.google.gerrit.server.git.CodeReviewCommit in project gerrit by GerritCodeReview.
the class FastForwardOnly method buildOps.
@Override
public ImmutableList<SubmitStrategyOp> buildOps(Collection<CodeReviewCommit> toMerge) {
List<CodeReviewCommit> sorted = args.mergeUtil.reduceToMinimalMerge(args.mergeSorter, toMerge);
Map<BranchNameKey, CodeReviewCommit> branchToCommit = new HashMap<>();
for (CodeReviewCommit codeReviewCommit : sorted) {
BranchNameKey branchNameKey = codeReviewCommit.change().getDest();
CodeReviewCommit otherCommitInBranch = branchToCommit.get(branchNameKey);
if (otherCommitInBranch == null) {
branchToCommit.put(branchNameKey, codeReviewCommit);
} else {
// we found another change with the same destination branch.
codeReviewCommit.setStatusCode(CommitMergeStatus.FAST_FORWARD_INDEPENDENT_CHANGES);
otherCommitInBranch.setStatusCode(CommitMergeStatus.FAST_FORWARD_INDEPENDENT_CHANGES);
return ImmutableList.of();
}
}
ImmutableList.Builder<SubmitStrategyOp> ops = ImmutableList.builderWithExpectedSize(sorted.size());
CodeReviewCommit newTipCommit = args.mergeUtil.getFirstFastForward(args.mergeTip.getInitialTip(), args.rw, sorted);
if (!newTipCommit.equals(args.mergeTip.getInitialTip())) {
ops.add(new FastForwardOp(args, newTipCommit));
} else {
for (CodeReviewCommit c : toMerge) {
ops.add(new NotFastForwardOp(c));
}
}
return ops.build();
}
Aggregations