]> source.dussan.org Git - jgit.git/commitdiff
Revert "Config: Distinguish between empty and null strings" 62/49862/3
authorJonathan Nieder <jrn@google.com>
Tue, 9 Jun 2015 22:54:52 +0000 (15:54 -0700)
committerJonathan Nieder <jrn@google.com>
Tue, 9 Jun 2015 22:58:12 +0000 (15:58 -0700)
This reverts commit 96eb3ee3976e7e9e3e118851fa614cce8a1f7d88, which
broke Gerrit tests that set a config value to 'null', serialize the
result, deserialize, and expect 'null' from Config.getString[1].

The intent of that commit was to make it possible to distinguish between
an absent and an empty config value, which we'll have to do with a new
method.

Revert the behavior change.  Keep the tests from 428cb23f2de8, since
they test the behavior more precisely than the old tests did.

[1] https://gerrit-review.googlesource.com/68452

Change-Id: Ie8042f380ea0e34e3203e1991aa0feb2e6e44641
Signed-off-by: Jonathan Nieder <jrn@google.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java

index b90a0c467130a0410b163f0aa0147e2cd80ae2e7..6238a354d8ce4999177191b1fa39a1065c8967f1 100644 (file)
@@ -707,8 +707,8 @@ public class ConfigTest {
                assertEquals("0", c.getString("a", null, "x"));
                assertEquals(0, c.getInt("a", null, "x", 1));
 
-               assertEquals("", c.getString("a", null, "y"));
-               assertArrayEquals(new String[]{""}, c.getStringList("a", null, "y"));
+               assertNull(c.getString("a", null, "y"));
+               assertArrayEquals(new String[]{null}, c.getStringList("a", null, "y"));
                try {
                        c.getInt("a", null, "y", 1);
                } catch (IllegalArgumentException e) {
@@ -730,9 +730,13 @@ public class ConfigTest {
        public void testEmptyValueAtEof() throws Exception {
                String text = "[a]\nx =";
                Config c = parse(text);
-               assertEquals("", c.getString("a", null, "x"));
+               assertNull(c.getString("a", null, "x"));
+               assertArrayEquals(new String[]{null},
+                               c.getStringList("a", null, "x"));
                c = parse(text + "\n");
-               assertEquals("", c.getString("a", null, "x"));
+               assertNull(c.getString("a", null, "x"));
+               assertArrayEquals(new String[]{null},
+                               c.getStringList("a", null, "x"));
        }
 
        private static void assertReadLong(long exp) throws ConfigInvalidException {
index 16953bb3406093319c9b3c03d5df887d075905d6..e48386d02406d03ac869880c6c28c5fd081dae5b 100644 (file)
@@ -1266,7 +1266,7 @@ public class Config {
 
                        value.append((char) c);
                }
-               return value.toString();
+               return value.length() > 0 ? value.toString() : null;
        }
 
        /**