git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Constantine Plotnikov <constantine.plotnikov@gmail.com>
To: git@vger.kernel.org
Cc: Constantine Plotnikov <constantine.plotnikov@gmail.com>
Subject: [JGIT PATCH] Removed conversion of subsection to the lowecase when accessing subsection names in config files
Date: Wed, 22 Jul 2009 16:53:41 +0400	[thread overview]
Message-ID: <1248267221-2312-1-git-send-email-constantine.plotnikov@gmail.com> (raw)

The entries are stored in Config.byName without coversion of
the subsection name to the lowercase. But the methods
setStringList(...) and getRawEntry(...) were converting subsection
names to the lowercase, thus making it impossible to access
values in subsection with names that contained upppercase characters.
This patch removes conversion to the lowercase and introduce
the methods that appropriately concatentates the key. This key
is now used for all map accesses.

Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>
---
The patch assumes the current head "FindBugs: don't use new String(String) in RefDatabase".

To apply above the series "[JGIT PATCH 00/12] Cleanup Config class" the
field names in the method add(final Entry e) should be changed. Possibly 
the patch should be merged into the patch 

 "[JGIT PATCH 10/12] Match config subsection names using case sensitive search".
                                   
 .../src/org/spearce/jgit/lib/Config.java           |   61 ++++++++++----------
 1 files changed, 31 insertions(+), 30 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 c2d5c6e..a8639ff 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
@@ -419,15 +419,29 @@ private void ensureLoaded() {
 	private Object getRawEntry(final String section, final String subsection,
 			final String name) {
 		ensureLoaded();
+		return byName.get(concatenateKey(section, subsection, name));
+	}
 
+	/**
+	 * Create simple a key name from the key components
+	 *
+	 * @param section
+	 *            the section name
+	 * @param subsection
+	 *            the subsection name
+	 * @param name
+	 *            the key name
+	 * @return a simple key name that have all components concatenated and the
+	 *         case converted
+	 */
+	private static String concatenateKey(final String section,
+			final String subsection, final String name) {
 		String ss;
 		if (subsection != null)
-			ss = "." + subsection.toLowerCase();
+			ss = "." + subsection;
 		else
 			ss = "";
-		final Object o;
-		o = byName.get(section.toLowerCase() + ss + "." + name.toLowerCase());
-		return o;
+		return section.toLowerCase() + ss + "." + name.toLowerCase();
 	}
 
 	/**
@@ -548,10 +562,7 @@ public void setStringList(final String section, final String subsection,
 			final String name, final List<String> values) {
 		// Update our parsed cache of values for future reference.
 		//
-		String key = section.toLowerCase();
-		if (subsection != null)
-			key += "." + subsection.toLowerCase();
-		key += "." + name.toLowerCase();
+		String key = concatenateKey(section, subsection, name);
 		if (values.size() == 0)
 			byName.remove(key);
 		else if (values.size() == 1) {
@@ -787,28 +798,18 @@ protected void clear() {
 	@SuppressWarnings("unchecked")
 	private void add(final Entry e) {
 		entries.add(e);
-		if (e.base != null) {
-			final String b = e.base.toLowerCase();
-			final String group;
-			if (e.extendedBase != null) {
-				group = b + "." + e.extendedBase;
-			} else {
-				group = b;
-			}
-			if (e.name != null) {
-				final String n = e.name.toLowerCase();
-				final String key = group + "." + n;
-				final Object o = byName.get(key);
-				if (o == null) {
-					byName.put(key, e);
-				} else if (o instanceof Entry) {
-					final ArrayList<Object> l = new ArrayList<Object>();
-					l.add(o);
-					l.add(e);
-					byName.put(key, l);
-				} else if (o instanceof List) {
-					((List<Entry>) o).add(e);
-				}
+		if (e.base != null && e.name != null) {
+			final String key = concatenateKey(e.base, e.extendedBase, e.name);
+			final Object o = byName.get(key);
+			if (o == null) {
+				byName.put(key, e);
+			} else if (o instanceof Entry) {
+				final ArrayList<Object> l = new ArrayList<Object>();
+				l.add(o);
+				l.add(e);
+				byName.put(key, l);
+			} else if (o instanceof List) {
+				((List<Entry>) o).add(e);
 			}
 		}
 	}
-- 
1.6.1.2

                 reply	other threads:[~2009-07-22 12:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1248267221-2312-1-git-send-email-constantine.plotnikov@gmail.com \
    --to=constantine.plotnikov@gmail.com \
    --cc=git@vger.kernel.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).