Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for the git option "index.skipHash" #1488

Merged
merged 3 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dulwich/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def read(self) -> None:
self.update(read_index_dict(f))
# FIXME: Additional data?
f.read(os.path.getsize(self._filename) - f.tell() - 20)
f.check_sha()
f.check_sha(allow_empty=True)
finally:
f.close()

Expand Down
5 changes: 3 additions & 2 deletions dulwich/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,9 +1605,10 @@ def read(self, num=None):
self.sha1.update(data)
return data

def check_sha(self) -> None:
def check_sha(self, allow_empty: bool = False) -> None:
stored = self.f.read(20)
if stored != self.sha1.digest():
# If git option index.skipHash is set the index will be empty
if stored != self.sha1.digest() and (not allow_empty or sha_to_hex(stored) != b'0000000000000000000000000000000000000000'):
raise ChecksumMismatch(self.sha1.hexdigest(), sha_to_hex(stored))

def close(self):
Expand Down
Binary file added testdata/indexes/index_skip_hash
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def test_len(self) -> None:
def test_iter(self) -> None:
self.assertEqual([b"bla"], list(self.get_simple_index("index")))

def test_iter_skip_hash(self) -> None:
self.assertEqual([b"bla"], list(self.get_simple_index("index_skip_hash")))

def test_iterobjects(self) -> None:
self.assertEqual(
[(b"bla", b"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", 33188)],
Expand Down
Loading