From: Robin Rosenberg <robin.rosenberg@dewire.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: git@vger.kernel.org
Subject: Re: [JGIT PATCH 11/12] Cleanup Config's MAGIC_EMPTY_VALUE to be more safe
Date: Tue, 21 Jul 2009 23:51:21 +0200 [thread overview]
Message-ID: <200907212351.21760.robin.rosenberg@dewire.com> (raw)
In-Reply-To: <1248207570-13880-12-git-send-email-spearce@spearce.org>
tisdag 21 juli 2009 22:19:29 skrev "Shawn O. Pearce" <spearce@spearce.org>:
> The magic value "%%magic%%empty%%" is just too magic; if it ever
> did appear as a value in a key string Config would have treated
> it as a true value instead of as a string value. We also had to
> special case conversions of it to the empty string in a string
> context. Instead we create a special String object using the
> empty string as a template, and use reference equality against
> that to indicate the magic empty value.
>
> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
> ---
> .../src/org/spearce/jgit/lib/Config.java | 28 +++++++++----------
> 1 files changed, 13 insertions(+), 15 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 974ffea..e4528b1 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
> @@ -76,9 +76,14 @@
> private Map<String, Object> byName;
>
> /**
> - * Magic value indicating a missing entry
> + * Magic value indicating a missing entry.
> + * <p>
> + * This value is tested for reference equality in some contexts, so we
> + * must ensure it is a special copy of the empty string. It also must
> + * be treated like the empty string.
> */
> - private static final String MAGIC_EMPTY_VALUE = "%%magic%%empty%%";
> + private static final String MAGIC_EMPTY_VALUE = new StringBuilder(0)
> + .toString();
Can we be sure an implementation doesn't "optimize" toString() here? But an
explicit new String() shouldn't be..?
-- robin
> /**
> * The constructor for configuration file
> @@ -293,7 +298,7 @@ public boolean getBoolean(final String section, String subsection,
> if (n == null)
> return defaultValue;
>
> - if (MAGIC_EMPTY_VALUE.equals(n) || "yes".equalsIgnoreCase(n)
> + if (MAGIC_EMPTY_VALUE == n || "yes".equalsIgnoreCase(n)
> || "true".equalsIgnoreCase(n) || "1".equals(n)
> || "on".equalsIgnoreCase(n)) {
> return true;
> @@ -321,11 +326,7 @@ public boolean getBoolean(final String section, String subsection,
> */
> public String getString(final String section, String subsection,
> final String name) {
> - String val = getRawString(section, subsection, name);
> - if (MAGIC_EMPTY_VALUE.equals(val)) {
> - return "";
> - }
> - return val;
> + return getRawString(section, subsection, name);
> }
>
> /**
> @@ -345,16 +346,13 @@ public String getString(final String section, String subsection,
> if (o instanceof List) {
> final List lst = (List) o;
> final String[] r = new String[lst.size()];
> - for (int i = 0; i < r.length; i++) {
> - final String val = ((Entry) lst.get(i)).value;
> - r[i] = MAGIC_EMPTY_VALUE.equals(val) ? "" : val;
> - }
> + for (int i = 0; i < r.length; i++)
> + r[i] = ((Entry) lst.get(i)).value;
> return r;
> }
>
> if (o instanceof Entry) {
> - final String val = ((Entry) o).value;
> - return new String[] { MAGIC_EMPTY_VALUE.equals(val) ? "" : val };
> + return new String[] { ((Entry) o).value };
> }
>
> if (baseConfig != null)
> @@ -700,7 +698,7 @@ protected void printConfig(final PrintWriter r) {
> }
> r.print(e.name);
> if (e.value != null) {
> - if (!MAGIC_EMPTY_VALUE.equals(e.value)) {
> + if (MAGIC_EMPTY_VALUE != e.value) {
> r.print(" = ");
> r.print(escapeValue(e.value));
> }
next prev parent reply other threads:[~2009-07-21 21:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-21 20:19 [JGIT PATCH 00/12] Cleanup Config class Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 01/12] Use NB.readFully(File) to slurp complete file contents Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 02/12] Correct name of fileRead member of Config class Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 03/12] Add setLong to Config Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 04/12] Fix Config setInt(..., 0) to store "0" not "0 g" Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 05/12] Rename Config.unsetString to just unset() Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 06/12] Remove pointless null assignments in Config Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 07/12] Clarify section and subsection values in Config code Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 08/12] Don't subclass PrintWriter when writing the Config Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 09/12] Use a Java 5 style iteration over the Config entries list Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 10/12] Match config subsection names using case sensitive search Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 11/12] Cleanup Config's MAGIC_EMPTY_VALUE to be more safe Shawn O. Pearce
2009-07-21 20:19 ` [JGIT PATCH 12/12] Remove unreferenced REMOTE_SECTION from RepositoryConfig Shawn O. Pearce
2009-07-21 21:51 ` Robin Rosenberg [this message]
2009-07-21 21:54 ` [JGIT PATCH 11/12] Cleanup Config's MAGIC_EMPTY_VALUE to be more safe Shawn O. Pearce
2009-07-22 11:11 ` [JGIT PATCH 10/12] Match config subsection names using case sensitive search Constantine Plotnikov
2009-07-22 21:37 ` Robin Rosenberg
2009-07-24 21:34 ` [PATCH] Ensure Config readers handle case insensitive names correctly 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=200907212351.21760.robin.rosenberg@dewire.com \
--to=robin.rosenberg@dewire.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).