Skip to content

Commit

Permalink
iter_prefix: fix handling of missing loose object directories (#1428)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer authored Nov 11, 2024
2 parents 4c878b4 + 1534e37 commit e7e83d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.22.6 UNRELEASED

* ``ObjectStore.iter_prefix``: fix handling of missing
loose object directories. (Jelmer Vernooij)

0.22.5 2024-11-07

* Drop support for Python 3.8. (Jelmer Vernooij)
Expand Down
15 changes: 9 additions & 6 deletions dulwich/object_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,12 +1039,15 @@ def iter_prefix(self, prefix):
seen = set()
dir = prefix[:2].decode()
rest = prefix[2:].decode()
for name in os.listdir(os.path.join(self.path, dir)):
if name.startswith(rest):
sha = os.fsencode(dir + name)
if sha not in seen:
seen.add(sha)
yield sha
try:
for name in os.listdir(os.path.join(self.path, dir)):
if name.startswith(rest):
sha = os.fsencode(dir + name)
if sha not in seen:
seen.add(sha)
yield sha
except FileNotFoundError:
pass

for p in self.packs:
bin_prefix = (
Expand Down
3 changes: 3 additions & 0 deletions dulwich/tests/test_object_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ def test_iter_prefix(self):
)
self.assertEqual([testobject.id], list(self.store.iter_prefix(b"")))

def test_iter_prefix_not_found(self):
self.assertEqual([], list(self.store.iter_prefix(b"1" * 40)))


class PackBasedObjectStoreTests(ObjectStoreTests):
def tearDown(self):
Expand Down

0 comments on commit e7e83d6

Please sign in to comment.