use of com.google.gerrit.entities.BranchNameKey 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.entities.BranchNameKey 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.entities.BranchNameKey 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.entities.BranchNameKey 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();
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class LocalMergeSuperSetComputation method completeWithoutTopic.
@Override
public ChangeSet completeWithoutTopic(MergeOpRepoManager orm, ChangeSet changeSet, CurrentUser user) throws IOException {
Collection<ChangeData> visibleChanges = new ArrayList<>();
Collection<ChangeData> nonVisibleChanges = new ArrayList<>();
// For each target branch we run a separate rev walk to find open changes
// reachable from changes already in the merge super set.
ImmutableSet<BranchNameKey> branches = byBranch(Iterables.concat(changeSet.changes(), changeSet.nonVisibleChanges())).keySet();
ImmutableListMultimap<BranchNameKey, ChangeData> visibleChangesPerBranch = byBranch(changeSet.changes());
ImmutableListMultimap<BranchNameKey, ChangeData> nonVisibleChangesPerBranch = byBranch(changeSet.nonVisibleChanges());
for (BranchNameKey branchNameKey : branches) {
OpenRepo or = getRepo(orm, branchNameKey.project());
List<RevCommit> visibleCommits = new ArrayList<>();
List<RevCommit> nonVisibleCommits = new ArrayList<>();
for (ChangeData cd : visibleChangesPerBranch.get(branchNameKey)) {
if (submitType(cd) == SubmitType.CHERRY_PICK) {
visibleChanges.add(cd);
} else {
visibleCommits.add(or.rw.parseCommit(cd.currentPatchSet().commitId()));
}
}
for (ChangeData cd : nonVisibleChangesPerBranch.get(branchNameKey)) {
if (submitType(cd) == SubmitType.CHERRY_PICK) {
nonVisibleChanges.add(cd);
} else {
nonVisibleCommits.add(or.rw.parseCommit(cd.currentPatchSet().commitId()));
}
}
Set<String> visibleHashes = walkChangesByHashes(visibleCommits, Collections.emptySet(), or, branchNameKey);
Set<String> nonVisibleHashes = walkChangesByHashes(nonVisibleCommits, visibleHashes, or, branchNameKey);
ChangeSet partialSet = byCommitsOnBranchNotMerged(or, branchNameKey, visibleHashes, nonVisibleHashes, user);
Iterables.addAll(visibleChanges, partialSet.changes());
Iterables.addAll(nonVisibleChanges, partialSet.nonVisibleChanges());
}
return new ChangeSet(visibleChanges, nonVisibleChanges);
}
Aggregations