Refactor MergeOp: implement each submit strategy in an own class

This is the second step in the MergeOp refactoring. With this change
an abstraction for a submit strategy is introduced. There is a new
abstract base class that each submit strategy has to extend. By having
polymorphism for the submit type the coding for the different submit
strategies gets seperated. This makes it much easier to add a new
submit strategy because only a clearly defined interface has to be
implemented.

Change-Id: I5afe9fdc3e4c5a796cc2be715194effed9e34ddf
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2012-09-25 14:41:36 +02:00
parent 2b3bafa470
commit 7e136c540a
7 changed files with 822 additions and 391 deletions

View File

@@ -0,0 +1,54 @@
// Copyright (C) 2012 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.git;
import static com.google.gerrit.server.git.MergeUtil.getFirstFastForward;
import static com.google.gerrit.server.git.MergeUtil.markCleanMerges;
import static com.google.gerrit.server.git.MergeUtil.mergeOneCommit;
import static com.google.gerrit.server.git.MergeUtil.reduceToMinimalMerge;
import com.google.gerrit.reviewdb.client.PatchSetApproval;
import java.util.List;
public class MergeIfNecessary extends SubmitStrategy {
MergeIfNecessary(final SubmitStrategy.Arguments args) {
super(args);
}
@Override
protected CodeReviewCommit _run(final CodeReviewCommit mergeTip,
final List<CodeReviewCommit> toMerge) throws MergeException {
reduceToMinimalMerge(args.mergeSorter, toMerge);
CodeReviewCommit newMergeTip =
getFirstFastForward(mergeTip, args.rw, toMerge);
// For every other commit do a pair-wise merge.
while (!toMerge.isEmpty()) {
newMergeTip =
mergeOneCommit(args.db, args.identifiedUserFactory, args.myIdent,
args.repo, args.rw, args.inserter, args.useContentMerge,
args.destBranch, mergeTip, toMerge.remove(0));
}
final PatchSetApproval submitApproval =
markCleanMerges(args.db, args.rw, args.canMergeFlag, newMergeTip,
args.alreadyAccepted);
setRefLogIdent(submitApproval);
return newMergeTip;
}
}