Add macro for the revision from which the documentation is shown

'@REVISION@' can now be used as a placeholder for the revision ID.

Change-Id: Iae6085ca158b3e09396167b2b72034f92c7d64ed
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocLoader.java b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocLoader.java
index 758a7c2..13949e1 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocLoader.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/xdocs/XDocLoader.java
@@ -36,6 +36,7 @@
 import com.googlesource.gerrit.plugins.xdocs.formatter.Formatters.FormatterProvider;
 
 import org.eclipse.jgit.diff.RawText;
+import org.eclipse.jgit.lib.AbbreviatedObjectId;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.ObjectLoader;
 import org.eclipse.jgit.lib.ObjectReader;
@@ -106,10 +107,11 @@
           }
           ObjectReader reader = repo.newObjectReader();
           try {
+            String abbrRevId = reader.abbreviate(key.getRevId()).name();
             String html =
                 formatter.get().format(key.getProject().get(),
-                    reader.abbreviate(key.getRevId()).name(), formatterCfg,
-                    replaceMacros(key.getProject(), bytes));
+                    abbrRevId, formatterCfg,
+                    replaceMacros(key.getProject(), abbrRevId, bytes));
             return getAsHtmlResource(html, commit.getCommitTime());
           } finally {
             reader.release();
@@ -125,7 +127,8 @@
     }
   }
 
-  private String replaceMacros(Project.NameKey project, byte[] raw) {
+  private String replaceMacros(Project.NameKey project, String abbrRevId,
+      byte[] raw) {
     Map<String, String> macros = Maps.newHashMap();
 
     String url = webUrl.get();
@@ -136,6 +139,7 @@
 
     macros.put("PROJECT", project.get());
     macros.put("PROJECT_URL", url + "#/admin/projects/" + project.get());
+    macros.put("REVISION", abbrRevId);
 
     Matcher m = Pattern.compile("(\\\\)?@([A-Z_]+)@")
         .matcher(new String(raw, UTF_8));
diff --git a/src/main/resources/Documentation/user.md b/src/main/resources/Documentation/user.md
index 760b4da..fc31782 100644
--- a/src/main/resources/Documentation/user.md
+++ b/src/main/resources/Documentation/user.md
@@ -77,3 +77,4 @@
 * `\@URL@`: The web URL of the Gerrit server.
 * `\@PROJECT@`: The name of the project from which the documentation is shown.
 * `\@PROJECT_URL@`: The web URL of the project from which the documentation is shown.
+* `\@REVISION@`: The abbreviated ID of the revision from which the documentation is shown.