Set commit ID in result of the /changes/*/revisions/*/commit endpoint
Setting the commit ID is important when a revision ID other than a
commit ID is used, e.g. a legacy numeric patch set number, or the
literal 'current'.
Also explain in the documentation in which case the commit ID is not
set.
Change-Id: Iadcff2c7cbe98be8c826a0ea6d0aa8bd8ff2a6be
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt
index 55b4800..1300628 100644
--- a/Documentation/rest-api-changes.txt
+++ b/Documentation/rest-api-changes.txt
@@ -2235,6 +2235,7 @@
)]}'
{
+ "commit": "674ac754f91e64a0efb8087e59a176484bd534d1",
"parents": [
{
"commit": "1eee2c9d8f352483781e772f35dc586a69ff5646",
@@ -3947,7 +3948,10 @@
[options="header",cols="1,^1,5"]
|===========================
|Field Name ||Description
-|`commit` ||The commit ID.
+|`commit` |Optional|
+The commit ID. Not set if included in a link:#revision-info[
+RevisionInfo] entity that is contained in a map which has the commit ID
+as key.
|`parents` ||
The parent commits of this commit as a list of
link:#commit-info[CommitInfo] entities. In each parent
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetCommit.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetCommit.java
index a7f8dea..72f8c35 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/change/GetCommit.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/GetCommit.java
@@ -54,6 +54,7 @@
rw.parseBody(commit);
CommitInfo info = json.create(ChangeJson.NO_OPTIONS)
.toCommit(rsrc.getControl(), rw, commit, addLinks);
+ info.commit = commit.name();
Response<CommitInfo> r = Response.ok(info);
if (rsrc.isCacheable()) {
r.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS));