summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2019-06-08 15:01:44 +0900
committerDavid Pursehouse <david.pursehouse@gmail.com>2019-06-11 10:51:40 +0900
commitfd8d779b5eec614d2cb5a611f2e36f522b34a439 (patch)
treeab49a2697885057730a721e69c7a60a5953ffccc
parent8bd0ba0f150feb485295f8c3890648eddf05fa41 (diff)
downloadjgit-fd8d779b5eec614d2cb5a611f2e36f522b34a439.tar.gz
jgit-fd8d779b5eec614d2cb5a611f2e36f522b34a439.zip
Config: Add helper method to check for empty value
Rename MAGIC_EMPTY_VALUE to MISSING_ENTRY, make it private, and add a helper method to check if a given string is that value. This avoids that callers trigger the "reference equality" warning from Error Prone. Change-Id: Idc76f78c0cf1828aa48d02ee33911a4b5df50355 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java19
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java2
2 files changed, 16 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
index 2c01d60381..1032fd0df1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java
@@ -107,7 +107,7 @@ public class Config {
* must ensure it is a special copy of the empty string. It also must
* be treated like the empty string.
*/
- static final String MAGIC_EMPTY_VALUE = new String();
+ private static final String MISSING_ENTRY = new String();
/**
* Create a configuration with no default fallback.
@@ -129,6 +129,17 @@ public class Config {
}
/**
+ * Check if a given string is the "missing" value.
+ *
+ * @param value
+ * @return true if the given string is the "missing" value.
+ * @since 5.4
+ */
+ public static boolean isMissing(String value) {
+ return value == MISSING_ENTRY;
+ }
+
+ /**
* Globally sets a {@link org.eclipse.jgit.lib.TypedConfigGetter} that is
* subsequently used to read typed values from all git configs.
*
@@ -1041,7 +1052,7 @@ public class Config {
if (e.prefix == null || "".equals(e.prefix)) //$NON-NLS-1$
out.append('\t');
out.append(e.name);
- if (MAGIC_EMPTY_VALUE != e.value) {
+ if (MISSING_ENTRY != e.value) {
out.append(" ="); //$NON-NLS-1$
if (e.value != null) {
out.append(' ');
@@ -1132,7 +1143,7 @@ public class Config {
e.name = readKeyName(in);
if (e.name.endsWith("\n")) { //$NON-NLS-1$
e.name = e.name.substring(0, e.name.length() - 1);
- e.value = MAGIC_EMPTY_VALUE;
+ e.value = MISSING_ENTRY;
} else
e.value = readValue(in);
@@ -1165,7 +1176,7 @@ public class Config {
private void addIncludedConfig(final List<ConfigLine> newEntries,
ConfigLine line, int depth) throws ConfigInvalidException {
if (!line.name.equalsIgnoreCase("path") || //$NON-NLS-1$
- line.value == null || line.value.equals(MAGIC_EMPTY_VALUE)) {
+ line.value == null || line.value.equals(MISSING_ENTRY)) {
throw new ConfigInvalidException(MessageFormat.format(
JGitText.get().invalidLineInConfigFileWithParam, line));
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java
index 6a66cf682f..4c70d20d6c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/DefaultTypedConfigGetter.java
@@ -72,7 +72,7 @@ public class DefaultTypedConfigGetter implements TypedConfigGetter {
if (n == null) {
return defaultValue;
}
- if (Config.MAGIC_EMPTY_VALUE == n) {
+ if (Config.isMissing(n)) {
return true;
}
try {