Add experimental support for automatic conflict handling

Use new content merge functionality in JGit for automatic
resolution of conflicts within a file.

Change-Id: Ifae8a94709fb60f13e4c79fb6bb77a214ef5f0b7
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Dmitry Fink
2010-09-29 23:44:22 -07:00
committed by Shawn O. Pearce
parent 35d753c8f7
commit 876953ea4d
10 changed files with 84 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ SYNOPSIS
[\--permissions-only] \
[\--description <DESC>] \
[\--submit-type <TYPE>] \
[\--use-content-merge] \
[\--use-contributor-agreements] \
[\--use-signed-off-by]
@@ -95,6 +96,13 @@ Description values containing spaces should be quoted in single quotes
Defaults to MERGE_IF_NECESSARY. For more details see
link:project-setup.html#submit_type[Change Submit Actions].
\--use-content-merge::
If enabled, Gerrit will try to perform a 3-way merge of text
file content when a file has been modified by both the
destination branch and the change being submitted. This
option only takes effect if submit type is not
FAST_FORWARD_ONLY. Disabled by default.
\--use-contributor-agreements::
If enabled, authors must complete a contributor agreement
on the site before pushing any commits or changes to this

View File

@@ -33,6 +33,7 @@ public interface AdminConstants extends Constants {
String buttonAddProjectRight();
String buttonClearProjectRight();
String buttonSaveChanges();
String useContentMerge();
String useContributorAgreements();
String useSignedOffBy();
String requireChangeID();

View File

@@ -14,6 +14,7 @@ buttonSelectGroup = Select
buttonAddProjectRight = Add Access Right
buttonClearProjectRight = Clear Form
buttonSaveChanges = Save Changes
useContentMerge = Automatically resolve conflicts
useContributorAgreements = Require a valid contributor agreement to upload
useSignedOffBy = Require <a href="http://gerrit.googlecode.com/svn/documentation/2.0/user-signedoffby.html#Signed-off-by" target="_blank"><code>Signed-off-by</code></a> in commit message
requireChangeID = Require <a href="http://gerrit.googlecode.com/svn/documentation/2.0/user-changeid.html" target="_blank"><code>Change-Id</code></a> in commit message

View File

@@ -36,6 +36,7 @@ public class ProjectInfoScreen extends ProjectScreen {
private Panel projectOptionsPanel;
private CheckBox requireChangeID;
private ListBox submitType;
private CheckBox useContentMerge;
private Panel agreementsPanel;
private CheckBox useContributorAgreements;
@@ -88,6 +89,7 @@ public class ProjectInfoScreen extends ProjectScreen {
private void enableForm(final boolean canModifyAgreements,
final boolean canModifyDescription, final boolean canModifyMergeType) {
submitType.setEnabled(canModifyMergeType);
useContentMerge.setEnabled(canModifyMergeType);
descTxt.setEnabled(canModifyDescription);
useContributorAgreements.setEnabled(canModifyAgreements);
useSignedOffBy.setEnabled(canModifyAgreements);
@@ -119,6 +121,10 @@ public class ProjectInfoScreen extends ProjectScreen {
saveEnabler.listenTo(submitType);
projectOptionsPanel.add(submitType);
useContentMerge = new CheckBox(Util.C.useContentMerge(), true);
saveEnabler.listenTo(useContentMerge);
projectOptionsPanel.add(useContentMerge);
requireChangeID = new CheckBox(Util.C.requireChangeID(), true);
saveEnabler.listenTo(requireChangeID);
projectOptionsPanel.add(requireChangeID);
@@ -166,6 +172,7 @@ public class ProjectInfoScreen extends ProjectScreen {
descTxt.setText(project.getDescription());
useContributorAgreements.setValue(project.isUseContributorAgreements());
useSignedOffBy.setValue(project.isUseSignedOffBy());
useContentMerge.setValue(project.isUseContentMerge());
requireChangeID.setValue(project.isRequireChangeID());
setSubmitType(project.getSubmitType());
@@ -176,6 +183,7 @@ public class ProjectInfoScreen extends ProjectScreen {
project.setDescription(descTxt.getText().trim());
project.setUseContributorAgreements(useContributorAgreements.getValue());
project.setUseSignedOffBy(useSignedOffBy.getValue());
project.setUseContentMerge(useContentMerge.getValue());
project.setRequireChangeID(requireChangeID.getValue());
if (submitType.getSelectedIndex() >= 0) {
project.setSubmitType(Project.SubmitType.valueOf(submitType

View File

@@ -102,6 +102,9 @@ public final class Project {
@Column(id = 7)
protected boolean requireChangeID;
@Column(id = 8)
protected boolean useContentMerge;
protected Project() {
}
@@ -139,6 +142,10 @@ public final class Project {
return useSignedOffBy;
}
public boolean isUseContentMerge() {
return useContentMerge;
}
public boolean isRequireChangeID() {
return requireChangeID;
}
@@ -147,6 +154,10 @@ public final class Project {
useSignedOffBy = sbo;
}
public void setUseContentMerge(final boolean cm) {
useContentMerge = cm;
}
public void setRequireChangeID(final boolean cid) {
requireChangeID = cid;
}
@@ -163,6 +174,7 @@ public final class Project {
description = update.description;
useContributorAgreements = update.useContributorAgreements;
useSignedOffBy = update.useSignedOffBy;
useContentMerge = update.useContentMerge;
requireChangeID = update.requireChangeID;
submitType = update.submitType;
}

View File

@@ -102,6 +102,7 @@ public class GitProjectImporter {
p.setSubmitType(SubmitType.MERGE_IF_NECESSARY);
p.setUseContributorAgreements(false);
p.setUseSignedOffBy(false);
p.setUseContentMerge(false);
p.setRequireChangeID(false);
db.projects().insert(Collections.singleton(p));

View File

@@ -436,7 +436,18 @@ public class MergeOp {
}
private void mergeOneCommit(final CodeReviewCommit n) throws MergeException {
final Merger m = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
final ThreeWayMerger m;
if (destProject.isUseContentMerge()) {
// Settings for this project allow us to try and
// automatically resolve conflicts within files if needed.
// Use ResolveMerge and instruct to operate in core.
m = MergeStrategy.RESOLVE.newMerger(db, true);
} else {
// No auto conflict resolving allowed. If any of the
// affected files was modified, merge will fail.
m = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
}
try {
if (m.merge(new AnyObjectId[] {mergeTip, n})) {
writeMergeCommit(m, n);
@@ -606,7 +617,17 @@ public class MergeOp {
final CodeReviewCommit n = toMerge.remove(0);
final ThreeWayMerger m;
m = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
if (destProject.isUseContentMerge()) {
// Settings for this project allow us to try and
// automatically resolve conflicts within files if needed.
// Use ResolveMerge and instruct to operate in core.
m = MergeStrategy.RESOLVE.newMerger(db, true);
} else {
// No auto conflict resolving allowed. If any of the
// affected files was modified, merge will fail.
m = MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.newMerger(db);
}
try {
if (mergeTip == null) {
// The branch is unborn. Take a fast-forward resolution to

View File

@@ -32,7 +32,7 @@ import java.util.List;
/** A version of the database schema. */
public abstract class SchemaVersion {
/** The current schema version. */
private static final Class<? extends SchemaVersion> C = Schema_46.class;
private static final Class<? extends SchemaVersion> C = Schema_47.class;
public static class Module extends AbstractModule {
@Override

View File

@@ -0,0 +1,25 @@
// Copyright (C) 2010 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.schema;
import com.google.inject.Inject;
import com.google.inject.Provider;
public class Schema_47 extends SchemaVersion {
@Inject
Schema_47(Provider<Schema_46> prior) {
super(prior);
}
}

View File

@@ -71,6 +71,9 @@ final class CreateProject extends BaseCommand {
@Option(name = "--use-signed-off-by", aliases = {"--so"}, usage = "if signed-off-by is required")
private boolean signedOffBy;
@Option(name = "--use-content-merge", usage = "allow automatic conflict resolving within files")
private boolean contentMerge;
@Option(name = "--require-change-id", aliases = {"--id"}, usage = "if change-id is required")
private boolean requireChangeID;
@@ -159,6 +162,7 @@ final class CreateProject extends BaseCommand {
newProject.setSubmitType(submitType);
newProject.setUseContributorAgreements(contributorAgreements);
newProject.setUseSignedOffBy(signedOffBy);
newProject.setUseContentMerge(contentMerge);
newProject.setRequireChangeID(requireChangeID);
if (newParent != null) {
newProject.setParent(newParent.getProject().getNameKey());