Changeset 9766154d0437…
Parent e603229a17a9…
by
Changes to 2 files · Browse files at 9766154d0437 Showing diff from parent e603229a17a9 Diff from another changeset...
@@ -148,7 +148,7 @@
# read the final confirmation sha
client_sha = self.proto.read(20)
- if not client_sha in (None, sha)
+ if not client_sha in (None, sha):
raise ChecksumMismatch(sha, client_sha)
return changed_refs
|
|
@@ -50,8 +50,70 @@
PACKDIR = 'pack'
-class ObjectStore(object):
- """Object store."""
+
+class BaseObjectStore(object):
+ """Object store interface."""
+
+ def determine_wants_all(self, refs):
+ return [sha for (ref, sha) in refs.iteritems() if not sha in self and not ref.endswith("^{}")]
+
+ def iter_shas(self, shas):
+ """Iterate over the objects for the specified shas.
+
+ :param shas: Iterable object with SHAs
+ """
+ return ObjectStoreIterator(self, shas)
+
+ def __contains__(self, sha):
+ """Check if a particular object is present by SHA1."""
+ raise NotImplementedError(self.__contains__)
+
+ def get_raw(self, name):
+ """Obtain the raw text for an object.
+
+ :param name: sha for the object.
+ :return: tuple with object type and object contents.
+ """
+ raise NotImplementedError(self.get_raw)
+
+ def __getitem__(self, sha):
+ """Obtain an object by SHA1."""
+ type, uncomp = self.get_raw(sha)
+ return ShaFile.from_raw_string(type, uncomp)
+
+ def __iter__(self):
+ """Iterate over the SHAs that are present in this store."""
+ raise NotImplementedError(self.__iter__)
+
+ def add_object(self, obj):
+ """Add a single object to this object store.
+
+ """
+ raise NotImplementedError(self.add_object)
+
+ def add_objects(self, objects):
+ """Add a set of objects to this object store.
+
+ :param objects: Iterable over a list of objects.
+ """
+ raise NotImplementedError(self.add_objects)
+
+ def find_missing_objects(self, wants, graph_walker, progress=None):
+ """Find the missing objects required for a set of revisions.
+
+ :param wants: Iterable over SHAs of objects to fetch.
+ :param graph_walker: Object that can iterate over the list of revisions
+ to fetch and has an "ack" method that will be called to acknowledge
+ that a revision is present.
+ :param progress: Simple progress function that will be called with
+ updated progress strings.
+ :return: Iterator over (sha, path) pairs.
+ """
+ return iter(MissingObjectFinder(self, wants, graph_walker, progress).next, None)
+
+
+class ObjectStore(BaseObjectStore):
+ """Git-style object store that exists on disk."""
def __init__(self, path):
"""Open an object store.
@@ -61,16 +123,6 @@ self.path = path
self._pack_cache = None
self.pack_dir = os.path.join(self.path, PACKDIR)
-
- def determine_wants_all(self, refs):
- return [sha for (ref, sha) in refs.iteritems() if not sha in self and not ref.endswith("^{}")]
-
- def iter_shas(self, shas):
- """Iterate over the objects for the specified shas.
-
- :param shas: Iterable object with SHAs
- """
- return ObjectStoreIterator(self, shas)
def __contains__(self, sha):
"""Check if a particular object is present by SHA1."""
@@ -157,10 +209,6 @@ return ret.type, ret.as_raw_string()
raise KeyError(hexsha)
- def __getitem__(self, sha):
- type, uncomp = self.get_raw(sha)
- return ShaFile.from_raw_string(type, uncomp)
-
def move_in_thin_pack(self, path):
"""Move a specific file containing a pack into the pack directory.
@@ -251,18 +299,6 @@ write_pack_data(f, objects, len(objects))
commit()
- def find_missing_objects(self, wants, graph_walker, progress=None):
- """Find the missing objects required for a set of revisions.
-
- :param wants: Iterable over SHAs of objects to fetch.
- :param graph_walker: Object that can iterate over the list of revisions
- to fetch and has an "ack" method that will be called to acknowledge
- that a revision is present.
- :param progress: Simple progress function that will be called with
- updated progress strings.
- :return: Iterator over (sha, path) pairs.
- """
- return iter(MissingObjectFinder(self, wants, graph_walker, progress).next, None)
class ObjectImporter(object):
|
Loading...