git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 1/2] Fix RepositoryConfig.setStringList to not corrupt internal state

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jul 27, 2008, 02:11 UTC
Message-ID
<1217124716-12063-1-git-send-email-spearce@spearce.org>

Calling setStringList was incorrectly storing the String objects directly in byName. The byName table should have either an Entry or a List<Entry> stored within its value position. Storing the String (or List<String>) directly confused our get code as it did not find the object type it expected. This caused the get code to fallback to the base configuration (e.g. ~/.gitconfig) or just return null (claiming the value was never set).

A test case for this appears in the next commit.
Noticed-by: Marek Zawirski <marek.zawirski@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/lib/RepositoryConfig.java |   23 ++++++++++++++++---
 1 files changed, 19 insertions(+), 4 deletions(-)
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 1431f1f..d1cd5fc 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
@@ -381,10 +381,25 @@ public class RepositoryConfig {
 		key += "." + name.toLowerCase();
 		if (values.size() == 0)
 			byName.remove(key);
-		else if (values.size() == 1)
-			byName.put(key, values.get(0));
-		else
-			byName.put(key, new ArrayList<String>(values));
+		else if (values.size() == 1) {
+			final Entry e = new Entry();
+			e.base = section;
+			e.extendedBase = subsection;
+			e.name = name;
+			e.value = values.get(0);
+			byName.put(key, e);
+		} else {
+			final ArrayList<Entry> eList = new ArrayList<Entry>(values.size());
+			for (final String v : values) {
+				final Entry e = new Entry();
+				e.base = section;
+				e.extendedBase = subsection;
+				e.name = name;
+				e.value = v;
+				eList.add(e);
+			}
+			byName.put(key, eList);
+		}
 
 		int entryIndex = 0;
 		int valueIndex = 0;
-- 
1.6.0.rc0.182.gb96c7
Next: Shawn O. Pearce
Message 1 of 2 in “Fix RepositoryConfig.setStringList to not corrupt internal state”
  1. 1/2 Fix RepositoryConfig.setStringList to not corrupt internal stateShawn O. Pearce, Jul 27, 2008
  2. 2/2 Extended test cases for RepositoryConfigTestShawn O. Pearce, Jul 27, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.