use of com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo in project gerrit by GerritCodeReview.
the class MergeOp method getSubmitStrategies.
private List<SubmitStrategy> getSubmitStrategies(Map<BranchNameKey, BranchBatch> toSubmit, UpdateOrderCalculator updateOrderCalculator, SubmoduleCommits submoduleCommits, SubscriptionGraph subscriptionGraph, boolean dryrun) throws IntegrationConflictException, NoSuchProjectException, IOException {
List<SubmitStrategy> strategies = new ArrayList<>();
Set<BranchNameKey> allBranches = updateOrderCalculator.getBranchesInOrder();
Set<CodeReviewCommit> allCommits = toSubmit.values().stream().map(BranchBatch::commits).flatMap(Set::stream).collect(toSet());
for (BranchNameKey branch : allBranches) {
OpenRepo or = orm.getRepo(branch.project());
if (toSubmit.containsKey(branch)) {
BranchBatch submitting = toSubmit.get(branch);
logger.atFine().log("adding ops for branch batch %s", submitting);
OpenBranch ob = or.getBranch(branch);
requireNonNull(submitting.submitType(), String.format("null submit type for %s; expected to previously fail fast", submitting));
Set<CodeReviewCommit> commitsToSubmit = submitting.commits();
ob.mergeTip = new MergeTip(ob.oldTip, commitsToSubmit);
SubmitStrategy strategy = submitStrategyFactory.create(submitting.submitType(), or.rw, or.canMergeFlag, getAlreadyAccepted(or, ob.oldTip), allCommits, branch, caller, ob.mergeTip, commitStatus, submissionId, submitInput, submoduleCommits, subscriptionGraph, dryrun);
strategies.add(strategy);
strategy.addOps(or.getUpdate(), commitsToSubmit);
}
}
return strategies;
}
use of com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo 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.submit.MergeOpRepoManager.OpenRepo in project gerrit by GerritCodeReview.
the class SubmoduleOp method updateSuperProjects.
public void updateSuperProjects(boolean dryrun) throws RestApiException {
ImmutableSet<Project.NameKey> projects = updateOrderCalculator.getProjectsInOrder();
if (projects == null) {
return;
}
if (dryrun) {
// On dryrun, the refs hasn't been updated.
// force the new tips on submoduleCommits
forceRefTips(updatedBranches, submoduleCommits);
}
LinkedHashSet<Project.NameKey> superProjects = new LinkedHashSet<>();
try {
GitlinkOp.Factory gitlinkOpFactory = new GitlinkOp.Factory(submoduleCommits, subscriptionGraph);
for (Project.NameKey project : projects) {
// only need superprojects
if (subscriptionGraph.isAffectedSuperProject(project)) {
superProjects.add(project);
// get a new BatchUpdate for the super project
OpenRepo or = orm.getRepo(project);
for (BranchNameKey branch : subscriptionGraph.getAffectedSuperBranches(project)) {
or.getUpdate().addRepoOnlyOp(gitlinkOpFactory.create(branch));
}
}
}
BatchUpdate.execute(orm.batchUpdates(superProjects), ImmutableList.of(), dryrun);
} catch (UpdateException | IOException | NoSuchProjectException e) {
throw new StorageException("Cannot update gitlinks", e);
}
}
use of com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo 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.submit.MergeOpRepoManager.OpenRepo in project gerrit by GerritCodeReview.
the class LocalMergeSuperSetComputation method getRepo.
private OpenRepo getRepo(MergeOpRepoManager orm, Project.NameKey project) throws IOException {
try {
OpenRepo or = orm.getRepo(project);
checkState(or.rw.hasRevSort(RevSort.TOPO));
return or;
} catch (NoSuchProjectException e) {
throw new IOException(e);
}
}
Aggregations