diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt index 79e1b79c85..d9ceed7622 100644 --- a/Documentation/rest-api-changes.txt +++ b/Documentation/rest-api-changes.txt @@ -50,6 +50,8 @@ Query for open changes of watched projects: "created": "2012-07-17 07:18:30.854000000", "updated": "2012-07-17 07:19:27.766000000", "mergeable": true, + "insertions": 26, + "deletions": 10, "_sortkey": "001e7057000006dc", "_number": 1756, "owner": { @@ -67,6 +69,8 @@ Query for open changes of watched projects: "created": "2012-07-17 07:18:30.884000000", "updated": "2012-07-17 07:18:30.885000000", "mergeable": true, + "insertions": 12, + "deletions": 18, "_sortkey": "001e7056000006dd", "_number": 1757, "owner": { @@ -121,6 +125,8 @@ Query that retrieves changes for a user's dashboard: "created": "2012-07-17 07:18:30.854000000", "updated": "2012-07-17 07:19:27.766000000", "mergeable": true, + "insertions": 4, + "deletions": 7, "_sortkey": "001e7057000006dc", "_number": 1756, "owner": { @@ -263,6 +269,8 @@ default. Optional fields are: "created": "2012-04-25 00:52:25.580000000", "updated": "2012-04-25 00:52:25.586000000", "mergeable": true, + "insertions": 16, + "deletions": 7, "_sortkey": "001c9bf400000061", "_number": 97, "owner": { @@ -399,6 +407,8 @@ describes the change. "created": "2013-02-01 09:59:32.126000000", "updated": "2013-02-21 11:16:36.775000000", "mergeable": true, + "insertions": 34, + "deletions": 101, "_sortkey": "0023412400000f7d", "_number": 3965, "owner": { @@ -449,6 +459,8 @@ describes the change. "created": "2013-02-01 09:59:32.126000000", "updated": "2013-02-21 11:16:36.775000000", "mergeable": true, + "insertions": 126, + "deletions": 11, "_sortkey": "0023412400000f7d", "_number": 3965, "owner": { @@ -702,6 +714,8 @@ describes the abandoned change. "created": "2013-02-01 09:59:32.126000000", "updated": "2013-02-21 11:16:36.775000000", "mergeable": true, + "insertions": 3, + "deletions": 310, "_sortkey": "0023412400000f7d", "_number": 3965, "owner": { @@ -761,6 +775,8 @@ describes the restored change. "created": "2013-02-01 09:59:32.126000000", "updated": "2013-02-21 11:16:36.775000000", "mergeable": true, + "insertions": 2, + "deletions": 13, "_sortkey": "0023412400000f7d", "_number": 3965, "owner": { @@ -818,6 +834,8 @@ is included. "created": "2013-02-01 09:59:32.126000000", "updated": "2013-02-21 11:16:36.775000000", "mergeable": false, + "insertions": 33, + "deletions": 9, "_sortkey": "0024cf9a000012bf", "_number": 4799, "owner": { @@ -910,6 +928,8 @@ describes the reverting change. "created": "2013-02-01 09:59:32.126000000", "updated": "2013-02-21 11:16:36.775000000", "mergeable": true, + "insertions": 6, + "deletions": 4, "_sortkey": "0023412400000f7d", "_number": 3965, "owner": { @@ -1402,6 +1422,8 @@ for the current patch set. "created": "2013-02-01 09:59:32.126000000", "updated": "2013-02-21 11:16:36.775000000", "mergeable": true, + "insertions": 34, + "deletions": 45, "_sortkey": "0023412400000f7d", "_number": 3965, "owner": { @@ -1585,6 +1607,8 @@ is included. "created": "2013-02-01 09:59:32.126000000", "updated": "2013-02-21 11:16:36.775000000", "mergeable": false, + "insertions": 21, + "deletions": 21, "_sortkey": "0024cf9a000012bf", "_number": 4799, "owner": { @@ -2513,6 +2537,8 @@ describes the resulting cherry picked change. "created": "2013-02-01 09:59:32.126000000", "updated": "2013-02-21 11:16:36.775000000", "mergeable": true, + "insertions": 12, + "deletions": 11, "_sortkey": "0023412400000f7d", "_number": 3965, "owner": { @@ -2564,6 +2590,8 @@ describes the change. "created": "2013-02-01 09:59:32.126000000", "updated": "2013-02-21 11:16:36.775000000", "mergeable": true, + "insertions": 261, + "deletions": 101, "_sortkey": "0023412400000f7d", "_number": 3965, "owner": { @@ -2759,6 +2787,10 @@ Only set if link:#reviewed[reviewed] is requested. |`mergeable` |optional| Whether the change is mergeable. + Not set for merged changes. +|`insertions` || +Number of inserted lines. +|`deletions` || +Number of deleted lines. |`_sortkey` ||The sortkey of the change. |`_number` ||The legacy numeric ID of the change. |`owner` || diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java index d454c4b4f5..af2a76ef41 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/ChangeJson.java @@ -77,6 +77,7 @@ import com.google.gerrit.server.account.AccountInfo; import com.google.gerrit.server.actions.ActionInfo; import com.google.gerrit.server.extensions.webui.UiActions; import com.google.gerrit.server.git.LabelNormalizer; +import com.google.gerrit.server.patch.PatchListCache; import com.google.gerrit.server.patch.PatchListNotAvailableException; import com.google.gerrit.server.patch.PatchSetInfoFactory; import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException; @@ -84,6 +85,7 @@ import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.ProjectControl; import com.google.gerrit.server.query.change.ChangeData; +import com.google.gerrit.server.query.change.ChangeData.ChangedLines; import com.google.gwtorm.server.OrmException; import com.google.gwtorm.server.ResultSet; import com.google.inject.Inject; @@ -137,6 +139,7 @@ public class ChangeJson { private final DynamicMap downloadCommands; private final DynamicMap> changes; private final Revisions revisions; + private final PatchListCache patchListCache; private EnumSet options; private AccountInfo.Loader accountLoader; @@ -158,7 +161,8 @@ public class ChangeJson { DynamicMap downloadSchemes, DynamicMap downloadCommands, DynamicMap> changes, - Revisions revisions) { + Revisions revisions, + PatchListCache patchListCache) { this.db = db; this.labelNormalizer = ln; this.userProvider = user; @@ -172,6 +176,7 @@ public class ChangeJson { this.downloadCommands = downloadCommands; this.changes = changes; this.revisions = revisions; + this.patchListCache = patchListCache; options = EnumSet.noneOf(ListChangesOption.class); projectControls = CacheBuilder.newBuilder() @@ -268,6 +273,11 @@ public class ChangeJson { out.topic = in.getTopic(); out.changeId = in.getKey().get(); out.mergeable = in.getStatus() != Change.Status.MERGED ? in.isMergeable() : null; + ChangedLines changedLines = cd.changedLines(db, patchListCache); + if (changedLines != null) { + out.insertions = changedLines.insertions; + out.deletions = changedLines.deletions; + } out.subject = in.getSubject(); out.status = in.getStatus(); out.owner = accountLoader.get(in.getOwner()); @@ -912,6 +922,8 @@ public class ChangeJson { public Boolean starred; public Boolean reviewed; public Boolean mergeable; + public Integer insertions; + public Integer deletions; public String _sortkey; public int _number; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeData.java b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeData.java index 91b2d9d380..0bf40e2720 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeData.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/query/change/ChangeData.java @@ -153,6 +153,7 @@ public class ChangeData { private ChangeControl changeControl; private List messages; private List submitRecords; + private ChangedLines changedLines; private boolean patchesLoaded; public ChangeData(final Change.Id id) { @@ -243,6 +244,31 @@ public class ChangeData { return currentFiles; } + public ChangedLines changedLines(Provider db, + PatchListCache cache) throws OrmException { + if (changedLines == null) { + Change c = change(db); + if (c == null) { + return null; + } + + PatchSet ps = currentPatchSet(db); + if (ps == null) { + return null; + } + + PatchList p; + try { + p = cache.get(c, ps); + } catch (PatchListNotAvailableException e) { + return null; + } + + changedLines = new ChangedLines(p.getInsertions(), p.getDeletions()); + } + return changedLines; + } + public Change.Id getId() { return legacyId; } @@ -485,4 +511,14 @@ public class ChangeData { public String toString() { return Objects.toStringHelper(this).addValue(getId()).toString(); } + + public static class ChangedLines { + public final int insertions; + public final int deletions; + + ChangedLines(int insertions, int deletions) { + this.insertions = insertions; + this.deletions = deletions; + } + } }