Documentation
¶
Overview ¶
Package storage provides an SQL-backed storage implementation for go-git using only basic SQL statements to ensure good compatibility with as many databases as is feasable.
Index ¶
- type ObjectStorage
- func (o *ObjectStorage) AddAlternate(remote string) error
- func (o *ObjectStorage) BufferEncodedObject(obj plumbing.EncodedObject) (plumbing.Hash, error)
- func (o *ObjectStorage) Commit() error
- func (o *ObjectStorage) EncodedObject(objType plumbing.ObjectType, objHash plumbing.Hash) (plumbing.EncodedObject, error)
- func (o *ObjectStorage) EncodedObjectSize(hash plumbing.Hash) (int64, error)
- func (o *ObjectStorage) HasEncodedObject(hash plumbing.Hash) error
- func (o *ObjectStorage) IterEncodedObjects(objType plumbing.ObjectType) (storer.EncodedObjectIter, error)
- func (o *ObjectStorage) NewEncodedObject() plumbing.EncodedObject
- func (o *ObjectStorage) SetEncodedObject(obj plumbing.EncodedObject) (plumbing.Hash, error)
- type ReferenceStorage
- func (r *ReferenceStorage) CheckAndSetReference(new, old *plumbing.Reference) error
- func (r *ReferenceStorage) CountLooseRefs() (int, error)
- func (r *ReferenceStorage) IterReferences() (storer.ReferenceIter, error)
- func (r *ReferenceStorage) PackRefs() error
- func (r *ReferenceStorage) Reference(name plumbing.ReferenceName) (*plumbing.Reference, error)
- func (r *ReferenceStorage) RemoveReference(name plumbing.ReferenceName) error
- func (r *ReferenceStorage) SetReference(ref *plumbing.Reference) error
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ObjectStorage ¶
type ObjectStorage struct {
// contains filtered or unexported fields
}
func (*ObjectStorage) AddAlternate ¶
func (o *ObjectStorage) AddAlternate(remote string) error
AddAlternate is not currently implemented.
func (*ObjectStorage) BufferEncodedObject ¶
func (o *ObjectStorage) BufferEncodedObject(obj plumbing.EncodedObject) (plumbing.Hash, error)
func (*ObjectStorage) Commit ¶
func (o *ObjectStorage) Commit() error
func (*ObjectStorage) EncodedObject ¶
func (o *ObjectStorage) EncodedObject(objType plumbing.ObjectType, objHash plumbing.Hash) (plumbing.EncodedObject, error)
EncodedObject returns the object with the specified hash and matching object type. If AnyObject is passed as the object type, only the object hash will be used in this lookup.
func (*ObjectStorage) EncodedObjectSize ¶
func (o *ObjectStorage) EncodedObjectSize(hash plumbing.Hash) (int64, error)
EncodedObjectSize returns the size of the contents stored against the object with the specified hash.
func (*ObjectStorage) HasEncodedObject ¶
func (o *ObjectStorage) HasEncodedObject(hash plumbing.Hash) error
HasEncodedObject checks if an object with the specified hash exists, returning nil if the object does exist, and an error if it does not.
func (*ObjectStorage) IterEncodedObjects ¶
func (o *ObjectStorage) IterEncodedObjects(objType plumbing.ObjectType) (storer.EncodedObjectIter, error)
IterEncodedObjects returns an iterator that traverses all of the available objects of the specified type.
func (*ObjectStorage) NewEncodedObject ¶
func (o *ObjectStorage) NewEncodedObject() plumbing.EncodedObject
NewEncodedObject returns a new copy of the default plumbing.MemoryObject.
func (*ObjectStorage) SetEncodedObject ¶
func (o *ObjectStorage) SetEncodedObject(obj plumbing.EncodedObject) (plumbing.Hash, error)
SetEncodedObject stores the object provided.
If the object contents cannot be read, or the object fails to be written to the database, a ZeroHash will be returned with the appropriate wrapped error.
type ReferenceStorage ¶
type ReferenceStorage struct {
// contains filtered or unexported fields
}
func (*ReferenceStorage) CheckAndSetReference ¶
func (r *ReferenceStorage) CheckAndSetReference(new, old *plumbing.Reference) error
func (*ReferenceStorage) CountLooseRefs ¶
func (r *ReferenceStorage) CountLooseRefs() (int, error)
func (*ReferenceStorage) IterReferences ¶
func (r *ReferenceStorage) IterReferences() (storer.ReferenceIter, error)
IterReferences returns an iterator capable of walking through all available Git references.
func (*ReferenceStorage) PackRefs ¶
func (r *ReferenceStorage) PackRefs() error
PackRefs is not currently implemented.
func (*ReferenceStorage) Reference ¶
func (r *ReferenceStorage) Reference(name plumbing.ReferenceName) (*plumbing.Reference, error)
Reference loads a Git reference from storage.
func (*ReferenceStorage) RemoveReference ¶
func (r *ReferenceStorage) RemoveReference(name plumbing.ReferenceName) error
RemoveReference deletes a Git reference from storage by its unique name.
func (*ReferenceStorage) SetReference ¶
func (r *ReferenceStorage) SetReference(ref *plumbing.Reference) error
SetReference writes a Git reference to storage, replacing it if reference with the same name alreayd exists.
type Storage ¶
type Storage struct {
ObjectStorage
ReferenceStorage
// The following structs are duplicated from the go-git memory storage
// implementation, however they are omitted from the declaration below.
memory.IndexStorage
memory.ShallowStorage
memory.ModuleStorage
memory.ConfigStorage
}
Storage is a struct implementation of the storage.Storer interface.
func NewStorage ¶
NewStorage creates an SQL-backed implementation of the storage.Storer interface that uses the supplied database client for all operations.
Below is a simple example of how one might create a storage interface that uses PostgreSQL and the pgx driver with a spurious connection string.
var db *sql.DB
var err error
db, err = sql.Open("pgx", "postgresql://user:pass@localhost")
if err != nil {
log.Fatal("Invalid DB config: ", err)
}
if err = db.Ping(); err != nil {
log.Fatal("DB unreachable: ", err)
}
storage := storage.NewStorage(db)