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
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index 8d80ecb..cf230f0 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -3932,10 +3932,16 @@
[[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::
+
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java
index 8423bbf..ce32b95 100644
--- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/SubmoduleSubscriptionsIT.java
@@ -202,6 +202,35 @@
}
@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");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/VerboseSuperprojectUpdate.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/VerboseSuperprojectUpdate.java
new file mode 100644
index 0000000..f328b1ff
--- /dev/null
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/VerboseSuperprojectUpdate.java
@@ -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
+}
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/SubmoduleOp.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/SubmoduleOp.java
index 7f79a68..b23ff95 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/git/SubmoduleOp.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/SubmoduleOp.java
@@ -26,6 +26,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
});
- if (verboseSuperProject) {
+ if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
createSubmoduleCommitMsg(msgbuf, s, subOr, newCommit, oldCommit);
}
subOr.rw.parseBody(newCommit);
@@ -487,7 +490,11 @@
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 "