Thread (6 messages) flat view 6 messages, 4 authors, 2016-06-15

Re: [JGIT PATCH 1/2] Add support for boolean config values "yes", "no"

From: Brandon Casey <hidden>
Date: 2016-06-15 22:46:43

Shawn O. Pearce wrote:
In 8f8c6fafd92f (shipped in 1.6.3) Linus taught C Git how to read
boolean configuration values set to "yes" as true and "no" as false.
Add support for these values, and some test cases.
Linus added support for "on" and "off" in that commit as it appears
your commit is also doing. :)

I was about to point out that you are not ignoring case for "on", but
using equalsIgnoreCase() appears to be unnecessary since above that
you are already doing n = n.toLowerCase().

-brandon

quoted hunk ↗ jump to hunk
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 cb287ee..e3a303f 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java
@@ -254,10 +254,19 @@ public boolean getBoolean(final String section, String subsection,
 			return defaultValue;
 
 		n = n.toLowerCase();
-		if (MAGIC_EMPTY_VALUE.equals(n) || "yes".equalsIgnoreCase(n) || "true".equalsIgnoreCase(n) || "1".equals(n)) {
+		if (MAGIC_EMPTY_VALUE.equals(n)
+				|| "yes".equalsIgnoreCase(n)
+				|| "true".equalsIgnoreCase(n)
+				|| "1".equals(n)
+				|| "on".equals(n)) {
 			return true;
-		} else if ("no".equalsIgnoreCase(n) || "false".equalsIgnoreCase(n) || "0".equalsIgnoreCase(n)) {
+
+		} else if ("no".equalsIgnoreCase(n)
+				|| "false".equalsIgnoreCase(n)
+				|| "0".equalsIgnoreCase(n)
+				|| "off".equalsIgnoreCase(n)) {
 			return false;
+
 		} else {
 			throw new IllegalArgumentException("Invalid boolean value: "
 					+ section + "." + name + "=" + n);
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help