/changes/: Return more data

Allow more data to be provided in the JSON results from /changes/,
including all revisions of the change (aka patch sets), commit
message data, files, and URLs to fetch the revisions with.

Revisions are indexed by the commit SHA-1, as a commit can only
really appear once per change. The current_revision field points
to the revision structure that is the most recent for this change.

Within a revision structure the fetch map provides a set of URLs and
the corresponding reference that should point to the commit. This can
be used to fetch the change over the Git protocols. All available URL
permutations are made by the server rather than the client, giving the
server more flexibility in the long term to move changes around. This
should one day support moving closed changes out to archive
repositories with different reference names.

$ curl 'http://127.0.0.1:8080/changes/?q=97&format=JSON&o=CURRENT_REVISION&o=CURRENT_COMMIT&o=CURRENT_FILES'
)]}'
[
  {
    "project": "gerrit",
    "branch": "master",
    "id": "I7ea46d2e2ee5c64c0d807677859cfb7d90b8966a",
    "subject": "Use an EventBus to manage star icons",
    "status": "NEW",
    "created": "2012-04-25 00:52:25.580000000",
    "updated": "2012-04-25 00:52:25.586000000",
    "_sortkey": "001c9bf400000061",
    "_number": 97,
    "owner": {
      "name": "Shawn Pearce"
    },
    "current_revision": "184ebe53805e102605d11f6b143486d15c23a09c",
    "revisions": {
      "184ebe53805e102605d11f6b143486d15c23a09c": {
        "_number": 1,
        "fetch": {
          "git": {
            "url": "git://localhost/gerrit",
            "ref": "refs/changes/97/97/1"
          },
          "http": {
            "url": "http://127.0.0.1:8080/gerrit",
            "ref": "refs/changes/97/97/1"
          }
        },
        "commit": {
          "parents": [
            {
              "commit": "1eee2c9d8f352483781e772f35dc586a69ff5646",
              "subject": "Migrate contributor agreements to All-Projects."
            }
          ],
          "author": {
            "name": "Shawn O. Pearce",
            "email": "sop@google.com",
            "date": "2012-04-24 18:08:08.000000000",
            "tz": -420
          },
          "committer": {
            "name": "Shawn O. Pearce",
            "email": "sop@google.com",
            "date": "2012-04-24 18:08:08.000000000",
            "tz": -420
          },
          "subject": "Use an EventBus to manage star icons",
          "message": "Use an EventBus to manage star icons\n\nImage widgets that need to ..."
        },
        "files": {
          "gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeCache.java": {
            "lines_deleted": 8
          },
          "gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeDetailCache.java": {
            "lines_inserted": 1
          },
          "gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeScreen.java": {
            "lines_inserted": 11,
            "lines_deleted": 19
          },
          "gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeTable.java": {
            "lines_inserted": 23,
            "lines_deleted": 20
          },
          "gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/StarCache.java": {
            "status": "D",
            "lines_deleted": 139
          },
          "gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/StarredChanges.java": {
            "status": "A",
            "lines_inserted": 204
          },
          "gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/Screen.java": {
            "lines_deleted": 9
          }
        }
      }
    }
  }
]

Change-Id: I9589cc46b3dfcc43e799fdd40ee8d6c292c4f17b
This commit is contained in:
Shawn O. Pearce
2012-04-07 19:48:25 -07:00
parent 1071ec0015
commit 423c4a972c
6 changed files with 514 additions and 20 deletions

View File

@@ -0,0 +1,65 @@
// 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.common.changes;
import java.util.EnumSet;
/** Output options available when using {@code /changes/} RPCs. */
public enum ListChangesOption {
LABELS(0),
/** Return information on the current patch set of the change. */
CURRENT_REVISION(1),
ALL_REVISIONS(2),
/** If revisions are included, parse the commit object. */
CURRENT_COMMIT(3),
ALL_COMMITS(4),
/** If a patch set is included, include the files of the patch set. */
CURRENT_FILES(5),
ALL_FILES(6);
private final int value;
private ListChangesOption(int v) {
this.value = v;
}
public static EnumSet<ListChangesOption> fromBits(int v) {
EnumSet<ListChangesOption> r = EnumSet.noneOf(ListChangesOption.class);
for (ListChangesOption o : ListChangesOption.values()) {
if ((v & (1 << o.value)) != 0) {
r.add(o);
v &= ~(1 << o.value);
}
if (v == 0) {
return r;
}
}
if (v != 0) {
throw new IllegalArgumentException("unknown " + Integer.toHexString(v));
}
return r;
}
public static int toBits(EnumSet<ListChangesOption> set) {
int r = 0;
for (ListChangesOption o : set) {
r |= 1 << o.value;
}
return r;
}
}