[JGIT PATCH] Removed conversion of subsection to the lowecase when accessing subsection names in config files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
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

--
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]