Răsfoiți Sursa

alternates: add alternates check to __contains__ and __iter__ to make it match __getitem__.

Dmitriy 12 ani în urmă
părinte
comite
4dd7427cf0
1 a modificat fișierele cu 21 adăugiri și 1 ștergeri
  1. 21 1
      dulwich/object_store.py

+ 21 - 1
dulwich/object_store.py

@@ -237,6 +237,20 @@ class PackBasedObjectStore(BaseObjectStore):
                 return True
         return False
 
+    def contains_alternate(self, sha):
+        """Check if a particular object is present by SHA1 in the alternate storage."""
+        for alternate in self.alternates:
+            if alternate.contains_loose(sha) or alternate.contains_packed(sha):
+                return True
+        return False
+
+    def __contains__(self, sha):
+        """Check if a particular object is present by SHA1 in the main or alternate stores.
+
+        This method makes no distinction between loose and packed objects.
+        """
+        return self.contains_packed(sha) or self.contains_loose(sha) or self.contains_alternate(sha)
+
     def _load_packs(self):
         raise NotImplementedError(self._load_packs)
 
@@ -258,6 +272,12 @@ class PackBasedObjectStore(BaseObjectStore):
             self._pack_cache = self._load_packs()
         return self._pack_cache
 
+    def _iter_alternate_objects(self):
+        """Iterate over the SHAs of all the objects in alternate stores."""
+        for alternate in self.alternates:
+            for alternate_object in alternate:
+                yield alternate_object
+
     def _iter_loose_objects(self):
         """Iterate over the SHAs of all loose objects."""
         raise NotImplementedError(self._iter_loose_objects)
@@ -283,7 +303,7 @@ class PackBasedObjectStore(BaseObjectStore):
 
     def __iter__(self):
         """Iterate over the SHAs that are present in this store."""
-        iterables = self.packs + [self._iter_loose_objects()]
+        iterables = self.packs + [self._iter_loose_objects()] + [self._iter_alternate_objects()]
         return itertools.chain(*iterables)
 
     def contains_loose(self, sha):