def read_header(stream: IO[bytes]) -> Tuple[int, int]:
    """Return tuple(version_long, num_entries) from the given stream."""
    type_id = stream.read(4)
    if type_id != b"DIRC":
        raise AssertionError("Invalid index file header: %r" % type_id)
    unpacked = cast(Tuple[int, int], unpack(">LL", stream.read(4 * 2)))
    version, num_entries = unpacked

    # TODO: Handle version 3: extended data, see read-cache.c.
    assert version in (1, 2)
    return version, num_entries
Return tuple(version_long, num_entries) from the given stream.
git/index/fun.py