commit 2f6f4d1e97d567eb45ea18634fdd1f7a29b63991 from: Jelmer Vernooij date: Sat Jan 14 02:13:51 2023 UTC Factor out MissingObjectStore. commit - f40a60968957e3982eee437f04b3e515bb2f5493 commit + 2f6f4d1e97d567eb45ea18634fdd1f7a29b63991 blob - d91771e9710ddfbf1e9db3650492dccaaec683c0 blob + 1701cf2d7f1c8a91bcd73b64a42f1ccd38eaa62a --- dulwich/object_store.py +++ dulwich/object_store.py @@ -261,7 +261,6 @@ class BaseObjectStore: progress=None, get_tagged=None, get_parents=lambda commit: commit.parents, - depth=None, ): """Find the missing objects required for a set of revisions. @@ -277,16 +276,18 @@ class BaseObjectStore: commit. Returns: Iterator over (sha, path) pairs. """ + warnings.warn( + 'Please use MissingObjectFinder(store)', DeprecationWarning) finder = MissingObjectFinder( self, - haves, - wants, - shallow, - progress, - get_tagged, + haves=haves, + wants=wants, + shallow=shallow, + progress=progress, + get_tagged=get_tagged, get_parents=get_parents, ) - return iter(finder.next, None) + return iter(finder) def find_common_revisions(self, graphwalker): """Find which revisions this store has in common using graphwalker. @@ -313,7 +314,8 @@ class BaseObjectStore: shallow: Set of shallow commit SHA1s to skip progress: Optional progress reporting method """ - missing = self.find_missing_objects(have, want, shallow, progress) + missing = MissingObjectFinder( + self, haves=have, wants=want, shallow=shallow, progress=progress) return self.iter_shas(missing) def generate_pack_data( @@ -1267,6 +1269,7 @@ class MissingObjectFinder: object_store, haves, wants, + *, shallow=None, progress=None, get_tagged=None, @@ -1334,7 +1337,7 @@ class MissingObjectFinder: def add_todo(self, entries): self.objects_to_send.update([e for e in entries if not e[0] in self.sha_done]) - def next(self): + def __next__(self): while True: if not self.objects_to_send: return None @@ -1361,7 +1364,8 @@ class MissingObjectFinder: self.progress(("counting objects: %d\r" % len(self.sha_done)).encode("ascii")) return (sha, name) - __next__ = next + def __iter__(self): + return iter(self.__next__, None) class ObjectStoreGraphWalker: blob - 53d889c29e74271cc59631a4ae5bab62f8254bb0 blob + 23912c85cfb8baf084b62829820e7667a99c43ce --- dulwich/repo.py +++ dulwich/repo.py @@ -73,6 +73,7 @@ from dulwich.object_store import ( BaseObjectStore, ObjectStoreGraphWalker, peel_sha, + MissingObjectFinder, ) from dulwich.objects import ( check_hexsha, @@ -566,12 +567,13 @@ class BaseRepo: return parents_provider.get_parents(commit.id, commit) return self.object_store.iter_shas( - self.object_store.find_missing_objects( - haves, - wants, - self.get_shallow(), - progress, - get_tagged, + MissingObjectFinder( + self.object_store, + haves=haves, + wants=wants, + shallow=self.get_shallow(), + progress=progress, + get_tagged=get_tagged, get_parents=get_parents, ) ) blob - 15826f71c7ba0777d3d4f25b4a5d89626f9697dd blob + c971db37c0ed0e4c10d39a49a4baefac4c32fa9c --- dulwich/tests/test_missing_obj_finder.py +++ dulwich/tests/test_missing_obj_finder.py @@ -20,6 +20,7 @@ from dulwich.object_store import ( MemoryObjectStore, + MissingObjectFinder, ) from dulwich.objects import ( Blob, @@ -42,7 +43,7 @@ class MissingObjectFinderTest(TestCase): return self.commits[n - 1] def assertMissingMatch(self, haves, wants, expected): - for sha, path in self.store.find_missing_objects(haves, wants, set()): + for sha, path in MissingObjectFinder(self.store, haves, wants, shallow=set()): self.assertIn( sha, expected, @@ -115,8 +116,7 @@ class MOFLinearRepoTest(MissingObjectFinderTest): haves = [self.cmt(1).id] wants = [self.cmt(3).id, bogus_sha] self.assertRaises( - KeyError, self.store.find_missing_objects, haves, wants, set() - ) + KeyError, MissingObjectFinder, self.store, haves, wants, shallow=set()) def test_no_changes(self): self.assertMissingMatch([self.cmt(3).id], [self.cmt(3).id], [])