Show for binary files the file size increase/decrease as percentage
Change-Id: I2003eb427141ed4bf72254659210f1c7b5e7dcdf Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -34,6 +34,11 @@ public class FileInfo extends JavaScriptObject {
|
|||||||
// JSNI methods cannot have 'long' as a parameter type or a return type and
|
// JSNI methods cannot have 'long' as a parameter type or a return type and
|
||||||
// it's suggested to use double in this case:
|
// it's suggested to use double in this case:
|
||||||
// http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#important
|
// http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html#important
|
||||||
|
public final long size() {
|
||||||
|
return (long)_size();
|
||||||
|
}
|
||||||
|
private final native double _size() /*-{ return this.size || 0; }-*/;
|
||||||
|
|
||||||
public final long sizeDelta() {
|
public final long sizeDelta() {
|
||||||
return (long)_sizeDelta();
|
return (long)_sizeDelta();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.client;
|
package com.google.gerrit.client;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.change.Resources;
|
||||||
import com.google.gerrit.client.info.AccountInfo;
|
import com.google.gerrit.client.info.AccountInfo;
|
||||||
import com.google.gerrit.client.info.AccountPreferencesInfo;
|
import com.google.gerrit.client.info.AccountPreferencesInfo;
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
@@ -134,4 +135,19 @@ public class FormatUtil {
|
|||||||
+ NumberFormat.getFormat("#.0").format(bytes / Math.pow(1024, exp))
|
+ NumberFormat.getFormat("#.0").format(bytes / Math.pow(1024, exp))
|
||||||
+ " " + "KMGTPE".charAt(exp - 1) + "iB";
|
+ " " + "KMGTPE".charAt(exp - 1) + "iB";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String formatPercentage(long size, long delta) {
|
||||||
|
if (size == 0) {
|
||||||
|
return Resources.C.notAvailable();
|
||||||
|
}
|
||||||
|
return (delta > 0 ? "+" : "-") + formatAbsPercentage(size, delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String formatAbsPercentage(long size, long delta) {
|
||||||
|
if (size == 0) {
|
||||||
|
return Resources.C.notAvailable();
|
||||||
|
}
|
||||||
|
int p = Math.abs(Math.round(delta * 100 / size));
|
||||||
|
return p + "%";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ package com.google.gerrit.client.change;
|
|||||||
|
|
||||||
import com.google.gwt.i18n.client.Constants;
|
import com.google.gwt.i18n.client.Constants;
|
||||||
|
|
||||||
interface ChangeConstants extends Constants {
|
public interface ChangeConstants extends Constants {
|
||||||
String previousChange();
|
String previousChange();
|
||||||
String nextChange();
|
String nextChange();
|
||||||
String openChange();
|
String openChange();
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ package com.google.gerrit.client.change;
|
|||||||
|
|
||||||
import static com.google.gerrit.client.FormatUtil.formatAbsBytes;
|
import static com.google.gerrit.client.FormatUtil.formatAbsBytes;
|
||||||
import static com.google.gerrit.client.FormatUtil.formatBytes;
|
import static com.google.gerrit.client.FormatUtil.formatBytes;
|
||||||
|
import static com.google.gerrit.client.FormatUtil.formatPercentage;
|
||||||
|
import static com.google.gerrit.client.FormatUtil.formatAbsPercentage;
|
||||||
|
|
||||||
import com.google.gerrit.client.Dispatcher;
|
import com.google.gerrit.client.Dispatcher;
|
||||||
import com.google.gerrit.client.Gerrit;
|
import com.google.gerrit.client.Gerrit;
|
||||||
@@ -464,6 +466,7 @@ public class FileTable extends FlowPanel {
|
|||||||
private boolean hasNonBinaryFile;
|
private boolean hasNonBinaryFile;
|
||||||
private int inserted;
|
private int inserted;
|
||||||
private int deleted;
|
private int deleted;
|
||||||
|
private long binOldSize;
|
||||||
private long bytesInserted;
|
private long bytesInserted;
|
||||||
private long bytesDeleted;
|
private long bytesDeleted;
|
||||||
|
|
||||||
@@ -520,6 +523,7 @@ public class FileTable extends FlowPanel {
|
|||||||
private void computeInsertedDeleted() {
|
private void computeInsertedDeleted() {
|
||||||
inserted = 0;
|
inserted = 0;
|
||||||
deleted = 0;
|
deleted = 0;
|
||||||
|
binOldSize = 0;
|
||||||
bytesInserted = 0;
|
bytesInserted = 0;
|
||||||
bytesDeleted = 0;
|
bytesDeleted = 0;
|
||||||
for (int i = 0; i < list.length(); i++) {
|
for (int i = 0; i < list.length(); i++) {
|
||||||
@@ -531,6 +535,7 @@ public class FileTable extends FlowPanel {
|
|||||||
deleted += info.linesDeleted();
|
deleted += info.linesDeleted();
|
||||||
} else {
|
} else {
|
||||||
hasBinaryFile = true;
|
hasBinaryFile = true;
|
||||||
|
binOldSize += info.size() - info.sizeDelta();
|
||||||
if (info.sizeDelta() >= 0) {
|
if (info.sizeDelta() >= 0) {
|
||||||
bytesInserted += info.sizeDelta();
|
bytesInserted += info.sizeDelta();
|
||||||
} else {
|
} else {
|
||||||
@@ -771,6 +776,12 @@ public class FileTable extends FlowPanel {
|
|||||||
}
|
}
|
||||||
} else if (info.binary()) {
|
} else if (info.binary()) {
|
||||||
sb.append(formatBytes(info.sizeDelta()));
|
sb.append(formatBytes(info.sizeDelta()));
|
||||||
|
long oldSize = info.size() - info.sizeDelta();
|
||||||
|
if (oldSize != 0) {
|
||||||
|
sb.append(" (")
|
||||||
|
.append(formatPercentage(oldSize, info.sizeDelta()))
|
||||||
|
.append(")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sb.closeTd();
|
sb.closeTd();
|
||||||
}
|
}
|
||||||
@@ -827,8 +838,17 @@ public class FileTable extends FlowPanel {
|
|||||||
if (hasNonBinaryFile) {
|
if (hasNonBinaryFile) {
|
||||||
sb.br();
|
sb.br();
|
||||||
}
|
}
|
||||||
sb.append(Util.M.patchTableSize_ModifyBinaryFiles(
|
if (binOldSize != 0) {
|
||||||
formatAbsBytes(bytesInserted), formatAbsBytes(bytesDeleted)));
|
sb.append(Util.M.patchTableSize_ModifyBinaryFilesWithPercentages(
|
||||||
|
formatAbsBytes(bytesInserted),
|
||||||
|
formatAbsPercentage(binOldSize, bytesInserted),
|
||||||
|
formatAbsBytes(bytesDeleted),
|
||||||
|
formatAbsPercentage(binOldSize, bytesDeleted)));
|
||||||
|
} else {
|
||||||
|
sb.append(Util.M.patchTableSize_ModifyBinaryFiles(
|
||||||
|
formatAbsBytes(bytesInserted),
|
||||||
|
formatAbsBytes(bytesDeleted)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sb.closeTh();
|
sb.closeTh();
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ public interface ChangeMessages extends Messages {
|
|||||||
String patchTableSize_Modify(int insertions, int deletions);
|
String patchTableSize_Modify(int insertions, int deletions);
|
||||||
String patchTableSize_ModifyBinaryFiles(String bytesInserted,
|
String patchTableSize_ModifyBinaryFiles(String bytesInserted,
|
||||||
String bytesDeleted);
|
String bytesDeleted);
|
||||||
|
String patchTableSize_ModifyBinaryFilesWithPercentages(String bytesInserted,
|
||||||
|
String percentageInserted, String bytesDeleted, String percentageDeleted);
|
||||||
String patchTableSize_LongModify(int insertions, int deletions);
|
String patchTableSize_LongModify(int insertions, int deletions);
|
||||||
String patchTableSize_Lines(@PluralCount int insertions);
|
String patchTableSize_Lines(@PluralCount int insertions);
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ patchTableComments = {0} comments
|
|||||||
patchTableDrafts = {0} drafts
|
patchTableDrafts = {0} drafts
|
||||||
patchTableSize_Modify = +{0}, -{1}
|
patchTableSize_Modify = +{0}, -{1}
|
||||||
patchTableSize_ModifyBinaryFiles = +{0}, -{1}
|
patchTableSize_ModifyBinaryFiles = +{0}, -{1}
|
||||||
|
patchTableSize_ModifyBinaryFilesWithPercentages = +{0} (+{1}), -{2} (-{3})
|
||||||
patchTableSize_LongModify = {0} inserted, {1} deleted
|
patchTableSize_LongModify = {0} inserted, {1} deleted
|
||||||
patchTableSize_Lines = {0} lines
|
patchTableSize_Lines = {0} lines
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
package com.google.gerrit.client;
|
package com.google.gerrit.client;
|
||||||
|
|
||||||
import static com.google.gerrit.client.FormatUtil.formatBytes;
|
import static com.google.gerrit.client.FormatUtil.formatBytes;
|
||||||
|
import static com.google.gerrit.client.FormatUtil.formatPercentage;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import com.googlecode.gwt.test.GwtModule;
|
import com.googlecode.gwt.test.GwtModule;
|
||||||
@@ -45,4 +46,17 @@ public class FormatUtilTest extends GwtTest {
|
|||||||
assertEquals("-27 B", formatBytes(-27));
|
assertEquals("-27 B", formatBytes(-27));
|
||||||
assertEquals("-1.7 MiB", formatBytes(-1728));
|
assertEquals("-1.7 MiB", formatBytes(-1728));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFormatPercentage() {
|
||||||
|
assertEquals("N/A", formatPercentage(0, 10));
|
||||||
|
assertEquals("0%", formatPercentage(100, 0));
|
||||||
|
assertEquals("+25%", formatPercentage(100, 25));
|
||||||
|
assertEquals("-25%", formatPercentage(100, -25));
|
||||||
|
assertEquals("+50%", formatPercentage(100, 50));
|
||||||
|
assertEquals("-50%", formatPercentage(100, -50));
|
||||||
|
assertEquals("+100%", formatPercentage(100, 100));
|
||||||
|
assertEquals("-100%", formatPercentage(100, -100));
|
||||||
|
assertEquals("+500%", formatPercentage(100, 500));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user