{"thread":{"id":"20193","subject":"[JGIT PATCH] Removed conversion of subsection to the lowecase when accessing subsection names in config files","startedAt":"2009-07-22T12:53:41Z","lastAt":"2009-07-22T12:53:41Z","messageCount":1,"participants":["Constantine Plotnikov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"118459","messageId":"1248267221-2312-1-git-send-email-constantine.plotnikov@gmail.com","threadId":"20193","inReplyTo":null,"subject":"[JGIT PATCH] Removed conversion of subsection to the lowecase when accessing subsection names in config files","fromName":"Constantine Plotnikov","fromEmail":"constantine.plotnikov@gmail.com","sentAt":"2009-07-22T12:53:41Z","receivedAt":"2009-07-22T12:53:41Z","isPatch":true,"sender":{"key":"constantine.plotnikov@gmail.com","avatar":null},"body":"The entries are stored in Config.byName without coversion of\nthe subsection name to the lowercase. But the methods\nsetStringList(...) and getRawEntry(...) were converting subsection\nnames to the lowercase, thus making it impossible to access\nvalues in subsection with names that contained upppercase characters.\nThis patch removes conversion to the lowercase and introduce\nthe methods that appropriately concatentates the key. This key\nis now used for all map accesses.\n\nSigned-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>\n---\nThe patch assumes the current head \"FindBugs: don't use new String(String) in RefDatabase\".\n\nTo apply above the series \"[JGIT PATCH 00/12] Cleanup Config class\" the\nfield names in the method add(final Entry e) should be changed. Possibly \nthe patch should be merged into the patch \n\n \"[JGIT PATCH 10/12] Match config subsection names using case sensitive search\".\n                                   \n .../src/org/spearce/jgit/lib/Config.java           |   61 ++++++++++----------\n 1 files changed, 31 insertions(+), 30 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java\nindex c2d5c6e..a8639ff 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java\n@@ -419,15 +419,29 @@ private void ensureLoaded() {\n \tprivate Object getRawEntry(final String section, final String subsection,\n \t\t\tfinal String name) {\n \t\tensureLoaded();\n+\t\treturn byName.get(concatenateKey(section, subsection, name));\n+\t}\n \n+\t/**\n+\t * Create simple a key name from the key components\n+\t *\n+\t * @param section\n+\t *            the section name\n+\t * @param subsection\n+\t *            the subsection name\n+\t * @param name\n+\t *            the key name\n+\t * @return a simple key name that have all components concatenated and the\n+\t *         case converted\n+\t */\n+\tprivate static String concatenateKey(final String section,\n+\t\t\tfinal String subsection, final String name) {\n \t\tString ss;\n \t\tif (subsection != null)\n-\t\t\tss = \".\" + subsection.toLowerCase();\n+\t\t\tss = \".\" + subsection;\n \t\telse\n \t\t\tss = \"\";\n-\t\tfinal Object o;\n-\t\to = byName.get(section.toLowerCase() + ss + \".\" + name.toLowerCase());\n-\t\treturn o;\n+\t\treturn section.toLowerCase() + ss + \".\" + name.toLowerCase();\n \t}\n \n \t/**\n@@ -548,10 +562,7 @@ public void setStringList(final String section, final String subsection,\n \t\t\tfinal String name, final List<String> values) {\n \t\t// Update our parsed cache of values for future reference.\n \t\t//\n-\t\tString key = section.toLowerCase();\n-\t\tif (subsection != null)\n-\t\t\tkey += \".\" + subsection.toLowerCase();\n-\t\tkey += \".\" + name.toLowerCase();\n+\t\tString key = concatenateKey(section, subsection, name);\n \t\tif (values.size() == 0)\n \t\t\tbyName.remove(key);\n \t\telse if (values.size() == 1) {\n@@ -787,28 +798,18 @@ protected void clear() {\n \t@SuppressWarnings(\"unchecked\")\n \tprivate void add(final Entry e) {\n \t\tentries.add(e);\n-\t\tif (e.base != null) {\n-\t\t\tfinal String b = e.base.toLowerCase();\n-\t\t\tfinal String group;\n-\t\t\tif (e.extendedBase != null) {\n-\t\t\t\tgroup = b + \".\" + e.extendedBase;\n-\t\t\t} else {\n-\t\t\t\tgroup = b;\n-\t\t\t}\n-\t\t\tif (e.name != null) {\n-\t\t\t\tfinal String n = e.name.toLowerCase();\n-\t\t\t\tfinal String key = group + \".\" + n;\n-\t\t\t\tfinal Object o = byName.get(key);\n-\t\t\t\tif (o == null) {\n-\t\t\t\t\tbyName.put(key, e);\n-\t\t\t\t} else if (o instanceof Entry) {\n-\t\t\t\t\tfinal ArrayList<Object> l = new ArrayList<Object>();\n-\t\t\t\t\tl.add(o);\n-\t\t\t\t\tl.add(e);\n-\t\t\t\t\tbyName.put(key, l);\n-\t\t\t\t} else if (o instanceof List) {\n-\t\t\t\t\t((List<Entry>) o).add(e);\n-\t\t\t\t}\n+\t\tif (e.base != null && e.name != null) {\n+\t\t\tfinal String key = concatenateKey(e.base, e.extendedBase, e.name);\n+\t\t\tfinal Object o = byName.get(key);\n+\t\t\tif (o == null) {\n+\t\t\t\tbyName.put(key, e);\n+\t\t\t} else if (o instanceof Entry) {\n+\t\t\t\tfinal ArrayList<Object> l = new ArrayList<Object>();\n+\t\t\t\tl.add(o);\n+\t\t\t\tl.add(e);\n+\t\t\t\tbyName.put(key, l);\n+\t\t\t} else if (o instanceof List) {\n+\t\t\t\t((List<Entry>) o).add(e);\n \t\t\t}\n \t\t}\n \t}\n-- \n1.6.1.2\n"}]}