From: Ferry Huberts <ferry.huberts@pelagic•nl>
To: "Shawn O. Pearce" <spearce@spearce•org>
Cc: Robin Rosenberg <robin.rosenberg@dewire•com>, git@vger•kernel.org
Subject: Re: [JGIT PATCH 1/2] Add getLong to RepositoryConfig
Date: Sat, 13 Jun 2009 09:57:11 +0200 [thread overview]
Message-ID: <4A335BD7.60107@pelagic.nl> (raw)
In-Reply-To: <1244848986-10526-1-git-send-email-spearce@spearce.org>
Shawn O. Pearce wrote:
> This supports parsing 64 bit configuration values. We want to use
> it for values like core.packedGitLimit where a 64 bit JVM may want
> to support a very large value, well past the 2 GiB barrier.
>
> Signed-off-by: Shawn O. Pearce <spearce@spearce•org>
> ---
> .../org/spearce/jgit/lib/RepositoryConfigTest.java | 26 ++++++++++++++++++++
> .../src/org/spearce/jgit/lib/RepositoryConfig.java | 26 ++++++++++++++++++-
> 2 files changed, 50 insertions(+), 2 deletions(-)
>
> 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
> index ed573e1..5e2328b 100644
> --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java
> +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java
> @@ -233,6 +233,32 @@ public void testReadBoolean_OnOff2() throws IOException {
> assertFalse(c.getBoolean("s", "b", true));
> }
>
> + public void testReadLong() throws IOException {
> + assertReadLong(1L);
> + assertReadLong(-1L);
> + assertReadLong(Long.MIN_VALUE);
> + assertReadLong(Long.MAX_VALUE);
> + assertReadLong(4L * 1024 * 1024 * 1024, "4g");
> + assertReadLong(3L * 1024 * 1024, "3 m");
> + assertReadLong(8L * 1024, "8 k");
> +
> + try {
> + assertReadLong(-1, "1.5g");
> + fail("incorrectly accepted 1.5g");
> + } catch (IllegalArgumentException e) {
> + assertEquals("Invalid integer value: s.a=1.5g", e.getMessage());
> + }
> + }
> +
> + private void assertReadLong(long exp) throws IOException {
> + assertReadLong(exp, String.valueOf(exp));
> + }
> +
> + private void assertReadLong(long exp, String act) throws IOException {
> + final RepositoryConfig c = read("[s]\na = " + act + "\n");
> + assertEquals(exp, c.getLong("s", null, "a", 0L));
> + }
> +
> private RepositoryConfig read(final String content) throws IOException {
> final File p = writeTrashFile(getName() + ".config", content);
> final RepositoryConfig c = new RepositoryConfig(null, p);
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
> index b816604..a339514 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
> @@ -183,6 +183,28 @@ public int getInt(final String section, final String name,
> */
> public int getInt(final String section, String subsection,
> final String name, final int defaultValue) {
> + final long val = getLong(section, subsection, name, defaultValue);
> + if (Integer.MIN_VALUE <= val && val <= Integer.MAX_VALUE)
> + return (int) val;
> + throw new IllegalArgumentException("Integer value " + section + "."
> + + name + " out of range");
> + }
> +
> + /**
> + * Obtain an integer value from the configuration.
s/integer/long/g in this (copy&paste) javadoc part
> + *
> + * @param section
> + * section the key is grouped within.
> + * @param subsection
> + * subsection name, such a remote or branch name.
> + * @param name
> + * name of the key to get.
> + * @param defaultValue
> + * default value to return if no value was present.
> + * @return an integer value from the configuration, or defaultValue.
> + */
> + public long getLong(final String section, String subsection,
> + final String name, final long defaultValue) {
> final String str = getString(section, subsection, name);
> if (str == null)
> return defaultValue;
> @@ -191,7 +213,7 @@ public int getInt(final String section, String subsection,
> if (n.length() == 0)
> return defaultValue;
>
> - int mul = 1;
> + long mul = 1;
> switch (Character.toLowerCase(n.charAt(n.length() - 1))) {
> case 'g':
> mul = 1024 * 1024 * 1024;
> @@ -209,7 +231,7 @@ public int getInt(final String section, String subsection,
> return defaultValue;
>
> try {
> - return mul * Integer.parseInt(n);
> + return mul * Long.parseLong(n);
> } catch (NumberFormatException nfe) {
> throw new IllegalArgumentException("Invalid integer value: "
> + section + "." + name + "=" + str);
next prev parent reply other threads:[~2009-06-13 7:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-12 23:23 [JGIT PATCH 1/2] Add getLong to RepositoryConfig Shawn O. Pearce
2009-06-12 23:23 ` [JGIT PATCH 2/2] Allow core.packedGitLimit to exceed "2 g" Shawn O. Pearce
2009-06-13 7:56 ` Ferry Huberts
2009-06-13 19:19 ` Shawn O. Pearce
2009-06-14 8:49 ` Ferry Huberts
2009-06-13 7:57 ` Ferry Huberts [this message]
2009-06-13 19:21 ` [JGIT PATCH 1/2] Add getLong to RepositoryConfig Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A335BD7.60107@pelagic.nl \
--to=ferry.huberts@pelagic$(echo .)nl \
--cc=git@vger$(echo .)kernel.org \
--cc=robin.rosenberg@dewire$(echo .)com \
--cc=spearce@spearce$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox