Return for changes the number of insertions and deletions
Change-Id: I71c97ce2075d2f012fe75bc2287e0e6a99cd5570 Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
parent
ca80447775
commit
a6b6eaf811
@ -50,6 +50,8 @@ Query for open changes of watched projects:
|
|||||||
"created": "2012-07-17 07:18:30.854000000",
|
"created": "2012-07-17 07:18:30.854000000",
|
||||||
"updated": "2012-07-17 07:19:27.766000000",
|
"updated": "2012-07-17 07:19:27.766000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 26,
|
||||||
|
"deletions": 10,
|
||||||
"_sortkey": "001e7057000006dc",
|
"_sortkey": "001e7057000006dc",
|
||||||
"_number": 1756,
|
"_number": 1756,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -67,6 +69,8 @@ Query for open changes of watched projects:
|
|||||||
"created": "2012-07-17 07:18:30.884000000",
|
"created": "2012-07-17 07:18:30.884000000",
|
||||||
"updated": "2012-07-17 07:18:30.885000000",
|
"updated": "2012-07-17 07:18:30.885000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 12,
|
||||||
|
"deletions": 18,
|
||||||
"_sortkey": "001e7056000006dd",
|
"_sortkey": "001e7056000006dd",
|
||||||
"_number": 1757,
|
"_number": 1757,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -121,6 +125,8 @@ Query that retrieves changes for a user's dashboard:
|
|||||||
"created": "2012-07-17 07:18:30.854000000",
|
"created": "2012-07-17 07:18:30.854000000",
|
||||||
"updated": "2012-07-17 07:19:27.766000000",
|
"updated": "2012-07-17 07:19:27.766000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 4,
|
||||||
|
"deletions": 7,
|
||||||
"_sortkey": "001e7057000006dc",
|
"_sortkey": "001e7057000006dc",
|
||||||
"_number": 1756,
|
"_number": 1756,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -263,6 +269,8 @@ default. Optional fields are:
|
|||||||
"created": "2012-04-25 00:52:25.580000000",
|
"created": "2012-04-25 00:52:25.580000000",
|
||||||
"updated": "2012-04-25 00:52:25.586000000",
|
"updated": "2012-04-25 00:52:25.586000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 16,
|
||||||
|
"deletions": 7,
|
||||||
"_sortkey": "001c9bf400000061",
|
"_sortkey": "001c9bf400000061",
|
||||||
"_number": 97,
|
"_number": 97,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -399,6 +407,8 @@ describes the change.
|
|||||||
"created": "2013-02-01 09:59:32.126000000",
|
"created": "2013-02-01 09:59:32.126000000",
|
||||||
"updated": "2013-02-21 11:16:36.775000000",
|
"updated": "2013-02-21 11:16:36.775000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 34,
|
||||||
|
"deletions": 101,
|
||||||
"_sortkey": "0023412400000f7d",
|
"_sortkey": "0023412400000f7d",
|
||||||
"_number": 3965,
|
"_number": 3965,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -449,6 +459,8 @@ describes the change.
|
|||||||
"created": "2013-02-01 09:59:32.126000000",
|
"created": "2013-02-01 09:59:32.126000000",
|
||||||
"updated": "2013-02-21 11:16:36.775000000",
|
"updated": "2013-02-21 11:16:36.775000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 126,
|
||||||
|
"deletions": 11,
|
||||||
"_sortkey": "0023412400000f7d",
|
"_sortkey": "0023412400000f7d",
|
||||||
"_number": 3965,
|
"_number": 3965,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -702,6 +714,8 @@ describes the abandoned change.
|
|||||||
"created": "2013-02-01 09:59:32.126000000",
|
"created": "2013-02-01 09:59:32.126000000",
|
||||||
"updated": "2013-02-21 11:16:36.775000000",
|
"updated": "2013-02-21 11:16:36.775000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 3,
|
||||||
|
"deletions": 310,
|
||||||
"_sortkey": "0023412400000f7d",
|
"_sortkey": "0023412400000f7d",
|
||||||
"_number": 3965,
|
"_number": 3965,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -761,6 +775,8 @@ describes the restored change.
|
|||||||
"created": "2013-02-01 09:59:32.126000000",
|
"created": "2013-02-01 09:59:32.126000000",
|
||||||
"updated": "2013-02-21 11:16:36.775000000",
|
"updated": "2013-02-21 11:16:36.775000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 2,
|
||||||
|
"deletions": 13,
|
||||||
"_sortkey": "0023412400000f7d",
|
"_sortkey": "0023412400000f7d",
|
||||||
"_number": 3965,
|
"_number": 3965,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -818,6 +834,8 @@ is included.
|
|||||||
"created": "2013-02-01 09:59:32.126000000",
|
"created": "2013-02-01 09:59:32.126000000",
|
||||||
"updated": "2013-02-21 11:16:36.775000000",
|
"updated": "2013-02-21 11:16:36.775000000",
|
||||||
"mergeable": false,
|
"mergeable": false,
|
||||||
|
"insertions": 33,
|
||||||
|
"deletions": 9,
|
||||||
"_sortkey": "0024cf9a000012bf",
|
"_sortkey": "0024cf9a000012bf",
|
||||||
"_number": 4799,
|
"_number": 4799,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -910,6 +928,8 @@ describes the reverting change.
|
|||||||
"created": "2013-02-01 09:59:32.126000000",
|
"created": "2013-02-01 09:59:32.126000000",
|
||||||
"updated": "2013-02-21 11:16:36.775000000",
|
"updated": "2013-02-21 11:16:36.775000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 6,
|
||||||
|
"deletions": 4,
|
||||||
"_sortkey": "0023412400000f7d",
|
"_sortkey": "0023412400000f7d",
|
||||||
"_number": 3965,
|
"_number": 3965,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -1402,6 +1422,8 @@ for the current patch set.
|
|||||||
"created": "2013-02-01 09:59:32.126000000",
|
"created": "2013-02-01 09:59:32.126000000",
|
||||||
"updated": "2013-02-21 11:16:36.775000000",
|
"updated": "2013-02-21 11:16:36.775000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 34,
|
||||||
|
"deletions": 45,
|
||||||
"_sortkey": "0023412400000f7d",
|
"_sortkey": "0023412400000f7d",
|
||||||
"_number": 3965,
|
"_number": 3965,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -1585,6 +1607,8 @@ is included.
|
|||||||
"created": "2013-02-01 09:59:32.126000000",
|
"created": "2013-02-01 09:59:32.126000000",
|
||||||
"updated": "2013-02-21 11:16:36.775000000",
|
"updated": "2013-02-21 11:16:36.775000000",
|
||||||
"mergeable": false,
|
"mergeable": false,
|
||||||
|
"insertions": 21,
|
||||||
|
"deletions": 21,
|
||||||
"_sortkey": "0024cf9a000012bf",
|
"_sortkey": "0024cf9a000012bf",
|
||||||
"_number": 4799,
|
"_number": 4799,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -2513,6 +2537,8 @@ describes the resulting cherry picked change.
|
|||||||
"created": "2013-02-01 09:59:32.126000000",
|
"created": "2013-02-01 09:59:32.126000000",
|
||||||
"updated": "2013-02-21 11:16:36.775000000",
|
"updated": "2013-02-21 11:16:36.775000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 12,
|
||||||
|
"deletions": 11,
|
||||||
"_sortkey": "0023412400000f7d",
|
"_sortkey": "0023412400000f7d",
|
||||||
"_number": 3965,
|
"_number": 3965,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -2564,6 +2590,8 @@ describes the change.
|
|||||||
"created": "2013-02-01 09:59:32.126000000",
|
"created": "2013-02-01 09:59:32.126000000",
|
||||||
"updated": "2013-02-21 11:16:36.775000000",
|
"updated": "2013-02-21 11:16:36.775000000",
|
||||||
"mergeable": true,
|
"mergeable": true,
|
||||||
|
"insertions": 261,
|
||||||
|
"deletions": 101,
|
||||||
"_sortkey": "0023412400000f7d",
|
"_sortkey": "0023412400000f7d",
|
||||||
"_number": 3965,
|
"_number": 3965,
|
||||||
"owner": {
|
"owner": {
|
||||||
@ -2759,6 +2787,10 @@ Only set if link:#reviewed[reviewed] is requested.
|
|||||||
|`mergeable` |optional|
|
|`mergeable` |optional|
|
||||||
Whether the change is mergeable. +
|
Whether the change is mergeable. +
|
||||||
Not set for merged changes.
|
Not set for merged changes.
|
||||||
|
|`insertions` ||
|
||||||
|
Number of inserted lines.
|
||||||
|
|`deletions` ||
|
||||||
|
Number of deleted lines.
|
||||||
|`_sortkey` ||The sortkey of the change.
|
|`_sortkey` ||The sortkey of the change.
|
||||||
|`_number` ||The legacy numeric ID of the change.
|
|`_number` ||The legacy numeric ID of the change.
|
||||||
|`owner` ||
|
|`owner` ||
|
||||||
|
@ -77,6 +77,7 @@ import com.google.gerrit.server.account.AccountInfo;
|
|||||||
import com.google.gerrit.server.actions.ActionInfo;
|
import com.google.gerrit.server.actions.ActionInfo;
|
||||||
import com.google.gerrit.server.extensions.webui.UiActions;
|
import com.google.gerrit.server.extensions.webui.UiActions;
|
||||||
import com.google.gerrit.server.git.LabelNormalizer;
|
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.PatchListNotAvailableException;
|
||||||
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
||||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
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.NoSuchProjectException;
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
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.OrmException;
|
||||||
import com.google.gwtorm.server.ResultSet;
|
import com.google.gwtorm.server.ResultSet;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@ -137,6 +139,7 @@ public class ChangeJson {
|
|||||||
private final DynamicMap<DownloadCommand> downloadCommands;
|
private final DynamicMap<DownloadCommand> downloadCommands;
|
||||||
private final DynamicMap<RestView<ChangeResource>> changes;
|
private final DynamicMap<RestView<ChangeResource>> changes;
|
||||||
private final Revisions revisions;
|
private final Revisions revisions;
|
||||||
|
private final PatchListCache patchListCache;
|
||||||
|
|
||||||
private EnumSet<ListChangesOption> options;
|
private EnumSet<ListChangesOption> options;
|
||||||
private AccountInfo.Loader accountLoader;
|
private AccountInfo.Loader accountLoader;
|
||||||
@ -158,7 +161,8 @@ public class ChangeJson {
|
|||||||
DynamicMap<DownloadScheme> downloadSchemes,
|
DynamicMap<DownloadScheme> downloadSchemes,
|
||||||
DynamicMap<DownloadCommand> downloadCommands,
|
DynamicMap<DownloadCommand> downloadCommands,
|
||||||
DynamicMap<RestView<ChangeResource>> changes,
|
DynamicMap<RestView<ChangeResource>> changes,
|
||||||
Revisions revisions) {
|
Revisions revisions,
|
||||||
|
PatchListCache patchListCache) {
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.labelNormalizer = ln;
|
this.labelNormalizer = ln;
|
||||||
this.userProvider = user;
|
this.userProvider = user;
|
||||||
@ -172,6 +176,7 @@ public class ChangeJson {
|
|||||||
this.downloadCommands = downloadCommands;
|
this.downloadCommands = downloadCommands;
|
||||||
this.changes = changes;
|
this.changes = changes;
|
||||||
this.revisions = revisions;
|
this.revisions = revisions;
|
||||||
|
this.patchListCache = patchListCache;
|
||||||
|
|
||||||
options = EnumSet.noneOf(ListChangesOption.class);
|
options = EnumSet.noneOf(ListChangesOption.class);
|
||||||
projectControls = CacheBuilder.newBuilder()
|
projectControls = CacheBuilder.newBuilder()
|
||||||
@ -268,6 +273,11 @@ public class ChangeJson {
|
|||||||
out.topic = in.getTopic();
|
out.topic = in.getTopic();
|
||||||
out.changeId = in.getKey().get();
|
out.changeId = in.getKey().get();
|
||||||
out.mergeable = in.getStatus() != Change.Status.MERGED ? in.isMergeable() : null;
|
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.subject = in.getSubject();
|
||||||
out.status = in.getStatus();
|
out.status = in.getStatus();
|
||||||
out.owner = accountLoader.get(in.getOwner());
|
out.owner = accountLoader.get(in.getOwner());
|
||||||
@ -912,6 +922,8 @@ public class ChangeJson {
|
|||||||
public Boolean starred;
|
public Boolean starred;
|
||||||
public Boolean reviewed;
|
public Boolean reviewed;
|
||||||
public Boolean mergeable;
|
public Boolean mergeable;
|
||||||
|
public Integer insertions;
|
||||||
|
public Integer deletions;
|
||||||
|
|
||||||
public String _sortkey;
|
public String _sortkey;
|
||||||
public int _number;
|
public int _number;
|
||||||
|
@ -153,6 +153,7 @@ public class ChangeData {
|
|||||||
private ChangeControl changeControl;
|
private ChangeControl changeControl;
|
||||||
private List<ChangeMessage> messages;
|
private List<ChangeMessage> messages;
|
||||||
private List<SubmitRecord> submitRecords;
|
private List<SubmitRecord> submitRecords;
|
||||||
|
private ChangedLines changedLines;
|
||||||
private boolean patchesLoaded;
|
private boolean patchesLoaded;
|
||||||
|
|
||||||
public ChangeData(final Change.Id id) {
|
public ChangeData(final Change.Id id) {
|
||||||
@ -243,6 +244,31 @@ public class ChangeData {
|
|||||||
return currentFiles;
|
return currentFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChangedLines changedLines(Provider<ReviewDb> 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() {
|
public Change.Id getId() {
|
||||||
return legacyId;
|
return legacyId;
|
||||||
}
|
}
|
||||||
@ -485,4 +511,14 @@ public class ChangeData {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return Objects.toStringHelper(this).addValue(getId()).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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user