Skip to content

Commit

Permalink
Add a dedicated exception for UnresolvedDeltas
Browse files Browse the repository at this point in the history
Fixes #1221
  • Loading branch information
jelmer committed Oct 3, 2023
1 parent 0a5c62b commit c9726cd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
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
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

0 comments on commit c9726cd

Please sign in to comment.