Add $change.originalSubject for email templates

GMail threads messages together by subject and ignores the list
headers included by Gerrit.  Keep track of the first (or most recent)
subject used by each change so that the string is available to the
site's ChangeSubject.vm template.

Site administrators that run servers whose end-user base is mostly on
GMail (e.g. internal Google) can modify the site's ChangeSubject.vm
to use $change.originalSubject to improve threading for GMail inboxes.

To simplify the schema upgrade for gerrit-review the originalSubject
field is automatically taken from the existing subject field during
first use.  This avoids needing to rewrite every change record in the
database to copy over the subject string to originalSubject.  Avoiding
update of every change also improves migration times for any large
server, as the database will not update XX,XXX merged changes.

Change-Id: Idc36cbf0cef9fe06b0b272f6a7eefe76635e3e19
This commit is contained in:
Shawn Pearce
2014-12-27 17:58:31 -05:00
parent e8ca2eadce
commit 43b10f8672
4 changed files with 59 additions and 1 deletions

View File

@@ -467,6 +467,15 @@ public final class Change {
// DELETED: id = 15 (lastSha1MergeTested)
// DELETED: id = 16 (mergeable)
/**
* First line of first patch set's commit message.
*
* Unlike {@link #subject}, this string does not change if future patch sets
* change the first line.
*/
@Column(id = 17, notNull = false)
protected String originalSubject;
protected Change() {
}
@@ -493,6 +502,7 @@ public final class Change {
status = other.status;
currentPatchSetId = other.currentPatchSetId;
subject = other.subject;
originalSubject = other.originalSubject;
topic = other.topic;
}
@@ -547,6 +557,10 @@ public final class Change {
return subject;
}
public String getOriginalSubject() {
return originalSubject != null ? originalSubject : subject;
}
/** Get the id of the most current {@link PatchSet} in this change. */
public PatchSet.Id currentPatchSetId() {
if (currentPatchSetId > 0) {
@@ -556,8 +570,20 @@ public final class Change {
}
public void setCurrentPatchSet(final PatchSetInfo ps) {
if (originalSubject == null && subject != null) {
// Change was created before schema upgrade. Use the last subject
// associated with this change, as the most recent discussion will
// be under that thread in an email client such as GMail.
originalSubject = subject;
}
currentPatchSetId = ps.getKey().get();
subject = ps.getSubject();
if (originalSubject == null) {
// Newly created changes remember the first commit's subject.
originalSubject = subject;
}
}
public Status getStatus() {

View File

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

View File

@@ -0,0 +1,27 @@
// Copyright (C) 2014 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_103 extends SchemaVersion {
@Inject
Schema_103(Provider<Schema_102> prior) {
super(prior);
}
// Adds originalSubject column
}

View File

@@ -31,6 +31,11 @@
## The ChangeSubject.vm template will determine the contents of the email
## subject line for ALL emails related to changes.
##
## Optionally $change.originalSubject can be used for the first subject
## in a change. This allows subject based email clients such as GMail
## to thread comments together even if subsequent patch sets change the
## first line of the commit message.
##
#macro(ellipsis $length $str)
#if($str.length() > $length)#set($length = $length - 3)${str.substring(0,$length)}...#else$str#end
#end