Expose instanceName in the subject template

Add a variable `instanceName` to the variables offered in the subject
template.

Remove the instanceAndProjectName as it is easy to reconstruct it using
the projectName and instanceName variables. It was also incorrect, as
it relied on the short name and not on the project name.

It was introduced recently, so _I_ don't think any gerrit instance will
break.

Change-Id: Iaf46fcbc1df6db637cb95711bac84a4ead5fc036
diff --git a/Documentation/config-mail.txt b/Documentation/config-mail.txt
index 40a6284..03f8d70 100644
--- a/Documentation/config-mail.txt
+++ b/Documentation/config-mail.txt
@@ -225,9 +225,10 @@
 +
 The project name with the path abbreviated.
 
-$instanceAndProjectName::
+$instanceName::
 +
-The Gerrit instance name, followed by the short project name
+The Gerrit instance name, as defined in the
+link:config-gerrit.html#gerrit.instanceName[configuration].
 
 $addInstanceNameInSubject::
 +
diff --git a/java/com/google/gerrit/server/mail/send/NotificationEmail.java b/java/com/google/gerrit/server/mail/send/NotificationEmail.java
index 2a24f38..1b2c205 100644
--- a/java/com/google/gerrit/server/mail/send/NotificationEmail.java
+++ b/java/com/google/gerrit/server/mail/send/NotificationEmail.java
@@ -111,11 +111,8 @@
     // shortProjectName is the project name with the path abbreviated.
     soyContext.put("shortProjectName", getShortProjectName(projectName));
 
-    // instanceAndProjectName is the instance's name followed by the abbreviated project path
-    soyContext.put(
-        "instanceAndProjectName",
-        getInstanceAndProjectName(args.instanceNameProvider.get(), projectName));
     soyContext.put("addInstanceNameInSubject", args.addInstanceNameInSubject);
+    soyContext.put("instanceName", args.instanceNameProvider.get());
 
     soyContextEmailData.put("sshHost", getSshHost());
 
@@ -136,14 +133,4 @@
 
     return "..." + projectName.substring(lastIndexSlash + 1);
   }
-
-  @VisibleForTesting
-  protected static String getInstanceAndProjectName(String instanceName, String projectName) {
-    if (instanceName == null || instanceName.isEmpty()) {
-      return getShortProjectName(projectName);
-    }
-    // Extract the project name (everything after the last slash) and prepends it with gerrit's
-    // instance name
-    return instanceName + "/" + projectName.substring(projectName.lastIndexOf('/') + 1);
-  }
 }
diff --git a/javatests/com/google/gerrit/server/mail/send/NotificationEmailTest.java b/javatests/com/google/gerrit/server/mail/send/NotificationEmailTest.java
index 885f7cd..f078f90 100644
--- a/javatests/com/google/gerrit/server/mail/send/NotificationEmailTest.java
+++ b/javatests/com/google/gerrit/server/mail/send/NotificationEmailTest.java
@@ -19,19 +19,6 @@
 import org.junit.Test;
 
 public class NotificationEmailTest {
-
-  @Test
-  public void getInstanceAndProjectName_returnsTheRightValue() {
-    String instanceAndProjectName = NotificationEmail.getInstanceAndProjectName("test", "/my/api");
-    assertThat(instanceAndProjectName).isEqualTo("test/api");
-  }
-
-  @Test
-  public void getInstanceAndProjectName_handlesNull() {
-    String instanceAndProjectName = NotificationEmail.getInstanceAndProjectName(null, "/my/api");
-    assertThat(instanceAndProjectName).isEqualTo("...api");
-  }
-
   @Test
   public void getShortProjectName() {
     assertThat(NotificationEmail.getShortProjectName("/api")).isEqualTo("api");
diff --git a/resources/com/google/gerrit/server/mail/ChangeSubject.soy b/resources/com/google/gerrit/server/mail/ChangeSubject.soy
index 48ec9a2..b0224de 100644
--- a/resources/com/google/gerrit/server/mail/ChangeSubject.soy
+++ b/resources/com/google/gerrit/server/mail/ChangeSubject.soy
@@ -22,13 +22,13 @@
  * @param branch
  * @param change
  * @param shortProjectName
- * @param instanceAndProjectName
+ * @param instanceName
  * @param addInstanceNameInSubject boolean
  */
 {template .ChangeSubject kind="text"}
   {if not $addInstanceNameInSubject}
     Change in {$shortProjectName}[{$branch.shortName}]: {$change.shortSubject}
   {else}
-    Change in {$instanceAndProjectName}[{$branch.shortName}]: {$change.shortSubject}
+    [{$instanceName}] Change in {$shortProjectName}[{$branch.shortName}]: {$change.shortSubject}
   {/if}
 {/template}