2
0
Эх сурвалжийг харах

Raise exception when encountering an unsupported index format.

Jelmer Vernooij 2 жил өмнө
parent
commit
463a6f9396
1 өөрчлөгдсөн 9 нэмэгдсэн , 1 устгасан
  1. 9 1
      dulwich/index.py

+ 9 - 1
dulwich/index.py

@@ -230,13 +230,21 @@ def write_cache_entry(f, name, entry, version):
         f.write(b"\0" * ((beginoffset + real_size) - f.tell()))
 
 
+class UnsupportedIndexFormat(Exception):
+    """An unsupported index format was encountered."""
+
+    def __init__(self, version):
+        self.index_format_version = version
+
+
 def read_index(f: BinaryIO):
     """Read an index file, yielding the individual entries."""
     header = f.read(4)
     if header != b"DIRC":
         raise AssertionError("Invalid index file header: %r" % header)
     (version, num_entries) = struct.unpack(b">LL", f.read(4 * 2))
-    assert version in (1, 2, 3), "index version is %r" % version
+    if version not in (1, 2, 3):
+        raise UnsupportedIndexFormat(version)
     for i in range(num_entries):
         yield read_cache_entry(f, version)