Browse Source

DiskObjectStore: fixed ignoring of comment lines

In Python3, b"something"[0] is not b"s", but ord(b"s").
On the otherhand, startswith just works.
Georges Racinet 4 years ago
parent
commit
544e90f8cb
2 changed files with 7 additions and 1 deletions
  1. 1 1
      dulwich/object_store.py
  2. 6 0
      dulwich/tests/test_object_store.py

+ 1 - 1
dulwich/object_store.py

@@ -577,7 +577,7 @@ class DiskObjectStore(PackBasedObjectStore):
         with f:
             for line in f.readlines():
                 line = line.rstrip(b"\n")
-                if line[0] == b"#":
+                if line.startswith(b"#"):
                     continue
                 if os.path.isabs(line):
                     yield os.fsdecode(line)

+ 6 - 0
dulwich/tests/test_object_store.py

@@ -374,6 +374,12 @@ class DiskObjectStoreTests(PackBasedObjectStoreTests, TestCase):
         self.assertIn(os.path.join(store.path, "relative-path"),
                       set(store._read_alternate_paths()))
 
+        # arguably, add_alternate_path() could strip comments.
+        # Meanwhile it's more convenient to use it than to import INFODIR
+        store.add_alternate_path("# comment")
+        for alt_path in store._read_alternate_paths():
+            self.assertNotIn("#", alt_path)
+
     def test_corrupted_object_raise_exception(self):
         """Corrupted sha1 disk file should raise specific exception"""
         self.store.add_object(testobject)