Line data Source code
1 : // Copyright (C) 2020 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.submit; 16 : 17 : import com.google.gerrit.entities.BranchNameKey; 18 : import com.google.gerrit.entities.SubmoduleSubscription; 19 : import com.google.gerrit.server.git.CodeReviewCommit; 20 : import com.google.gerrit.server.update.RepoContext; 21 : import com.google.gerrit.server.update.RepoOnlyOp; 22 : import java.util.Collection; 23 : import java.util.Optional; 24 : 25 : /** Only used for branches without code review changes */ 26 : public class GitlinkOp implements RepoOnlyOp { 27 : 28 : static class Factory { 29 : private SubmoduleCommits submoduleCommits; 30 : private SubscriptionGraph subscriptionGraph; 31 : 32 68 : Factory(SubmoduleCommits submoduleCommits, SubscriptionGraph subscriptionGraph) { 33 68 : this.submoduleCommits = submoduleCommits; 34 68 : this.subscriptionGraph = subscriptionGraph; 35 68 : } 36 : 37 : GitlinkOp create(BranchNameKey branch) { 38 2 : return new GitlinkOp(branch, submoduleCommits, subscriptionGraph.getSubscriptions(branch)); 39 : } 40 : } 41 : 42 : private final BranchNameKey branch; 43 : private final SubmoduleCommits commitHelper; 44 : private final Collection<SubmoduleSubscription> branchTargets; 45 : 46 : GitlinkOp( 47 : BranchNameKey branch, 48 : SubmoduleCommits commitHelper, 49 2 : Collection<SubmoduleSubscription> branchTargets) { 50 2 : this.branch = branch; 51 2 : this.commitHelper = commitHelper; 52 2 : this.branchTargets = branchTargets; 53 2 : } 54 : 55 : @Override 56 : public void updateRepo(RepoContext ctx) throws Exception { 57 2 : Optional<CodeReviewCommit> commit = commitHelper.composeGitlinksCommit(branch, branchTargets); 58 2 : if (commit.isPresent()) { 59 2 : CodeReviewCommit c = commit.get(); 60 2 : ctx.addRefUpdate(c.getParent(0), c, branch.branch()); 61 2 : commitHelper.addBranchTip(branch, c); 62 : } 63 2 : } 64 : }