2
0
Эх сурвалжийг харах

Make fetch_objects a bit easier to access.

Jelmer Vernooij 16 жил өмнө
parent
commit
09a6d515a7

+ 28 - 0
dulwich/object_store.py

@@ -39,6 +39,9 @@ class ObjectStore(object):
         self.path = path
         self._packs = None
 
+    def iter_shas(self, shas):
+        return ObjectIterator(self, shas)
+
     def pack_dir(self):
         return os.path.join(self.path, PACKDIR)
 
@@ -171,3 +174,28 @@ class ObjectStore(object):
         f, commit = self.add_pack()
         write_pack_data(f, objects, len(objects))
         commit()
+
+
+class ObjectImporter(object):
+
+    def __init__(self, count):
+        self.count = count
+
+    def add_object(self, object):
+        raise NotImplementedError(self.add_object)
+
+    def finish(self, object):
+        raise NotImplementedError(self.finish)
+
+
+class ObjectIterator(object):
+
+    def __init__(self, store, shas):
+        self.store = store
+        self.shas = shas
+
+    def __iter__(self):
+        return ((self.store.get_object(sha), path) for sha, path in self.shas)
+
+    def __len__(self):
+        return len(self.shas)

+ 2 - 4
dulwich/repo.py

@@ -144,8 +144,8 @@ class Repo(object):
         updated progress strings.
     :return: tuple with number of objects, iterator over objects
     """
-    shas = self.find_missing_objects(determine_wants, graph_walker, progress)
-    return (len(shas), ((self.get_object(sha), path) for sha, path in shas))
+    return self.object_store.iter_shas(
+        self.find_missing_objects(determine_wants, graph_walker, progress))
 
   def object_dir(self):
     return os.path.join(self.controldir(), OBJECTDIR)
@@ -313,5 +313,3 @@ class Repo(object):
 
   create = init_bare
 
-
-