Browse Source

Options on the same line as sections in config files are now supported. #920553

Jelmer Vernooij 13 years ago
parent
commit
312a436698
3 changed files with 39 additions and 28 deletions
  1. 10 3
      NEWS
  2. 25 25
      dulwich/config.py
  3. 4 0
      dulwich/tests/test_config.py

+ 10 - 3
NEWS

@@ -1,8 +1,15 @@
 0.8.4	UNRELEASED
 
- * $HOME is now explicitly specified for tests that use it to read
-   ``~/.gitconfig``, to prevent test isolation issues.
-   (Jelmer Vernooij, #920330)
+ BUG FIXES
+
+  * Options on the same line as sections in config files are now supported.
+    (Jelmer Vernooij, #920553)
+
+ TESTS
+
+  * $HOME is now explicitly specified for tests that use it to read
+    ``~/.gitconfig``, to prevent test isolation issues.
+    (Jelmer Vernooij, #920330)
 
 0.8.3	2012-01-21
 

+ 25 - 25
dulwich/config.py

@@ -198,14 +198,13 @@ class ConfigFile(ConfigDict):
         for lineno, line in enumerate(f.readlines()):
             line = line.lstrip()
             if setting is None:
-                if _strip_comments(line).strip() == "":
-                    continue
-                if line[0] == "[":
+                if len(line) > 0 and line[0] == "[":
                     line = _strip_comments(line).rstrip()
-                    if line[-1] != "]":
+                    last = line.index("]")
+                    if last == -1:
                         raise ValueError("expected trailing ]")
-                    key = line.strip()
-                    pts = key[1:-1].split(" ", 1)
+                    pts = line[1:last].split(" ", 1)
+                    line = line[last+1:]
                     pts[0] = pts[0].lower()
                     if len(pts) == 2:
                         if pts[1][0] != "\"" or pts[1][-1] != "\"":
@@ -227,26 +226,27 @@ class ConfigFile(ConfigDict):
                         else:
                             section = (pts[0], )
                     ret._values[section] = {}
+                if _strip_comments(line).strip() == "":
+                    continue
+                if section is None:
+                    raise ValueError("setting %r without section" % line)
+                try:
+                    setting, value = line.split("=", 1)
+                except ValueError:
+                    setting = line
+                    value = "true"
+                setting = setting.strip().lower()
+                if not _check_variable_name(setting):
+                    raise ValueError("invalid variable name %s" % setting)
+                if value.endswith("\\\n"):
+                    value = value[:-2]
+                    continuation = True
                 else:
-                    if section is None:
-                        raise ValueError("setting %r without section" % line)
-                    try:
-                        setting, value = line.split("=", 1)
-                    except ValueError:
-                        setting = line
-                        value = "true"
-                    setting = setting.strip().lower()
-                    if not _check_variable_name(setting):
-                        raise ValueError("invalid variable name %s" % setting)
-                    if value.endswith("\\\n"):
-                        value = value[:-2]
-                        continuation = True
-                    else:
-                        continuation = False
-                    value = _parse_string(value)
-                    ret._values[section][setting] = value
-                    if not continuation:
-                        setting = None
+                    continuation = False
+                value = _parse_string(value)
+                ret._values[section][setting] = value
+                if not continuation:
+                    setting = None
             else: # continuation line
                 if line.endswith("\\\n"):
                     line = line[:-2]

+ 4 - 0
dulwich/tests/test_config.py

@@ -147,6 +147,10 @@ class ConfigFileTests(TestCase):
         c.write_to_file(f)
         self.assertEquals("[branch \"blie\"]\nfoo = bar\n", f.getvalue())
 
+    def test_same_line(self):
+        cf = self.from_file("[branch.foo] foo = bar\n")
+        self.assertEquals("bar", cf.get(("branch", "foo"), "foo"))
+
 
 class ConfigDictTests(TestCase):