Add author and size information to output of query.
Add author information to output of query options: '--patch-sets'. '--current-patch-set'. Add size information to output of query options: '--patch-sets'. '--current-patch-set'. '--files'. This information can now be retrieved by both SSH and the HTTP REST API. Change-Id: I7ef0f2dce6a4d2bd2dd2532e4bb48a22522b659a Signed-off-by: Bruce Zu <bruce.zu@sonymobile.com>
This commit is contained in:
@@ -65,7 +65,8 @@ OPTIONS
|
|||||||
|
|
||||||
--files::
|
--files::
|
||||||
Support for listing files with patch sets and their
|
Support for listing files with patch sets and their
|
||||||
attributes (ADDED, MODIFIED, DELETED, RENAMED, COPIED).
|
attributes (ADDED, MODIFIED, DELETED, RENAMED, COPIED)
|
||||||
|
and size information (number of insertions and deletions).
|
||||||
Note that this option requires either the --current-patch-set
|
Note that this option requires either the --current-patch-set
|
||||||
or the --patch-sets option in order to give any file information.
|
or the --patch-sets option in order to give any file information.
|
||||||
|
|
||||||
|
@@ -107,6 +107,8 @@ for the containing change.
|
|||||||
|
|
||||||
uploader:: Uploader of the patch set in <<account,account attribute>>.
|
uploader:: Uploader of the patch set in <<account,account attribute>>.
|
||||||
|
|
||||||
|
author:: Author of this patchset in <<account,account attribute>>.
|
||||||
|
|
||||||
createdOn:: Time in seconds since the UNIX epoch when this patchset
|
createdOn:: Time in seconds since the UNIX epoch when this patchset
|
||||||
was created.
|
was created.
|
||||||
|
|
||||||
@@ -116,6 +118,10 @@ comments:: All inline comments for this patchset in <<patchsetcomment,patchsetCo
|
|||||||
|
|
||||||
files:: All changed files in this patchset in <<patch,patch attributes>>.
|
files:: All changed files in this patchset in <<patch,patch attributes>>.
|
||||||
|
|
||||||
|
sizeInsertions:: Size information of insertions of this patchset.
|
||||||
|
|
||||||
|
sizeDeletions:: Size information of deletions of this patchset.
|
||||||
|
|
||||||
[[approval]]
|
[[approval]]
|
||||||
approval
|
approval
|
||||||
--------
|
--------
|
||||||
@@ -257,6 +263,9 @@ type:: The type of change.
|
|||||||
|
|
||||||
REWRITE;; Sufficient amount of content changed to claim the file was rewritten.
|
REWRITE;; Sufficient amount of content changed to claim the file was rewritten.
|
||||||
|
|
||||||
|
insertions:: number of insertions of this patch.
|
||||||
|
|
||||||
|
deletions:: number of deletions of this patch.
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
|
@@ -73,6 +73,7 @@ public class DeprecatedChangeQueryServlet extends HttpServlet {
|
|||||||
p.setIncludeCurrentPatchSet(get(req, "current-patch-set", false));
|
p.setIncludeCurrentPatchSet(get(req, "current-patch-set", false));
|
||||||
p.setIncludePatchSets(get(req, "patch-sets", false));
|
p.setIncludePatchSets(get(req, "patch-sets", false));
|
||||||
p.setIncludeApprovals(get(req, "all-approvals", false));
|
p.setIncludeApprovals(get(req, "all-approvals", false));
|
||||||
|
p.setIncludeFiles(get(req, "files", false));
|
||||||
p.setOutput(rsp.getOutputStream(), format);
|
p.setOutput(rsp.getOutputStream(), format);
|
||||||
p.query(get(req, "q", "status:open"));
|
p.query(get(req, "q", "status:open"));
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@ import com.google.gerrit.reviewdb.client.Account;
|
|||||||
import com.google.gerrit.reviewdb.client.Branch;
|
import com.google.gerrit.reviewdb.client.Branch;
|
||||||
import com.google.gerrit.reviewdb.client.Change;
|
import com.google.gerrit.reviewdb.client.Change;
|
||||||
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
import com.google.gerrit.reviewdb.client.ChangeMessage;
|
||||||
|
import com.google.gerrit.reviewdb.client.Patch;
|
||||||
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
import com.google.gerrit.reviewdb.client.PatchLineComment;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.client.PatchSetAncestor;
|
import com.google.gerrit.reviewdb.client.PatchSetAncestor;
|
||||||
@@ -34,6 +35,8 @@ import com.google.gerrit.server.patch.PatchList;
|
|||||||
import com.google.gerrit.server.patch.PatchListCache;
|
import com.google.gerrit.server.patch.PatchListCache;
|
||||||
import com.google.gerrit.server.patch.PatchListEntry;
|
import com.google.gerrit.server.patch.PatchListEntry;
|
||||||
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.PatchSetInfoNotAvailableException;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.gwtorm.server.SchemaFactory;
|
import com.google.gwtorm.server.SchemaFactory;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
@@ -46,8 +49,8 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@@ -59,17 +62,20 @@ public class EventFactory {
|
|||||||
private final ApprovalTypes approvalTypes;
|
private final ApprovalTypes approvalTypes;
|
||||||
private final PatchListCache patchListCache;
|
private final PatchListCache patchListCache;
|
||||||
private final SchemaFactory<ReviewDb> schema;
|
private final SchemaFactory<ReviewDb> schema;
|
||||||
|
private final PatchSetInfoFactory psInfoFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
EventFactory(AccountCache accountCache,
|
EventFactory(AccountCache accountCache,
|
||||||
@CanonicalWebUrl @Nullable Provider<String> urlProvider,
|
@CanonicalWebUrl @Nullable Provider<String> urlProvider,
|
||||||
ApprovalTypes approvalTypes,
|
ApprovalTypes approvalTypes,
|
||||||
|
final PatchSetInfoFactory psif,
|
||||||
PatchListCache patchListCache, SchemaFactory<ReviewDb> schema) {
|
PatchListCache patchListCache, SchemaFactory<ReviewDb> schema) {
|
||||||
this.accountCache = accountCache;
|
this.accountCache = accountCache;
|
||||||
this.urlProvider = urlProvider;
|
this.urlProvider = urlProvider;
|
||||||
this.approvalTypes = approvalTypes;
|
this.approvalTypes = approvalTypes;
|
||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
this.schema = schema;
|
this.schema = schema;
|
||||||
|
this.psInfoFactory = psif;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -286,6 +292,8 @@ public class EventFactory {
|
|||||||
PatchAttribute p = new PatchAttribute();
|
PatchAttribute p = new PatchAttribute();
|
||||||
p.file = patch.getNewName();
|
p.file = patch.getNewName();
|
||||||
p.type = patch.getChangeType();
|
p.type = patch.getChangeType();
|
||||||
|
p.deletions -= patch.getDeletions();
|
||||||
|
p.insertions = patch.getInsertions();
|
||||||
patchSetAttribute.files.add(p);
|
patchSetAttribute.files.add(p);
|
||||||
}
|
}
|
||||||
} catch (PatchListNotAvailableException e) {
|
} catch (PatchListNotAvailableException e) {
|
||||||
@@ -323,6 +331,7 @@ public class EventFactory {
|
|||||||
p.ref = patchSet.getRefName();
|
p.ref = patchSet.getRefName();
|
||||||
p.uploader = asAccountAttribute(patchSet.getUploader());
|
p.uploader = asAccountAttribute(patchSet.getUploader());
|
||||||
p.createdOn = patchSet.getCreatedOn().getTime() / 1000L;
|
p.createdOn = patchSet.getCreatedOn().getTime() / 1000L;
|
||||||
|
final PatchSet.Id pId = patchSet.getId();
|
||||||
try {
|
try {
|
||||||
final ReviewDb db = schema.open();
|
final ReviewDb db = schema.open();
|
||||||
try {
|
try {
|
||||||
@@ -331,11 +340,28 @@ public class EventFactory {
|
|||||||
patchSet.getId())) {
|
patchSet.getId())) {
|
||||||
p.parents.add(a.getAncestorRevision().get());
|
p.parents.add(a.getAncestorRevision().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.author = asAccountAttribute(//
|
||||||
|
psInfoFactory.get(db, pId).getAuthor().getAccount());
|
||||||
|
|
||||||
|
Change change = db.changes().get(pId.getParentKey());
|
||||||
|
List<Patch> list =
|
||||||
|
patchListCache.get(change, patchSet).toPatchList(pId);
|
||||||
|
for (Patch pe : list) {
|
||||||
|
if (!Patch.COMMIT_MSG.equals(pe.getFileName())) {
|
||||||
|
p.sizeDeletions -= pe.getDeletions();
|
||||||
|
p.sizeInsertions += pe.getInsertions();
|
||||||
|
}
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
} catch (OrmException e) {
|
} catch (OrmException e) {
|
||||||
log.error("Cannot load patch set data for " + patchSet.getId(), e);
|
log.error("Cannot load patch set data for " + patchSet.getId(), e);
|
||||||
|
} catch (PatchSetInfoNotAvailableException e) {
|
||||||
|
log.error(String.format("Cannot get authorEmail for %s.", pId), e);
|
||||||
|
} catch (PatchListNotAvailableException e) {
|
||||||
|
log.error(String.format("Cannot get size information for %s.", pId), e);
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@@ -19,4 +19,6 @@ import com.google.gerrit.reviewdb.client.Patch.ChangeType;
|
|||||||
public class PatchAttribute {
|
public class PatchAttribute {
|
||||||
public String file;
|
public String file;
|
||||||
public ChangeType type;
|
public ChangeType type;
|
||||||
|
public int insertions;
|
||||||
|
public int deletions;
|
||||||
}
|
}
|
||||||
|
@@ -23,8 +23,11 @@ public class PatchSetAttribute {
|
|||||||
public String ref;
|
public String ref;
|
||||||
public AccountAttribute uploader;
|
public AccountAttribute uploader;
|
||||||
public Long createdOn;
|
public Long createdOn;
|
||||||
|
public AccountAttribute author;
|
||||||
|
|
||||||
public List<ApprovalAttribute> approvals;
|
public List<ApprovalAttribute> approvals;
|
||||||
public List<PatchSetCommentAttribute> comments;
|
public List<PatchSetCommentAttribute> comments;
|
||||||
public List<PatchAttribute> files;
|
public List<PatchAttribute> files;
|
||||||
|
public int sizeInsertions;
|
||||||
|
public int sizeDeletions;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user