Change verboseSuperprojectUpdate config into a tri-state Enum

verboseSuperprojectUpdate was a boolean config option that either do not
include anything (false state) or include the full commit messages(true
state) from all related submodule changes. Add a third state called
SUBJECT_ONLY that only include the subjects of the commits from the
change history. Also set the default to be SUBJECT_ONLY.

Change-Id: I6baa16180c31f36ed3d61930834470c3c27387ed
This commit is contained in:
Zhen Chen
2016-07-27 14:22:37 -07:00
parent 5bc3eef046
commit c877ca9f5e
4 changed files with 80 additions and 9 deletions

View File

@@ -3932,10 +3932,16 @@ It can contain placeholders for the groups matched by the
[[submodule.verbosesuperprojectupdate]]submodule.verboseSuperprojectUpdate::
+
When using link:user-submodules.html#automatic_update[automatic superproject updates]
this option will determine if the submodule commit messages are included into
this option will determine how the submodule commit messages are included into
the commit message of the superproject update.
+
By default this is true.
If `FALSE`, will not include any commit messages for the gitlink update.
+
If `SUBJECT_ONLY`, will include only the commit subjects.
+
If `TRUE`, will include full commit messages.
+
By default this is `TRUE`.
[[submodule.enableSuperProjectSubscriptions]]submodule.enableSuperProjectSubscriptions::
+

View File

@@ -201,6 +201,35 @@ public class SubmoduleSubscriptionsIT extends AbstractSubmoduleSubscription {
"Update git submodules\n\n");
}
@Test
@GerritConfig(name = "submodule.verboseSuperprojectUpdate", value = "SUBJECT_ONLY")
public void testSubmoduleSubjectCommitMessage() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowSubmoduleSubscription("subscribed-to-project", "refs/heads/master",
"super-project", "refs/heads/master");
pushChangeTo(subRepo, "master");
createSubmoduleSubscription(superRepo, "master",
"subscribed-to-project", "master");
ObjectId subHEAD = pushChangeTo(subRepo, "master");
// The first update doesn't include the rev log
RevWalk rw = subRepo.getRevWalk();
expectToHaveCommitMessage(superRepo, "master",
"Update git submodules\n\n" +
"* Update " + name("subscribed-to-project") + " from branch 'master'");
// The next commit should generate only its commit message,
// omitting previous commit logs
subHEAD = pushChangeTo(subRepo, "master");
RevCommit subCommitMsg = rw.parseCommit(subHEAD);
expectToHaveCommitMessage(superRepo, "master",
"Update git submodules\n\n" +
"* Update " + name("subscribed-to-project") + " from branch 'master'"
+ "\n - " + subCommitMsg.getShortMessage());
}
@Test
public void testSubmoduleCommitMessage() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");

View File

@@ -0,0 +1,29 @@
// Copyright (C) 2016 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.config;
/**
* Verbosity level of the commit message for submodule subscriptions.
*/
public enum VerboseSuperprojectUpdate {
/** Do not include any commit messages for the gitlink update. */
FALSE,
/** Only include the commit subjects. */
SUBJECT_ONLY,
/** Include full commit messages. */
TRUE
}

View File

@@ -26,6 +26,7 @@ import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.reviewdb.client.SubmoduleSubscription;
import com.google.gerrit.server.GerritPersonIdent;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.VerboseSuperprojectUpdate;
import com.google.gerrit.server.git.BatchUpdate.Listener;
import com.google.gerrit.server.git.BatchUpdate.RepoContext;
import com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo;
@@ -99,7 +100,7 @@ public class SubmoduleOp {
private final PersonIdent myIdent;
private final ProjectCache projectCache;
private final ProjectState.Factory projectStateFactory;
private final boolean verboseSuperProject;
private final VerboseSuperprojectUpdate verboseSuperProject;
private final boolean enableSuperProjectSubscriptions;
private final Multimap<Branch.NameKey, SubmoduleSubscription> targets;
private final Set<Branch.NameKey> updatedBranches;
@@ -121,8 +122,9 @@ public class SubmoduleOp {
this.myIdent = myIdent;
this.projectCache = projectCache;
this.projectStateFactory = projectStateFactory;
this.verboseSuperProject = cfg.getBoolean("submodule",
"verboseSuperprojectUpdate", true);
this.verboseSuperProject =
cfg.getEnum("submodule", null, "verboseSuperprojectUpdate",
VerboseSuperprojectUpdate.TRUE);
this.enableSuperProjectSubscriptions = cfg.getBoolean("submodule",
"enableSuperProjectSubscriptions", true);
this.orm = orm;
@@ -365,7 +367,7 @@ public class SubmoduleOp {
commit.setTreeId(newTreeId);
commit.setParentId(currentCommit);
StringBuilder commitMsg = new StringBuilder("Update git submodules\n\n");
if (verboseSuperProject) {
if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
commitMsg.append(msgbuf);
}
commit.setMessage(commitMsg.toString());
@@ -405,7 +407,8 @@ public class SubmoduleOp {
CommitBuilder commit = new CommitBuilder();
commit.setTreeId(newTreeId);
commit.setParentIds(currentCommit.getParents());
if (verboseSuperProject) {
if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
//TODO:czhen handle cherrypick footer
commit.setMessage(
currentCommit.getFullMessage() + "\n\n*submodules:\n" + msgbuf.toString());
} else {
@@ -463,7 +466,7 @@ public class SubmoduleOp {
}
});
if (verboseSuperProject) {
if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
createSubmoduleCommitMsg(msgbuf, s, subOr, newCommit, oldCommit);
}
subOr.rw.parseBody(newCommit);
@@ -487,7 +490,11 @@ public class SubmoduleOp {
subOr.rw.markUninteresting(oldCommit);
for (RevCommit c : subOr.rw) {
subOr.rw.parseBody(c);
msgbuf.append("\n - " + c.getFullMessage().replace("\n", "\n "));
if (verboseSuperProject == VerboseSuperprojectUpdate.SUBJECT_ONLY) {
msgbuf.append("\n - " + c.getShortMessage());
} else if (verboseSuperProject == VerboseSuperprojectUpdate.TRUE) {
msgbuf.append("\n - " + c.getFullMessage().replace("\n", "\n "));
}
}
} catch (IOException e) {
throw new SubmoduleException("Could not perform a revwalk to "