Merge "ChangeScreen: Show total binary increase/decrease in file table"
This commit is contained in:
commit
fb83532cb3
@ -109,17 +109,28 @@ public class FormatUtil {
|
||||
return new AccountFormatter(Gerrit.info().user().anonymousCowardName());
|
||||
}
|
||||
|
||||
/** The returned format string doesn't contain any +/- sign. */
|
||||
public static String formatAbsBytes(long bytes) {
|
||||
return formatBytes(bytes, true);
|
||||
}
|
||||
|
||||
public static String formatBytes(long bytes) {
|
||||
return formatBytes(bytes, false);
|
||||
}
|
||||
|
||||
private static String formatBytes(long bytes, boolean abs) {
|
||||
bytes = abs ? Math.abs(bytes) : bytes;
|
||||
|
||||
if (bytes == 0) {
|
||||
return "+/- 0 B";
|
||||
return abs ? "0 B" : "+/- 0 B";
|
||||
}
|
||||
|
||||
if (Math.abs(bytes) < 1024) {
|
||||
return (bytes > 0 ? "+" : "") + bytes + " B";
|
||||
return (bytes > 0 && !abs ? "+" : "") + bytes + " B";
|
||||
}
|
||||
|
||||
int exp = (int) (Math.log(Math.abs(bytes)) / Math.log(1024));
|
||||
return (bytes > 0 ? "+" : "")
|
||||
return (bytes > 0 && !abs ? "+" : "")
|
||||
+ NumberFormat.getFormat("#.0").format(bytes / Math.pow(1024, exp))
|
||||
+ " " + "KMGTPE".charAt(exp - 1) + "iB";
|
||||
}
|
||||
|
@ -14,8 +14,10 @@
|
||||
|
||||
package com.google.gerrit.client.change;
|
||||
|
||||
import static com.google.gerrit.client.FormatUtil.formatAbsBytes;
|
||||
import static com.google.gerrit.client.FormatUtil.formatBytes;
|
||||
|
||||
import com.google.gerrit.client.Dispatcher;
|
||||
import com.google.gerrit.client.FormatUtil;
|
||||
import com.google.gerrit.client.Gerrit;
|
||||
import com.google.gerrit.client.VoidResult;
|
||||
import com.google.gerrit.client.changes.ChangeApi;
|
||||
@ -458,8 +460,12 @@ public class FileTable extends FlowPanel {
|
||||
private ProgressBar meter;
|
||||
private String lastPath = "";
|
||||
|
||||
private boolean hasBinaryFile;
|
||||
private boolean hasNonBinaryFile;
|
||||
private int inserted;
|
||||
private int deleted;
|
||||
private long bytesInserted;
|
||||
private long bytesDeleted;
|
||||
|
||||
private DisplayCommand(NativeMap<FileInfo> map,
|
||||
JsArray<FileInfo> list,
|
||||
@ -514,11 +520,23 @@ public class FileTable extends FlowPanel {
|
||||
private void computeInsertedDeleted() {
|
||||
inserted = 0;
|
||||
deleted = 0;
|
||||
bytesInserted = 0;
|
||||
bytesDeleted = 0;
|
||||
for (int i = 0; i < list.length(); i++) {
|
||||
FileInfo info = list.get(i);
|
||||
if (!Patch.COMMIT_MSG.equals(info.path()) && !info.binary()) {
|
||||
if (!Patch.COMMIT_MSG.equals(info.path())) {
|
||||
if (!info.binary()) {
|
||||
hasNonBinaryFile = true;
|
||||
inserted += info.linesInserted();
|
||||
deleted += info.linesDeleted();
|
||||
} else {
|
||||
hasBinaryFile = true;
|
||||
if (info.sizeDelta() >= 0) {
|
||||
bytesInserted += info.sizeDelta();
|
||||
} else {
|
||||
bytesDeleted += info.sizeDelta();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -752,7 +770,7 @@ public class FileTable extends FlowPanel {
|
||||
}
|
||||
}
|
||||
} else if (info.binary()) {
|
||||
sb.append(FormatUtil.formatBytes(info.sizeDelta()));
|
||||
sb.append(formatBytes(info.sizeDelta()));
|
||||
}
|
||||
sb.closeTd();
|
||||
}
|
||||
@ -801,9 +819,18 @@ public class FileTable extends FlowPanel {
|
||||
sb.openTd().setAttribute("colspan", 3).closeTd(); // comments
|
||||
|
||||
// delta1
|
||||
sb.openTh().setStyleName(R.css().deltaColumn1())
|
||||
.append(Util.M.patchTableSize_Modify(inserted, deleted))
|
||||
.closeTh();
|
||||
sb.openTh().setStyleName(R.css().deltaColumn1());
|
||||
if (hasNonBinaryFile) {
|
||||
sb.append(Util.M.patchTableSize_Modify(inserted, deleted));
|
||||
}
|
||||
if (hasBinaryFile) {
|
||||
if (hasNonBinaryFile) {
|
||||
sb.br();
|
||||
}
|
||||
sb.append(Util.M.patchTableSize_ModifyBinaryFiles(
|
||||
formatAbsBytes(bytesInserted), formatAbsBytes(bytesDeleted)));
|
||||
}
|
||||
sb.closeTh();
|
||||
|
||||
// delta2
|
||||
sb.openTh().setStyleName(R.css().deltaColumn2());
|
||||
|
@ -75,7 +75,7 @@
|
||||
|
||||
.deltaColumn1 {
|
||||
white-space: nowrap;
|
||||
text-align: right;
|
||||
text-align: right !important;
|
||||
}
|
||||
|
||||
.deltaColumn2 {
|
||||
|
@ -34,6 +34,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_ModifyBinaryFiles(String bytesInserted,
|
||||
String bytesDeleted);
|
||||
String patchTableSize_LongModify(int insertions, int deletions);
|
||||
String patchTableSize_Lines(@PluralCount int insertions);
|
||||
|
||||
|
@ -17,6 +17,7 @@ submitPatchSet = Submit Patch Set {0}
|
||||
patchTableComments = {0} comments
|
||||
patchTableDrafts = {0} drafts
|
||||
patchTableSize_Modify = +{0}, -{1}
|
||||
patchTableSize_ModifyBinaryFiles = +{0}, -{1}
|
||||
patchTableSize_LongModify = {0} inserted, {1} deleted
|
||||
patchTableSize_Lines = {0} lines
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user