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

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

 



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 <spearce@xxxxxxxxxxx>
---
 .../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

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