LCOV - code coverage report
Current view: top level - server/submit - MergeAlways.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 14 14 100.0 %
Date: 2022-11-19 15:00:39 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2012 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.common.collect.ImmutableList;
      18             : import com.google.gerrit.server.git.CodeReviewCommit;
      19             : import java.util.Collection;
      20             : import java.util.List;
      21             : 
      22             : public class MergeAlways extends SubmitStrategy {
      23             :   MergeAlways(SubmitStrategy.Arguments args) {
      24           5 :     super(args);
      25           5 :   }
      26             : 
      27             :   @Override
      28             :   public ImmutableList<SubmitStrategyOp> buildOps(Collection<CodeReviewCommit> toMerge) {
      29           5 :     List<CodeReviewCommit> sorted = args.mergeUtil.reduceToMinimalMerge(args.mergeSorter, toMerge);
      30           5 :     ImmutableList.Builder<SubmitStrategyOp> ops =
      31           5 :         ImmutableList.builderWithExpectedSize(sorted.size());
      32           5 :     if (args.mergeTip.getInitialTip() == null && !sorted.isEmpty()) {
      33             :       // The branch is unborn. Take a fast-forward resolution to
      34             :       // create the branch.
      35           2 :       CodeReviewCommit first = sorted.remove(0);
      36           2 :       ops.add(new FastForwardOp(args, first));
      37             :     }
      38           5 :     while (!sorted.isEmpty()) {
      39           5 :       CodeReviewCommit n = sorted.remove(0);
      40           5 :       ops.add(new MergeOneOp(args, n));
      41           5 :     }
      42           5 :     return ops.build();
      43             :   }
      44             : 
      45             :   static boolean dryRun(
      46             :       SubmitDryRun.Arguments args, CodeReviewCommit mergeTip, CodeReviewCommit toMerge) {
      47           2 :     return args.mergeUtil.canMerge(args.mergeSorter, args.repo, mergeTip, toMerge);
      48             :   }
      49             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750