{"thread":{"id":"19795","subject":"[JGIT PATCH 1/2] Add getLong to RepositoryConfig","startedAt":"2009-06-12T23:23:05Z","lastAt":"2009-06-14T08:49:40Z","messageCount":7,"participants":["Shawn O. Pearce","Ferry Huberts"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"116200","messageId":"1244848986-10526-1-git-send-email-spearce@spearce.org","threadId":"19795","inReplyTo":null,"subject":"[JGIT PATCH 1/2] Add getLong to RepositoryConfig","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-12T23:23:05Z","receivedAt":"2009-06-12T23:23:05Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This supports parsing 64 bit configuration values.  We want to use\nit for values like core.packedGitLimit where a 64 bit JVM may want\nto support a very large value, well past the 2 GiB barrier.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../org/spearce/jgit/lib/RepositoryConfigTest.java |   26 ++++++++++++++++++++\n .../src/org/spearce/jgit/lib/RepositoryConfig.java |   26 ++++++++++++++++++-\n 2 files changed, 50 insertions(+), 2 deletions(-)\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java\nindex ed573e1..5e2328b 100644\n--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java\n@@ -233,6 +233,32 @@ public void testReadBoolean_OnOff2() throws IOException {\n \t\tassertFalse(c.getBoolean(\"s\", \"b\", true));\n \t}\n \n+\tpublic void testReadLong() throws IOException {\n+\t\tassertReadLong(1L);\n+\t\tassertReadLong(-1L);\n+\t\tassertReadLong(Long.MIN_VALUE);\n+\t\tassertReadLong(Long.MAX_VALUE);\n+\t\tassertReadLong(4L * 1024 * 1024 * 1024, \"4g\");\n+\t\tassertReadLong(3L * 1024 * 1024, \"3 m\");\n+\t\tassertReadLong(8L * 1024, \"8 k\");\n+\n+\t\ttry {\n+\t\t\tassertReadLong(-1, \"1.5g\");\n+\t\t\tfail(\"incorrectly accepted 1.5g\");\n+\t\t} catch (IllegalArgumentException e) {\n+\t\t\tassertEquals(\"Invalid integer value: s.a=1.5g\", e.getMessage());\n+\t\t}\n+\t}\n+\n+\tprivate void assertReadLong(long exp) throws IOException {\n+\t\tassertReadLong(exp, String.valueOf(exp));\n+\t}\n+\n+\tprivate void assertReadLong(long exp, String act) throws IOException {\n+\t\tfinal RepositoryConfig c = read(\"[s]\\na = \" + act + \"\\n\");\n+\t\tassertEquals(exp, c.getLong(\"s\", null, \"a\", 0L));\n+\t}\n+\n \tprivate RepositoryConfig read(final String content) throws IOException {\n \t\tfinal File p = writeTrashFile(getName() + \".config\", content);\n \t\tfinal RepositoryConfig c = new RepositoryConfig(null, p);\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java\nindex b816604..a339514 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java\n@@ -183,6 +183,28 @@ public int getInt(final String section, final String name,\n \t */\n \tpublic int getInt(final String section, String subsection,\n \t\t\tfinal String name, final int defaultValue) {\n+\t\tfinal long val = getLong(section, subsection, name, defaultValue);\n+\t\tif (Integer.MIN_VALUE <= val && val <= Integer.MAX_VALUE)\n+\t\t\treturn (int) val;\n+\t\tthrow new IllegalArgumentException(\"Integer value \" + section + \".\"\n+\t\t\t\t+ name + \" out of range\");\n+\t}\n+\n+\t/**\n+\t * Obtain an integer value from the configuration.\n+\t *\n+\t * @param section\n+\t *            section the key is grouped within.\n+\t * @param subsection\n+\t *            subsection name, such a remote or branch name.\n+\t * @param name\n+\t *            name of the key to get.\n+\t * @param defaultValue\n+\t *            default value to return if no value was present.\n+\t * @return an integer value from the configuration, or defaultValue.\n+\t */\n+\tpublic long getLong(final String section, String subsection,\n+\t\t\tfinal String name, final long defaultValue) {\n \t\tfinal String str = getString(section, subsection, name);\n \t\tif (str == null)\n \t\t\treturn defaultValue;\n@@ -191,7 +213,7 @@ public int getInt(final String section, String subsection,\n \t\tif (n.length() == 0)\n \t\t\treturn defaultValue;\n \n-\t\tint mul = 1;\n+\t\tlong mul = 1;\n \t\tswitch (Character.toLowerCase(n.charAt(n.length() - 1))) {\n \t\tcase 'g':\n \t\t\tmul = 1024 * 1024 * 1024;\n@@ -209,7 +231,7 @@ public int getInt(final String section, String subsection,\n \t\t\treturn defaultValue;\n \n \t\ttry {\n-\t\t\treturn mul * Integer.parseInt(n);\n+\t\t\treturn mul * Long.parseLong(n);\n \t\t} catch (NumberFormatException nfe) {\n \t\t\tthrow new IllegalArgumentException(\"Invalid integer value: \"\n \t\t\t\t\t+ section + \".\" + name + \"=\" + str);\n-- \n1.6.3.2.367.gf0de\n"},{"id":"116201","messageId":"1244848986-10526-2-git-send-email-spearce@spearce.org","threadId":"19795","inReplyTo":"1244848986-10526-1-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 2/2] Allow core.packedGitLimit to exceed \"2 g\"","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-12T23:23:06Z","receivedAt":"2009-06-12T23:23:06Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"A 64 bit JVM might actually be able to dedicate more than 2 GiB of\nmemory to the window cache, and on a busy server, this may be an\nideal configuration since JGit can't always reliably use mmap.  By\ntreating the limit as a long we increase our range to 2^63, which\nis far beyond what any JVM heap would be able to actually support.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/lib/WindowCache.java      |   13 +++++++------\n .../org/spearce/jgit/lib/WindowCacheConfig.java    |    8 ++++----\n 2 files changed, 11 insertions(+), 10 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java\nindex 0c60853..b6a35ad 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java\n@@ -41,6 +41,7 @@\n import java.io.IOException;\n import java.lang.ref.ReferenceQueue;\n import java.util.concurrent.atomic.AtomicInteger;\n+import java.util.concurrent.atomic.AtomicLong;\n \n /**\n  * Caches slices of a {@link PackFile} in memory for faster read access.\n@@ -140,7 +141,7 @@ static final void purge(final PackFile pack) {\n \n \tprivate final int maxFiles;\n \n-\tprivate final int maxBytes;\n+\tprivate final long maxBytes;\n \n \tprivate final boolean mmap;\n \n@@ -150,7 +151,7 @@ static final void purge(final PackFile pack) {\n \n \tprivate final AtomicInteger openFiles;\n \n-\tprivate final AtomicInteger openBytes;\n+\tprivate final AtomicLong openBytes;\n \n \tprivate WindowCache(final WindowCacheConfig cfg) {\n \t\tsuper(tableSize(cfg), lockCount(cfg));\n@@ -161,7 +162,7 @@ private WindowCache(final WindowCacheConfig cfg) {\n \t\twindowSize = 1 << windowSizeShift;\n \n \t\topenFiles = new AtomicInteger();\n-\t\topenBytes = new AtomicInteger();\n+\t\topenBytes = new AtomicLong();\n \n \t\tif (maxFiles < 1)\n \t\t\tthrow new IllegalArgumentException(\"Open files must be >= 1\");\n@@ -173,7 +174,7 @@ int getOpenFiles() {\n \t\treturn openFiles.get();\n \t}\n \n-\tint getOpenBytes() {\n+\tlong getOpenBytes() {\n \t\treturn openBytes.get();\n \t}\n \n@@ -233,12 +234,12 @@ private long toStart(final long offset) {\n \n \tprivate static int tableSize(final WindowCacheConfig cfg) {\n \t\tfinal int wsz = cfg.getPackedGitWindowSize();\n-\t\tfinal int limit = cfg.getPackedGitLimit();\n+\t\tfinal long limit = cfg.getPackedGitLimit();\n \t\tif (wsz <= 0)\n \t\t\tthrow new IllegalArgumentException(\"Invalid window size\");\n \t\tif (limit < wsz)\n \t\t\tthrow new IllegalArgumentException(\"Window size must be < limit\");\n-\t\treturn 5 * (limit / wsz) / 2;\n+\t\treturn (int) Math.min(5 * (limit / wsz) / 2, 2000000000);\n \t}\n \n \tprivate static int lockCount(final WindowCacheConfig cfg) {\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCacheConfig.java b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCacheConfig.java\nindex ea28164..97edd3a 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCacheConfig.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCacheConfig.java\n@@ -47,7 +47,7 @@\n \n \tprivate int packedGitOpenFiles;\n \n-\tprivate int packedGitLimit;\n+\tprivate long packedGitLimit;\n \n \tprivate int packedGitWindowSize;\n \n@@ -85,7 +85,7 @@ public void setPackedGitOpenFiles(final int fdLimit) {\n \t * @return maximum number bytes of heap memory to dedicate to caching pack\n \t *         file data. <b>Default is 10 MB.</b>\n \t */\n-\tpublic int getPackedGitLimit() {\n+\tpublic long getPackedGitLimit() {\n \t\treturn packedGitLimit;\n \t}\n \n@@ -94,7 +94,7 @@ public int getPackedGitLimit() {\n \t *            maximum number bytes of heap memory to dedicate to caching\n \t *            pack file data.\n \t */\n-\tpublic void setPackedGitLimit(final int newLimit) {\n+\tpublic void setPackedGitLimit(final long newLimit) {\n \t\tpackedGitLimit = newLimit;\n \t}\n \n@@ -162,7 +162,7 @@ public void setDeltaBaseCacheLimit(final int newLimit) {\n \t */\n \tpublic void fromConfig(final RepositoryConfig rc) {\n \t\tsetPackedGitOpenFiles(rc.getInt(\"core\", null, \"packedgitopenfiles\", getPackedGitOpenFiles()));\n-\t\tsetPackedGitLimit(rc.getInt(\"core\", null, \"packedgitlimit\", getPackedGitLimit()));\n+\t\tsetPackedGitLimit(rc.getLong(\"core\", null, \"packedgitlimit\", getPackedGitLimit()));\n \t\tsetPackedGitWindowSize(rc.getInt(\"core\", null, \"packedgitwindowsize\", getPackedGitWindowSize()));\n \t\tsetPackedGitMMAP(rc.getBoolean(\"core\", null, \"packedgitmmap\", isPackedGitMMAP()));\n \t\tsetDeltaBaseCacheLimit(rc.getInt(\"core\", null, \"deltabasecachelimit\", getDeltaBaseCacheLimit()));\n-- \n1.6.3.2.367.gf0de\n"},{"id":"116216","messageId":"4A335B9A.7080808@pelagic.nl","threadId":"19795","inReplyTo":"1244848986-10526-2-git-send-email-spearce@spearce.org","subject":"Re: [JGIT PATCH 2/2] Allow core.packedGitLimit to exceed \"2 g\"","fromName":"Ferry Huberts","fromEmail":"ferry.huberts@pelagic.nl","sentAt":"2009-06-13T07:56:10Z","receivedAt":"2009-06-13T07:56:10Z","isPatch":true,"sender":{"key":"ferry.huberts@pelagic.nl","avatar":"https://gravatar.com/avatar/9f63c0289ad23cbdef0f7609a0af85ff0f4b3babfd066de9ff58f62d48cfd6f2?d=mp&s=160"},"body":"Shawn O. Pearce wrote:\n> A 64 bit JVM might actually be able to dedicate more than 2 GiB of\n> memory to the window cache, and on a busy server, this may be an\n> ideal configuration since JGit can't always reliably use mmap.  By\n> treating the limit as a long we increase our range to 2^63, which\n> is far beyond what any JVM heap would be able to actually support.\n> \n> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n> ---\n>  .../src/org/spearce/jgit/lib/WindowCache.java      |   13 +++++++------\n>  .../org/spearce/jgit/lib/WindowCacheConfig.java    |    8 ++++----\n>  2 files changed, 11 insertions(+), 10 deletions(-)\n> \n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java\n> index 0c60853..b6a35ad 100644\n> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java\n> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCache.java\n> @@ -41,6 +41,7 @@\n>  import java.io.IOException;\n>  import java.lang.ref.ReferenceQueue;\n>  import java.util.concurrent.atomic.AtomicInteger;\n> +import java.util.concurrent.atomic.AtomicLong;\n>  \n>  /**\n>   * Caches slices of a {@link PackFile} in memory for faster read access.\n> @@ -140,7 +141,7 @@ static final void purge(final PackFile pack) {\n>  \n>  \tprivate final int maxFiles;\n>  \n> -\tprivate final int maxBytes;\n> +\tprivate final long maxBytes;\n>  \n>  \tprivate final boolean mmap;\n>  \n> @@ -150,7 +151,7 @@ static final void purge(final PackFile pack) {\n>  \n>  \tprivate final AtomicInteger openFiles;\n>  \n> -\tprivate final AtomicInteger openBytes;\n> +\tprivate final AtomicLong openBytes;\n>  \n>  \tprivate WindowCache(final WindowCacheConfig cfg) {\n>  \t\tsuper(tableSize(cfg), lockCount(cfg));\n> @@ -161,7 +162,7 @@ private WindowCache(final WindowCacheConfig cfg) {\n>  \t\twindowSize = 1 << windowSizeShift;\n>  \n>  \t\topenFiles = new AtomicInteger();\n> -\t\topenBytes = new AtomicInteger();\n> +\t\topenBytes = new AtomicLong();\n>  \n>  \t\tif (maxFiles < 1)\n>  \t\t\tthrow new IllegalArgumentException(\"Open files must be >= 1\");\n> @@ -173,7 +174,7 @@ int getOpenFiles() {\n>  \t\treturn openFiles.get();\n>  \t}\n>  \n> -\tint getOpenBytes() {\n> +\tlong getOpenBytes() {\n>  \t\treturn openBytes.get();\n>  \t}\n>  \n> @@ -233,12 +234,12 @@ private long toStart(final long offset) {\n>  \n>  \tprivate static int tableSize(final WindowCacheConfig cfg) {\n>  \t\tfinal int wsz = cfg.getPackedGitWindowSize();\n> -\t\tfinal int limit = cfg.getPackedGitLimit();\n> +\t\tfinal long limit = cfg.getPackedGitLimit();\n>  \t\tif (wsz <= 0)\n>  \t\t\tthrow new IllegalArgumentException(\"Invalid window size\");\n>  \t\tif (limit < wsz)\n>  \t\t\tthrow new IllegalArgumentException(\"Window size must be < limit\");\n> -\t\treturn 5 * (limit / wsz) / 2;\n> +\t\treturn (int) Math.min(5 * (limit / wsz) / 2, 2000000000);\n\nMath.min returns a long because the prototype Math.min(long,long) will\nbe chosen. The cast can then overflow and fail. Better change the return\ntype to a long:\n+ return Math.min(5 * (limit / wsz) / 2, 2000000000L);\n\n>  \t}\n>  \n>  \tprivate static int lockCount(final WindowCacheConfig cfg) {\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCacheConfig.java b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCacheConfig.java\n> index ea28164..97edd3a 100644\n> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCacheConfig.java\n> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowCacheConfig.java\n> @@ -47,7 +47,7 @@\n>  \n>  \tprivate int packedGitOpenFiles;\n>  \n> -\tprivate int packedGitLimit;\n> +\tprivate long packedGitLimit;\n>  \n>  \tprivate int packedGitWindowSize;\n>  \n> @@ -85,7 +85,7 @@ public void setPackedGitOpenFiles(final int fdLimit) {\n>  \t * @return maximum number bytes of heap memory to dedicate to caching pack\n>  \t *         file data. <b>Default is 10 MB.</b>\n>  \t */\n> -\tpublic int getPackedGitLimit() {\n> +\tpublic long getPackedGitLimit() {\n>  \t\treturn packedGitLimit;\n>  \t}\n>  \n> @@ -94,7 +94,7 @@ public int getPackedGitLimit() {\n>  \t *            maximum number bytes of heap memory to dedicate to caching\n>  \t *            pack file data.\n>  \t */\n> -\tpublic void setPackedGitLimit(final int newLimit) {\n> +\tpublic void setPackedGitLimit(final long newLimit) {\n>  \t\tpackedGitLimit = newLimit;\n>  \t}\n>  \n> @@ -162,7 +162,7 @@ public void setDeltaBaseCacheLimit(final int newLimit) {\n>  \t */\n>  \tpublic void fromConfig(final RepositoryConfig rc) {\n>  \t\tsetPackedGitOpenFiles(rc.getInt(\"core\", null, \"packedgitopenfiles\", getPackedGitOpenFiles()));\n> -\t\tsetPackedGitLimit(rc.getInt(\"core\", null, \"packedgitlimit\", getPackedGitLimit()));\n> +\t\tsetPackedGitLimit(rc.getLong(\"core\", null, \"packedgitlimit\", getPackedGitLimit()));\n>  \t\tsetPackedGitWindowSize(rc.getInt(\"core\", null, \"packedgitwindowsize\", getPackedGitWindowSize()));\n>  \t\tsetPackedGitMMAP(rc.getBoolean(\"core\", null, \"packedgitmmap\", isPackedGitMMAP()));\n>  \t\tsetDeltaBaseCacheLimit(rc.getInt(\"core\", null, \"deltabasecachelimit\", getDeltaBaseCacheLimit()));\n"},{"id":"116217","messageId":"4A335BD7.60107@pelagic.nl","threadId":"19795","inReplyTo":"1244848986-10526-1-git-send-email-spearce@spearce.org","subject":"Re: [JGIT PATCH 1/2] Add getLong to RepositoryConfig","fromName":"Ferry Huberts","fromEmail":"ferry.huberts@pelagic.nl","sentAt":"2009-06-13T07:57:11Z","receivedAt":"2009-06-13T07:57:11Z","isPatch":true,"sender":{"key":"ferry.huberts@pelagic.nl","avatar":"https://gravatar.com/avatar/9f63c0289ad23cbdef0f7609a0af85ff0f4b3babfd066de9ff58f62d48cfd6f2?d=mp&s=160"},"body":"Shawn O. Pearce wrote:\n> This supports parsing 64 bit configuration values.  We want to use\n> it for values like core.packedGitLimit where a 64 bit JVM may want\n> to support a very large value, well past the 2 GiB barrier.\n> \n> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n> ---\n>  .../org/spearce/jgit/lib/RepositoryConfigTest.java |   26 ++++++++++++++++++++\n>  .../src/org/spearce/jgit/lib/RepositoryConfig.java |   26 ++++++++++++++++++-\n>  2 files changed, 50 insertions(+), 2 deletions(-)\n> \n> diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java\n> index ed573e1..5e2328b 100644\n> --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java\n> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java\n> @@ -233,6 +233,32 @@ public void testReadBoolean_OnOff2() throws IOException {\n>  \t\tassertFalse(c.getBoolean(\"s\", \"b\", true));\n>  \t}\n>  \n> +\tpublic void testReadLong() throws IOException {\n> +\t\tassertReadLong(1L);\n> +\t\tassertReadLong(-1L);\n> +\t\tassertReadLong(Long.MIN_VALUE);\n> +\t\tassertReadLong(Long.MAX_VALUE);\n> +\t\tassertReadLong(4L * 1024 * 1024 * 1024, \"4g\");\n> +\t\tassertReadLong(3L * 1024 * 1024, \"3 m\");\n> +\t\tassertReadLong(8L * 1024, \"8 k\");\n> +\n> +\t\ttry {\n> +\t\t\tassertReadLong(-1, \"1.5g\");\n> +\t\t\tfail(\"incorrectly accepted 1.5g\");\n> +\t\t} catch (IllegalArgumentException e) {\n> +\t\t\tassertEquals(\"Invalid integer value: s.a=1.5g\", e.getMessage());\n> +\t\t}\n> +\t}\n> +\n> +\tprivate void assertReadLong(long exp) throws IOException {\n> +\t\tassertReadLong(exp, String.valueOf(exp));\n> +\t}\n> +\n> +\tprivate void assertReadLong(long exp, String act) throws IOException {\n> +\t\tfinal RepositoryConfig c = read(\"[s]\\na = \" + act + \"\\n\");\n> +\t\tassertEquals(exp, c.getLong(\"s\", null, \"a\", 0L));\n> +\t}\n> +\n>  \tprivate RepositoryConfig read(final String content) throws IOException {\n>  \t\tfinal File p = writeTrashFile(getName() + \".config\", content);\n>  \t\tfinal RepositoryConfig c = new RepositoryConfig(null, p);\n> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java\n> index b816604..a339514 100644\n> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java\n> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java\n> @@ -183,6 +183,28 @@ public int getInt(final String section, final String name,\n>  \t */\n>  \tpublic int getInt(final String section, String subsection,\n>  \t\t\tfinal String name, final int defaultValue) {\n> +\t\tfinal long val = getLong(section, subsection, name, defaultValue);\n> +\t\tif (Integer.MIN_VALUE <= val && val <= Integer.MAX_VALUE)\n> +\t\t\treturn (int) val;\n> +\t\tthrow new IllegalArgumentException(\"Integer value \" + section + \".\"\n> +\t\t\t\t+ name + \" out of range\");\n> +\t}\n> +\n> +\t/**\n> +\t * Obtain an integer value from the configuration.\ns/integer/long/g in this (copy&paste) javadoc part\n\n> +\t *\n> +\t * @param section\n> +\t *            section the key is grouped within.\n> +\t * @param subsection\n> +\t *            subsection name, such a remote or branch name.\n> +\t * @param name\n> +\t *            name of the key to get.\n> +\t * @param defaultValue\n> +\t *            default value to return if no value was present.\n> +\t * @return an integer value from the configuration, or defaultValue.\n> +\t */\n> +\tpublic long getLong(final String section, String subsection,\n> +\t\t\tfinal String name, final long defaultValue) {\n>  \t\tfinal String str = getString(section, subsection, name);\n>  \t\tif (str == null)\n>  \t\t\treturn defaultValue;\n> @@ -191,7 +213,7 @@ public int getInt(final String section, String subsection,\n>  \t\tif (n.length() == 0)\n>  \t\t\treturn defaultValue;\n>  \n> -\t\tint mul = 1;\n> +\t\tlong mul = 1;\n>  \t\tswitch (Character.toLowerCase(n.charAt(n.length() - 1))) {\n>  \t\tcase 'g':\n>  \t\t\tmul = 1024 * 1024 * 1024;\n> @@ -209,7 +231,7 @@ public int getInt(final String section, String subsection,\n>  \t\t\treturn defaultValue;\n>  \n>  \t\ttry {\n> -\t\t\treturn mul * Integer.parseInt(n);\n> +\t\t\treturn mul * Long.parseLong(n);\n>  \t\t} catch (NumberFormatException nfe) {\n>  \t\t\tthrow new IllegalArgumentException(\"Invalid integer value: \"\n>  \t\t\t\t\t+ section + \".\" + name + \"=\" + str);\n"},{"id":"116247","messageId":"20090613191943.GS16497@spearce.org","threadId":"19795","inReplyTo":"4A335B9A.7080808@pelagic.nl","subject":"Re: [JGIT PATCH 2/2] Allow core.packedGitLimit to exceed \"2 g\"","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-13T19:19:43Z","receivedAt":"2009-06-13T19:19:43Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Ferry Huberts <ferry.huberts@pelagic.nl> wrote:\n> Shawn O. Pearce wrote:\n> > A 64 bit JVM might actually be able to dedicate more than 2 GiB of\n\nPlease don't quote everything if you are only replying to a tiny\npart.\n\n> >  \tprivate static int tableSize(final WindowCacheConfig cfg) {\n> >  \t\tfinal int wsz = cfg.getPackedGitWindowSize();\n> > -\t\tfinal int limit = cfg.getPackedGitLimit();\n> > +\t\tfinal long limit = cfg.getPackedGitLimit();\n> >  \t\tif (wsz <= 0)\n> >  \t\t\tthrow new IllegalArgumentException(\"Invalid window size\");\n> >  \t\tif (limit < wsz)\n> >  \t\t\tthrow new IllegalArgumentException(\"Window size must be < limit\");\n> > -\t\treturn 5 * (limit / wsz) / 2;\n> > +\t\treturn (int) Math.min(5 * (limit / wsz) / 2, 2000000000);\n> \n> Math.min returns a long because the prototype Math.min(long,long) will\n> be chosen. The cast can then overflow and fail. Better change the return\n> type to a long:\n> + return Math.min(5 * (limit / wsz) / 2, 2000000000L);\n\nIf you looked at that, 2,000,000,000 is within the range of an int.\nWe select the smallest value.  The first argument expression is\ncomputed as a long, so we shouldn't ever overflow and cause the\nfirst argument to be negative.  If the first argument is larger\nthan 2 billion, then it does risk overflow, but the 2nd argument\nis smaller, so it is returned.\n\nThe code is fine as is.\n \n-- \nShawn.\n"},{"id":"116248","messageId":"20090613192122.GT16497@spearce.org","threadId":"19795","inReplyTo":"4A335BD7.60107@pelagic.nl","subject":"Re: [JGIT PATCH 1/2] Add getLong to RepositoryConfig","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-06-13T19:21:22Z","receivedAt":"2009-06-13T19:21:22Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Ferry Huberts <ferry.huberts@pelagic.nl> wrote:\n> Shawn O. Pearce wrote:\n> > This supports parsing 64 bit configuration values.\n...\n> > +\t/**\n> > +\t * Obtain an integer value from the configuration.\n> s/integer/long/g in this (copy&paste) javadoc part\n\nIts still integer as in from the integer number space, and not say\na floating point decimal.  Thus I didn't bother with this edit,\nI figured the method name was clear enough that it would return\na long, but the concept of it parsing only \"2g\" and not \"1.5g\"\nshould go in the documentation.\n \nAnd again, please trim parts you aren't replying to.\n\n-- \nShawn.\n"},{"id":"116278","messageId":"4A34B9A4.7020702@pelagic.nl","threadId":"19795","inReplyTo":"20090613191943.GS16497@spearce.org","subject":"Re: [JGIT PATCH 2/2] Allow core.packedGitLimit to exceed \"2 g\"","fromName":"Ferry Huberts","fromEmail":"ferry.huberts@pelagic.nl","sentAt":"2009-06-14T08:49:40Z","receivedAt":"2009-06-14T08:49:40Z","isPatch":true,"sender":{"key":"ferry.huberts@pelagic.nl","avatar":"https://gravatar.com/avatar/9f63c0289ad23cbdef0f7609a0af85ff0f4b3babfd066de9ff58f62d48cfd6f2?d=mp&s=160"},"body":"> If you looked at that, 2,000,000,000 is within the range of an int.\n> We select the smallest value.  The first argument expression is\n> computed as a long, so we shouldn't ever overflow and cause the\n> first argument to be negative.  If the first argument is larger\n> than 2 billion, then it does risk overflow, but the 2nd argument\n> is smaller, so it is returned.\n> \n> The code is fine as is.\n>  \n\nI stand corrected :-)\n"}]}