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:
Bruce Zu
2012-10-09 14:49:39 +08:00
committed by Gustaf Lundh
parent 9e553f8265
commit 1a9be5ee43
6 changed files with 44 additions and 2 deletions

View File

@@ -65,7 +65,8 @@ OPTIONS
--files::
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
or the --patch-sets option in order to give any file information.

View File

@@ -107,6 +107,8 @@ for the containing change.
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
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>>.
sizeInsertions:: Size information of insertions of this patchset.
sizeDeletions:: Size information of deletions of this patchset.
[[approval]]
approval
--------
@@ -257,6 +263,9 @@ type:: The type of change.
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
--------

View File

@@ -73,6 +73,7 @@ public class DeprecatedChangeQueryServlet extends HttpServlet {
p.setIncludeCurrentPatchSet(get(req, "current-patch-set", false));
p.setIncludePatchSets(get(req, "patch-sets", false));
p.setIncludeApprovals(get(req, "all-approvals", false));
p.setIncludeFiles(get(req, "files", false));
p.setOutput(rsp.getOutputStream(), format);
p.query(get(req, "q", "status:open"));
}

View File

@@ -21,6 +21,7 @@ import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.Change;
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.PatchSet;
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.PatchListEntry;
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.SchemaFactory;
import com.google.inject.Inject;
@@ -46,8 +49,8 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
@@ -59,17 +62,20 @@ public class EventFactory {
private final ApprovalTypes approvalTypes;
private final PatchListCache patchListCache;
private final SchemaFactory<ReviewDb> schema;
private final PatchSetInfoFactory psInfoFactory;
@Inject
EventFactory(AccountCache accountCache,
@CanonicalWebUrl @Nullable Provider<String> urlProvider,
ApprovalTypes approvalTypes,
final PatchSetInfoFactory psif,
PatchListCache patchListCache, SchemaFactory<ReviewDb> schema) {
this.accountCache = accountCache;
this.urlProvider = urlProvider;
this.approvalTypes = approvalTypes;
this.patchListCache = patchListCache;
this.schema = schema;
this.psInfoFactory = psif;
}
/**
@@ -286,6 +292,8 @@ public class EventFactory {
PatchAttribute p = new PatchAttribute();
p.file = patch.getNewName();
p.type = patch.getChangeType();
p.deletions -= patch.getDeletions();
p.insertions = patch.getInsertions();
patchSetAttribute.files.add(p);
}
} catch (PatchListNotAvailableException e) {
@@ -323,6 +331,7 @@ public class EventFactory {
p.ref = patchSet.getRefName();
p.uploader = asAccountAttribute(patchSet.getUploader());
p.createdOn = patchSet.getCreatedOn().getTime() / 1000L;
final PatchSet.Id pId = patchSet.getId();
try {
final ReviewDb db = schema.open();
try {
@@ -331,11 +340,28 @@ public class EventFactory {
patchSet.getId())) {
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 {
db.close();
}
} catch (OrmException 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;
}

View File

@@ -19,4 +19,6 @@ import com.google.gerrit.reviewdb.client.Patch.ChangeType;
public class PatchAttribute {
public String file;
public ChangeType type;
public int insertions;
public int deletions;
}

View File

@@ -23,8 +23,11 @@ public class PatchSetAttribute {
public String ref;
public AccountAttribute uploader;
public Long createdOn;
public AccountAttribute author;
public List<ApprovalAttribute> approvals;
public List<PatchSetCommentAttribute> comments;
public List<PatchAttribute> files;
public int sizeInsertions;
public int sizeDeletions;
}