Thread (26 messages) flat view 26 messages, 2 authors, 2016-06-15
DORMANTno replies

[JGIT PATCH 12/19] Return base values first from Config.getStringList()

From: Shawn O. Pearce <hidden>
Date: 2016-06-15 22:47:06
Subsystem: the rest · Maintainer: Linus Torvalds

C Git's `git config --get-all foo.bar` returns the base configuration
values for foo.bar (aka those found in /etc/gitconfig or ~/.gitconfig)
before the repository specific configuration values for foo.bar.  To
better match C Git behavior when processing a multi-value key we must
do the same in our getStringList() method.

Signed-off-by: Shawn O. Pearce <redacted>
---
 .../src/org/spearce/jgit/lib/Config.java           |   24 +++++++++++++++----
 1 files changed, 19 insertions(+), 5 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 0f91412..f4e78f3 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
@@ -55,6 +55,7 @@
  * Git style {@code .config}, {@code .gitconfig}, {@code .gitmodules} file.
  */
 public class Config {
+	private static final String[] EMPTY_STRING_ARRAY = {};
 	private static final long KiB = 1024;
 	private static final long MiB = 1024 * KiB;
 	private static final long GiB = 1024 * MiB;
@@ -316,6 +317,9 @@ public String getString(final String section, String subsection,
 
 	/**
 	 * Get a list of string values
+	 * <p>
+	 * If this instance was created with a base, the base's values are returned
+	 * first (if any).
 	 *
 	 * @param section
 	 *            the section
@@ -327,12 +331,22 @@ public String getString(final String section, String subsection,
 	 */
 	public String[] getStringList(final String section, String subsection,
 			final String name) {
-		final List<String> lst = getRawStringList(section, subsection, name);
-		if (lst != null)
-			return lst.toArray(new String[lst.size()]);
+		final String[] baseList;
 		if (baseConfig != null)
-			return baseConfig.getStringList(section, subsection, name);
-		return new String[0];
+			baseList = baseConfig.getStringList(section, subsection, name);
+		else
+			baseList = EMPTY_STRING_ARRAY;
+
+		final List<String> lst = getRawStringList(section, subsection, name);
+		if (lst != null) {
+			final String[] res = new String[baseList.length + lst.size()];
+			int idx = baseList.length;
+			System.arraycopy(baseList, 0, res, 0, idx);
+			for (final String val : lst)
+				res[idx++] = val;
+			return res;
+		}
+		return baseList;
 	}
 
 	/**
-- 
1.6.4.rc2.216.g769fa
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help