sendemail.includeDiff: Enable $email.UnifiedDiff in NewChange.vm

Instead of making site administrators hack the email template,
allow admins to enable the diff feature by setting a configuration
variable in gerrit.config.

Change-Id: I378485ca076cd9c56bc5149a0aaa202b20ba82d4
This commit is contained in:
Shawn O. Pearce
2012-06-12 13:44:22 -07:00
parent b032a529f8
commit 02aacbc43c
5 changed files with 50 additions and 3 deletions

View File

@@ -1879,6 +1879,14 @@ email from Gerrit.
+
By default, unset, permitting delivery to any email address.
[[sendemail.includeDiff]]sendemail.includeDiff::
+
If true, new change emails from Gerrit will include the complete
unified diff of the change. There is no upper limit on how large
the email can get when this option is enabled.
+
By default, false.
[[sendemail.importance]]sendemail.importance::
+
If present, emails sent from Gerrit will have the given level

View File

@@ -55,6 +55,7 @@ class EmailArguments {
final Provider<ChangeQueryRewriter> queryRewriter;
final Provider<ReviewDb> db;
final RuntimeInstance velocityRuntime;
final EmailSettings settings;
@Inject
EmailArguments(GitRepositoryManager server, ProjectCache projectCache,
@@ -68,7 +69,8 @@ class EmailArguments {
AllProjectsName allProjectsName,
ChangeQueryBuilder.Factory queryBuilder,
Provider<ChangeQueryRewriter> queryRewriter, Provider<ReviewDb> db,
RuntimeInstance velocityRuntime) {
RuntimeInstance velocityRuntime,
EmailSettings settings) {
this.server = server;
this.projectCache = projectCache;
this.groupBackend = groupBackend;
@@ -86,5 +88,6 @@ class EmailArguments {
this.queryRewriter = queryRewriter;
this.db = db;
this.velocityRuntime = velocityRuntime;
this.settings = settings;
}
}

View File

@@ -0,0 +1,31 @@
// 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.mail;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.lib.Config;
@Singleton
class EmailSettings {
final boolean includeDiff;
@Inject
EmailSettings(@GerritServerConfig Config cfg) {
includeDiff = cfg.getBoolean("sendemail", "includeDiff", false);
}
}

View File

@@ -101,6 +101,10 @@ public abstract class NewChangeSender extends ChangeEmail {
return host;
}
public boolean getIncludeDiff() {
return args.settings.includeDiff;
}
/** Show patch set as unified difference. */
public String getUnifiedDiff() {
ByteArrayOutputStream out = new ByteArrayOutputStream();

View File

@@ -52,6 +52,7 @@ $email.changeDetail
#if($email.sshHost)
git pull ssh://$email.sshHost/$projectName $patchSet.refName
#end
#if($email.includeDiff)
## It is possible to include the patch as a unified diff in the email:
#$email.UnifiedDiff
$email.UnifiedDiff
#end