From e147fbcd6646f1746073d4d6b8f07ab1ee41b08c Mon Sep 17 00:00:00 2001 From: Marc Strapetz Date: Fri, 26 Nov 2010 11:07:04 +0100 Subject: Fix DiffConfig to understand "copy" resp. "copies" for diff.renames property. Rename detection should be considered enabled if diff.renames config property is set to "copy" or "copies", instead of throwing IllegalArgumentException. Change-Id: If55d955e37235d4d00f5b0febd6aa10c0e27814e --- .../src/org/eclipse/jgit/util/StringUtils.java | 49 +++++++++++++++------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java index 3759a12820..59f3d83ccf 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java @@ -120,6 +120,28 @@ public final class StringUtils { return true; } + /** + * Parse a string as a standard Git boolean value. See + * {@link #toBooleanOrNull(String)}. + * + * @param stringValue + * the string to parse. + * @return the boolean interpretation of {@code value}. + * @throws IllegalArgumentException + * if {@code value} is not recognized as one of the standard + * boolean names. + */ + public static boolean toBoolean(final String stringValue) { + if (stringValue == null) + throw new NullPointerException(JGitText.get().expectedBooleanStringValue); + + final Boolean bool = toBooleanOrNull(stringValue); + if (bool == null) + throw new IllegalArgumentException(MessageFormat.format(JGitText.get().notABoolean, stringValue)); + + return bool.booleanValue(); + } + /** * Parse a string as a standard Git boolean value. *

@@ -133,30 +155,25 @@ public final class StringUtils { * * @param stringValue * the string to parse. - * @return the boolean interpretation of {@code value}. - * @throws IllegalArgumentException - * if {@code value} is not recognized as one of the standard - * boolean names. + * @return the boolean interpretation of {@code value} or null in case the + * string does not represent a boolean value */ - public static boolean toBoolean(final String stringValue) { + public static Boolean toBooleanOrNull(final String stringValue) { if (stringValue == null) - throw new NullPointerException(JGitText.get().expectedBooleanStringValue); + return null; if (equalsIgnoreCase("yes", stringValue) || equalsIgnoreCase("true", stringValue) || equalsIgnoreCase("1", stringValue) - || equalsIgnoreCase("on", stringValue)) { - return true; - - } else if (equalsIgnoreCase("no", stringValue) + || equalsIgnoreCase("on", stringValue)) + return Boolean.TRUE; + else if (equalsIgnoreCase("no", stringValue) || equalsIgnoreCase("false", stringValue) || equalsIgnoreCase("0", stringValue) - || equalsIgnoreCase("off", stringValue)) { - return false; - - } else { - throw new IllegalArgumentException(MessageFormat.format(JGitText.get().notABoolean, stringValue)); - } + || equalsIgnoreCase("off", stringValue)) + return Boolean.FALSE; + else + return null; } /** -- cgit v1.2.3