If the value is less than the unit's minimum value, we don't want to store the value with the unit suffix, but instead must try the next lower unit's value. Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx> --- .../src/org/spearce/jgit/lib/Config.java | 24 +++++++++++-------- 1 files changed, 14 insertions(+), 10 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java index 6fbdab9..20f42c4 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java @@ -60,6 +60,10 @@ * file. */ public abstract class Config { + private static final long KiB = 1024; + private static final long MiB = 1024 * KiB; + private static final long GiB = 1024 * MiB; + private boolean fileRead; private List<Entry> entries; @@ -230,13 +234,13 @@ public long getLong(final String section, String subsection, long mul = 1; switch (Character.toLowerCase(n.charAt(n.length() - 1))) { case 'g': - mul = 1024 * 1024 * 1024; + mul = GiB; break; case 'm': - mul = 1024 * 1024; + mul = MiB; break; case 'k': - mul = 1024; + mul = KiB; break; } if (mul > 1) @@ -473,13 +477,13 @@ public void setInt(final String section, final String subsection, public void setLong(final String section, final String subsection, final String name, final long value) { final String s; - - if ((value % (1024 * 1024 * 1024)) == 0) - s = String.valueOf(value / (1024 * 1024 * 1024)) + " g"; - else if ((value % (1024 * 1024)) == 0) - s = String.valueOf(value / (1024 * 1024)) + " m"; - else if ((value % 1024) == 0) - s = String.valueOf(value / 1024) + " k"; + + if (value >= GiB && (value % GiB) == 0) + s = String.valueOf(value / GiB) + " g"; + else if (value >= MiB && (value % MiB) == 0) + s = String.valueOf(value / MiB) + " m"; + else if (value >= KiB && (value % KiB) == 0) + s = String.valueOf(value / KiB) + " k"; else s = String.valueOf(value); -- 1.6.4.rc1.186.g60aa0c -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html