Add parent info to each ChangeScreen PatchSetBlock

Parent commit id and short message is placed in a Grid that expands
vertically when a patch set has more than one parent. The text
"Initial Commit" is used when a patch set has no parents.

Change-Id: I5775e8e09b506d9a97d0303e0ba150a926a091e8
This commit is contained in:
Nasser Grainawi 2011-05-17 18:20:14 -07:00 committed by Shawn O. Pearce
parent a2b0e272c9
commit 4f066809b5
7 changed files with 102 additions and 3 deletions

View File

@ -131,10 +131,12 @@ public interface GerritCss extends CssResource {
String menuScreenMenuBar();
String missingApproval();
String missingApprovalList();
String monospace();
String needsReview();
String negscore();
String noLineLineNumber();
String noborder();
String parentsTable();
String patchBrowserPopup();
String patchBrowserPopupBody();
String patchComments();

View File

@ -99,6 +99,8 @@ public interface ChangeConstants extends Constants {
String patchSetInfoAuthor();
String patchSetInfoCommitter();
String patchSetInfoDownload();
String patchSetInfoParents();
String initialCommit();
String buttonAbandonChangeBegin();
String buttonAbandonChangeSend();

View File

@ -76,6 +76,8 @@ messageCollapseAll = Collapse All
patchSetInfoAuthor = Author
patchSetInfoCommitter = Committer
patchSetInfoDownload = Download
patchSetInfoParents = Parent(s)
initialCommit = Initial Commit
buttonAbandonChangeBegin = Abandon Change
buttonAbandonChangeSend = Abandon Change

View File

@ -54,13 +54,15 @@ import com.google.gwtexpui.clippy.client.CopyableLabel;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel implements OpenHandler<DisclosurePanel> {
private static final int R_AUTHOR = 0;
private static final int R_COMMITTER = 1;
private static final int R_DOWNLOAD = 2;
private static final int R_CNT = 3;
private static final int R_PARENTS = 2;
private static final int R_DOWNLOAD = 3;
private static final int R_CNT = 4;
private final ChangeScreen changeScreen;
private final ChangeDetail changeDetail;
@ -125,6 +127,7 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel implements O
initRow(R_AUTHOR, Util.C.patchSetInfoAuthor());
initRow(R_COMMITTER, Util.C.patchSetInfoCommitter());
initRow(R_PARENTS, Util.C.patchSetInfoParents());
initRow(R_DOWNLOAD, Util.C.patchSetInfoDownload());
final CellFormatter itfmt = infoTable.getCellFormatter();
@ -139,6 +142,7 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel implements O
final PatchSetInfo info = detail.getInfo();
displayUserIdentity(R_AUTHOR, info.getAuthor());
displayUserIdentity(R_COMMITTER, info.getCommitter());
displayParents(info.getParents());
displayDownload();
@ -363,6 +367,28 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel implements O
infoTable.setWidget(row, 1, fp);
}
private void displayParents(final List<PatchSetInfo.ParentInfo> parents) {
if (parents.size() == 0) {
infoTable.setWidget(R_PARENTS, 1, new InlineLabel(Util.C.initialCommit()));
return;
}
final Grid parentsTable = new Grid(parents.size(), 2);
parentsTable.setStyleName(Gerrit.RESOURCES.css().parentsTable());
parentsTable.addStyleName(Gerrit.RESOURCES.css().noborder());
final CellFormatter ptfmt = parentsTable.getCellFormatter();
int row = 0;
for (PatchSetInfo.ParentInfo parent : parents) {
parentsTable.setWidget(row, 0, new InlineLabel(parent.id.get()));
ptfmt.addStyleName(row, 0, Gerrit.RESOURCES.css().noborder());
ptfmt.addStyleName(row, 0, Gerrit.RESOURCES.css().monospace());
parentsTable.setWidget(row, 1, new InlineLabel(parent.shortMessage));
ptfmt.addStyleName(row, 1, Gerrit.RESOURCES.css().noborder());
row++;
}
infoTable.setWidget(R_PARENTS, 1, parentsTable);
}
private void populateActions(final PatchSetDetail detail) {
final boolean isOpen = changeDetail.getChange().getStatus().isOpen();
Set<ApprovalCategory.Id> allowed = changeDetail.getCurrentActions();

View File

@ -972,6 +972,28 @@ a:hover.downloadLink {
width: 30em;
}
.parentsTable {
border-style: none;
border: 1px 1px 1px 0px;
outline: 0px;
padding: 0px;
border-spacing: 0px;
text-align: left;
font-family: mono-font;
font-size: 10px;
}
.parentsTable td.noborder {
border: none;
}
.parentsTable td.monospace {
font-family: mono-font;
font-size: 10px;
margin: 0px;
padding-left: 0px;
}
/** SideBySideScreen **/
.sideBySideScreenSideBySideTable {
width: 100%;

View File

@ -14,11 +14,26 @@
package com.google.gerrit.reviewdb;
import java.util.List;
/**
* Additional data about a {@link PatchSet} not normally loaded.
*/
public final class PatchSetInfo {
public static class ParentInfo {
public RevId id;
public String shortMessage;
public ParentInfo(final RevId id, final String shortMessage) {
this.id = id;
this.shortMessage = shortMessage;
}
protected ParentInfo() {
}
}
protected PatchSet.Id key;
/** First line of {@link #message}. */
@ -33,6 +48,9 @@ public final class PatchSetInfo {
/** Identity of who committed the patch set to the VCS. */
protected UserIdentity committer;
/** List of parents of the patch set. */
protected List<ParentInfo> parents;
protected PatchSetInfo() {
}
@ -79,4 +97,12 @@ public final class PatchSetInfo {
public void setCommitter(final UserIdentity u) {
committer = u;
}
public void setParents(final List<ParentInfo> p) {
parents = p;
}
public List<ParentInfo> getParents() {
return parents;
}
}

View File

@ -19,6 +19,7 @@ import com.google.gerrit.reviewdb.Change;
import com.google.gerrit.reviewdb.PatchSet;
import com.google.gerrit.reviewdb.PatchSetInfo;
import com.google.gerrit.reviewdb.Project;
import com.google.gerrit.reviewdb.RevId;
import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gerrit.reviewdb.UserIdentity;
import com.google.gerrit.server.account.AccountByEmailCache;
@ -28,6 +29,7 @@ import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Repository;
@ -36,6 +38,8 @@ import org.eclipse.jgit.revwalk.RevWalk;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@ -81,7 +85,9 @@ public class PatchSetInfoFactory {
try {
final RevCommit src =
rw.parseCommit(ObjectId.fromString(patchSet.getRevision().get()));
return get(src, patchSetId);
PatchSetInfo info = get(src, patchSetId);
info.setParents(toParentInfos(src.getParents(), rw));
return info;
} finally {
rw.release();
}
@ -117,4 +123,17 @@ public class PatchSetInfoFactory {
return u;
}
private List<PatchSetInfo.ParentInfo> toParentInfos(final RevCommit[] parents,
final RevWalk walk) throws IOException, MissingObjectException {
List<PatchSetInfo.ParentInfo> pInfos =
new ArrayList<PatchSetInfo.ParentInfo>(parents.length);
for (RevCommit parent : parents) {
walk.parseBody(parent);
RevId rev = new RevId(parent.getId().name());
String msg = parent.getShortMessage();
pInfos.add(new PatchSetInfo.ParentInfo(rev, msg));
}
return pInfos;
}
}