diff options
Diffstat (limited to 'core/storage.go')
-rw-r--r-- | core/storage.go | 72 |
1 files changed, 38 insertions, 34 deletions
diff --git a/core/storage.go b/core/storage.go index 739dfb6..101115b 100644 --- a/core/storage.go +++ b/core/storage.go @@ -7,45 +7,49 @@ import ( var ( //ErrStop is used to stop a ForEach function in an Iter - ErrStop = errors.New("stop iter") - ErrNotImplemented = errors.New("method not-implemented") + ErrStop = errors.New("stop iter") ) -// ObjectStorage generic storage of objects -type ObjectStorage interface { +// ObjectStorer generic storage of objects +type ObjectStorer interface { // NewObject returns a new Object, the real type of the object can be a // custom implementation or the defaul one, MemoryObject NewObject() Object - // Set save an object into the storage, the object shuld be create with - // the NewObject, method, and file if the type is not supported. - Set(Object) (Hash, error) - // Get an object by hash with the given ObjectType. Implementors should - // return (nil, ErrObjectNotFound) if an object doesn't exist with both the - // given hash and object type. + // SetObject save an object into the storage, the object shuld be create + // with the NewObject, method, and file if the type is not supported. + SetObject(Object) (Hash, error) + // Object an object by hash with the given ObjectType. Implementors + // should return (nil, ErrObjectNotFound) if an object doesn't exist with + // both the given hash and object type. // // Valid ObjectType values are CommitObject, BlobObject, TagObject, - // TreeObject and AnyObject. - // - // If AnyObject is given, the object must be looked up regardless of its type. - Get(ObjectType, Hash) (Object, error) - // Iter returns a custom ObjectIter over all the object on the storage. + // TreeObject and AnyObject. If AnyObject is given, the object must be + // looked up regardless of its type. + Object(ObjectType, Hash) (Object, error) + // IterObjects returns a custom ObjectIter over all the object on the + // storage. // // Valid ObjectType values are CommitObject, BlobObject, TagObject, - Iter(ObjectType) (ObjectIter, error) + IterObjects(ObjectType) (ObjectIter, error) +} + +// Transactioner is a optional method for ObjectStorer, it enable transaction +// base write and read operations in the storage +type Transactioner interface { // Begin starts a transaction. - Begin() TxObjectStorage + Begin() Transaction } -// ObjectStorageWrite is a optional method for ObjectStorage, it enable direct -// write of packfile to the storage -type ObjectStorageWrite interface { - // Writer retuns a writer for writing a packfile to the Storage, this method - // is optional, if not implemented the ObjectStorage should return a - // ErrNotImplemented error. +// PackfileWriter is a optional method for ObjectStorer, it enable direct write +// of packfile to the storage +type PackfileWriter interface { + // PackfileWriter retuns a writer for writing a packfile to the Storage, + // this method is optional, if not implemented the ObjectStorer should + // return a ErrNotImplemented error. // // If the implementation not implements Writer the objects should be written // using the Set method. - Writer() (io.WriteCloser, error) + PackfileWriter() (io.WriteCloser, error) } // ObjectIter is a generic closable interface for iterating over objects. @@ -55,20 +59,20 @@ type ObjectIter interface { Close() } -// TxObjectStorage is an in-progress storage transaction. -// A transaction must end with a call to Commit or Rollback. -type TxObjectStorage interface { - Set(Object) (Hash, error) - Get(ObjectType, Hash) (Object, error) +// Transaction is an in-progress storage transaction. A transaction must end +// with a call to Commit or Rollback. +type Transaction interface { + SetObject(Object) (Hash, error) + Object(ObjectType, Hash) (Object, error) Commit() error Rollback() error } -// ReferenceStorage generic storage of references -type ReferenceStorage interface { - Set(*Reference) error - Get(ReferenceName) (*Reference, error) - Iter() (ReferenceIter, error) +// ReferenceStorer generic storage of references +type ReferenceStorer interface { + SetReference(*Reference) error + Reference(ReferenceName) (*Reference, error) + IterReferences() (ReferenceIter, error) } // ReferenceIter is a generic closable interface for iterating over references |