Display the size of a patch (lines added/removed)

In a patch table we now display the number of new lines added or the
number of lines deleted for each file, assuming it is not binary.
Added files only show the total number of lines, while deleted
files show nothing at all.

A new row is added at the bottom of the table that shows the overall
size of the delta.  This can be useful if a project has rules about
how big a patch can be before additional types of review are required
(e.g. Eclipse based projects).

Bug: issue 499
Change-Id: I961d8fac3f5d82a5d24f0a4d0b0a9ddf39182a50
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2010-08-21 19:04:56 -07:00
parent b6adfc74c3
commit d4b2787ed3
13 changed files with 169 additions and 8 deletions

View File

@@ -145,6 +145,7 @@ public interface GerritCss extends CssResource {
String patchSetLink();
String patchSetRevision();
String patchSetUserIdentity();
String patchSizeCell();
String permalink();
String posscore();
String projectAdminApprovalCategoryRangeLine();

View File

@@ -54,6 +54,7 @@ public interface ChangeConstants extends Constants {
String patchTableColumnName();
String patchTableColumnComments();
String patchTableColumnSize();
String patchTableColumnDiff();
String patchTableDiffSideBySide();
String patchTableDiffUnified();

View File

@@ -34,6 +34,7 @@ keyPublishComments = Review and publish comments
patchTableColumnName = File Path
patchTableColumnComments = Comments
patchTableColumnSize = Size
patchTableColumnDiff = Diff
patchTableDiffSideBySide = Side-by-Side
patchTableDiffUnified = Unified

View File

@@ -31,6 +31,8 @@ public interface ChangeMessages extends Messages {
String patchTableComments(@PluralCount int count);
String patchTableDrafts(@PluralCount int count);
String patchTableSize_Modify(int insertions, int deletions);
String patchTableSize_Lines(@PluralCount int insertions);
String removeReviewer(String fullName);
String messageWrittenOn(String date);

View File

@@ -12,6 +12,8 @@ submitPatchSet = Submit Patch Set {0}
patchTableComments = {0} comments
patchTableDrafts = {0} drafts
patchTableSize_Modify = +{0}, -{1}
patchTableSize_Lines = {0} lines
removeReviewer = Remove reviewer {0}
messageWrittenOn = on {0}

View File

@@ -3,3 +3,6 @@ patchTableComments = {0} comments
patchTableDrafts[one] = 1 draft
patchTableDrafts = {0} drafts
patchTableSize_Lines[one] = 1 line
patchTableSize_Lines = {0} lines

View File

@@ -22,6 +22,7 @@ import com.google.gerrit.client.ui.PatchLink;
import com.google.gerrit.common.data.PatchSetDetail;
import com.google.gerrit.reviewdb.Patch;
import com.google.gerrit.reviewdb.Patch.Key;
import com.google.gerrit.reviewdb.Patch.PatchType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
@@ -242,7 +243,8 @@ public class PatchTable extends Composite {
private class MyTable extends NavigationTable<Patch> {
private static final int C_PATH = 2;
private static final int C_DRAFT = 3;
private static final int C_SIDEBYSIDE = 4;
private static final int C_SIZE = 4;
private static final int C_SIDEBYSIDE = 5;
private int activeRow = -1;
MyTable() {
@@ -404,6 +406,12 @@ public class PatchTable extends Composite {
m.append(Util.C.patchTableColumnComments());
m.closeTd();
// "Size"
m.openTd();
m.setStyleName(Gerrit.RESOURCES.css().dataHeader());
m.append(Util.C.patchTableColumnSize());
m.closeTd();
// "Diff"
m.openTd();
m.setStyleName(Gerrit.RESOURCES.css().dataHeader());
@@ -452,6 +460,12 @@ public class PatchTable extends Composite {
appendCommentCount(m, p);
m.closeTd();
m.openTd();
m.addStyleName(Gerrit.RESOURCES.css().dataCell());
m.addStyleName(Gerrit.RESOURCES.css().patchSizeCell());
appendSize(m, p);
m.closeTd();
switch (p.getPatchType()) {
case UNIFIED:
openlink(m, 2);
@@ -513,6 +527,29 @@ public class PatchTable extends Composite {
m.closeTr();
}
void appendTotals(final SafeHtmlBuilder m, int ins, int dels) {
m.openTr();
m.openTd();
m.addStyleName(Gerrit.RESOURCES.css().iconCell());
m.addStyleName(Gerrit.RESOURCES.css().noborder());
m.nbsp();
m.closeTd();
m.openTd();
m.setAttribute("colspan", C_SIZE - 1);
m.closeTd();
m.openTd();
m.addStyleName(Gerrit.RESOURCES.css().dataCell());
m.addStyleName(Gerrit.RESOURCES.css().patchSizeCell());
m.addStyleName(Gerrit.RESOURCES.css().leftMostCell());
m.append(Util.M.patchTableSize_Modify(ins, dels));
m.closeTd();
m.closeTr();
}
void appendCommentCount(final SafeHtmlBuilder m, final Patch p) {
if (p.getCommentCount() > 0) {
m.append(Util.M.patchTableComments(p.getCommentCount()));
@@ -528,6 +565,34 @@ public class PatchTable extends Composite {
}
}
void appendSize(final SafeHtmlBuilder m, final Patch p) {
if (Patch.COMMIT_MSG.equals(p.getFileName())) {
m.nbsp();
return;
}
if (p.getPatchType() == PatchType.UNIFIED) {
int ins = p.getInsertions();
int dels = p.getDeletions();
switch (p.getChangeType()) {
case ADDED:
m.append(Util.M.patchTableSize_Lines(ins));
break;
case DELETED:
m.nbsp();
break;
case MODIFIED:
case COPIED:
case RENAMED:
m.append(Util.M.patchTableSize_Modify(ins, dels));
break;
}
} else {
m.nbsp();
}
}
private void openlink(final SafeHtmlBuilder m, final int colspan) {
m.openTd();
m.addStyleName(Gerrit.RESOURCES.css().dataCell());
@@ -599,6 +664,9 @@ public class PatchTable extends Composite {
private double start;
private ProgressBar meter;
private int insertions;
private int deletions;
private DisplayCommand(final List<Patch> list) {
this.table = new MyTable();
this.list = list;
@@ -627,14 +695,19 @@ public class PatchTable extends Composite {
case 0:
if (row == 0) {
table.appendHeader(nc);
table.appendRow(nc, list.get(row++));
}
while (row < list.size()) {
table.appendRow(nc, list.get(row));
Patch p = list.get(row);
insertions += p.getInsertions();
deletions += p.getDeletions();
table.appendRow(nc, p);
if ((++row % 10) == 0 && longRunning()) {
updateMeter();
return true;
}
}
table.appendTotals(nc, insertions, deletions);
table.resetHtml(nc);
nc = null;
stage = 1;

View File

@@ -415,6 +415,14 @@
color: #ff5555;
}
.changeTable .patchSizeCell {
text-align: right;
white-space: nowrap;
}
.changeTable td.noborder {
border: none;
}
.changeTable .filePathCell {
white-space: nowrap;
}

View File

@@ -118,7 +118,7 @@ public abstract class NavigationTable<RowItem> extends FancyFlexTable<RowItem> {
row++;
} else if (sEnd < cTop) {
row--;
} else if (getRowItem(row) != null) {
} else {
break;
}
}