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 a dedicated exception for UnresolvedDeltas #1222

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 .codespellrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[codespell]
skip = .git,.mypy_cache,build,testdata
ignore-words-list = fpr,claus,feld,nd,bu,ue,te,fo,afile
ignore-words-list = fpr,claus,feld,nd,bu,ue,te,fo,afile,manuel
2 changes: 1 addition & 1 deletion .github/workflows/pythontest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: codespell
run: |
pip install --upgrade codespell
codespell .
codespell --config .codespellrc .
- name: Coverage test suite run
run: |
pip install --upgrade coverage
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,8 @@ apidocs:

fix:
ruff check --fix .

.PHONY: codespell

codespell:
codespell --config .codespellrc .
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* Raise exception when default identity can't be found.
(Jelmer Vernooij)

* Add a dedicated exception class for unresolved
deltas. (Jelmer Vernooij, #1221)

0.21.6 2023-09-02

* index: Handle different stages of conflicted paths.
Expand Down
2 changes: 1 addition & 1 deletion dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2210,7 +2210,7 @@ def __init__(
import urllib3.util

basic_auth = urllib3.util.make_headers(basic_auth=credentials)
self.pool_manager.headers.update(basic_auth)
self.pool_manager.headers.update(basic_auth) # type: ignore

self.config = config

Expand Down
11 changes: 9 additions & 2 deletions dulwich/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@
PackHint = Tuple[int, Optional[bytes]]


class UnresolvedDeltas(Exception):
""""Delta objects could not be resolved."""

def __init__(self, shas):
self.shas = shas


class ObjectContainer(Protocol):

def add_object(self, obj: ShaFile) -> None:
Expand Down Expand Up @@ -1443,7 +1450,7 @@ def _walk_all_chains(self):

def _ensure_no_pending(self) -> None:
if self._pending_ref:
raise KeyError([sha_to_hex(s) for s in self._pending_ref])
raise UnresolvedDeltas([sha_to_hex(s) for s in self._pending_ref])

def _walk_ref_chains(self):
if not self._resolve_ext_ref:
Expand Down Expand Up @@ -2442,7 +2449,7 @@ def iter_unpacked_subset(self, shas: Iterable[ObjectID], *, include_comp: bool =
yield child
assert not ofs_pending
if not allow_missing and todo:
raise KeyError(todo.pop())
raise UnresolvedDeltas(todo)

def iter_unpacked(self, include_comp=False):
ofs_to_entries = {ofs: (sha, crc32) for (sha, ofs, crc32) in self.index.iterentries()}
Expand Down
11 changes: 6 additions & 5 deletions dulwich/tests/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
PackData,
PackStreamReader,
UnpackedObject,
UnresolvedDeltas,
_delta_encode_size,
_encode_copy_operation,
apply_delta,
Expand Down Expand Up @@ -592,7 +593,7 @@ def test_get_unpacked_object(self):

def test_iterobjects(self):
with self.make_pack(False) as p:
self.assertRaises(KeyError, list, p.iterobjects())
self.assertRaises(UnresolvedDeltas, list, p.iterobjects())
with self.make_pack(True) as p:
self.assertEqual(
sorted(
Expand Down Expand Up @@ -1216,8 +1217,8 @@ def test_bad_ext_ref_non_thin_pack(self):
try:
list(pack_iter._walk_all_chains())
self.fail()
except KeyError as e:
self.assertEqual(([blob.id],), e.args)
except UnresolvedDeltas as e:
self.assertEqual([blob.id], e.shas)

def test_bad_ext_ref_thin_pack(self):
b1, b2, b3 = self.store_blobs([b"foo", b"bar", b"baz"])
Expand All @@ -1238,8 +1239,8 @@ def test_bad_ext_ref_thin_pack(self):
try:
list(pack_iter._walk_all_chains())
self.fail()
except KeyError as e:
self.assertEqual((sorted([b2.id, b3.id]),), (sorted(e.args[0]),))
except UnresolvedDeltas as e:
self.assertEqual((sorted([b2.id, b3.id]),), (sorted(e.shas),))


class DeltaEncodeSizeTests(TestCase):
Expand Down
Loading