Documentation ¶
Overview ¶
Package legacysiva implements a go-borges library that uses siva files as its storage backend. It has a 1-to-1 matching of locations and repositories and no filtering or conversion is done to its references or objects.
It's meant to be used with siva files generated by borges. It's also a read only implementation and does not support transactionality.
Example ¶
headReg := regexp.MustCompile(`^refs/heads/HEAD/([0-9a-f-]{36})$`) fs := osfs.New("./_testdata") lib, err := legacysiva.NewLibrary("library", fs, &legacysiva.LibraryOptions{ Bucket: 0, }) if err != nil { panic(err) } repos, err := lib.Repositories(borges.ReadOnlyMode) if err != nil { panic(err) } var heads []string err = repos.ForEach(func(r borges.Repository) error { refs, err := r.R().References() if err != nil { panic(err) } err = refs.ForEach(func(ref *plumbing.Reference) error { refName := ref.Name().String() if !headReg.Match([]byte(refName)) { return nil } location := r.Location().ID() id := headReg.FindAllString(refName, -1)[0] head := ref.Hash().String() h := fmt.Sprintf("location: %v, id %v, head: %v", location, id, head) heads = append(heads, h) return nil }) return err }) if err != nil { panic(err) } sort.Strings(heads) for _, h := range heads { fmt.Println(h) }
Output: location: 3974996807a9f596cf25ac3a714995c24bb97e2c, id refs/heads/HEAD/016b92d2-5b60-cbf8-a7d8-f0e0c6832d91, head: ce1e0703402e989bedf03d5df535401340f54b42 location: 3974996807a9f596cf25ac3a714995c24bb97e2c, id refs/heads/HEAD/016b92d2-5b62-e877-df42-887c21e354bd, head: ce1e0703402e989bedf03d5df535401340f54b42 location: 3974996807a9f596cf25ac3a714995c24bb97e2c, id refs/heads/HEAD/016b92d2-5b68-4376-da62-9bd3f44ccdf7, head: ce1e0703402e989bedf03d5df535401340f54b42 location: f2cee90acf3c6644d51a37057845b98ab1580932, id refs/heads/HEAD/016b92d2-5b58-9c19-84e5-ec45469a57ec, head: 4de1a2d995bc79d6e39bef647accbde6bec9093f location: f2cee90acf3c6644d51a37057845b98ab1580932, id refs/heads/HEAD/016b92d2-5b5c-8dac-2ae6-6437e11dad17, head: 38aec3212d377ae36b72fcc068f57e7a6344c5d4 location: f2cee90acf3c6644d51a37057845b98ab1580932, id refs/heads/HEAD/016b92d2-5b5e-2925-a091-7cdb57ab3c5e, head: 38aec3212d377ae36b72fcc068f57e7a6344c5d4
Index ¶
- type Library
- func (l *Library) Get(id borges.RepositoryID, _ borges.Mode) (borges.Repository, error)
- func (l *Library) GetOrInit(_ borges.RepositoryID) (borges.Repository, error)
- func (l *Library) Has(id borges.RepositoryID) (bool, borges.LibraryID, borges.LocationID, error)
- func (l *Library) ID() borges.LibraryID
- func (l *Library) Init(id borges.RepositoryID) (borges.Repository, error)
- func (l *Library) Location(id borges.LocationID) (borges.Location, error)
- func (l *Library) Locations() (borges.LocationIterator, error)
- func (l *Library) Repositories(_ borges.Mode) (borges.RepositoryIterator, error)
- type LibraryOptions
- type Location
- func (l *Location) Get(id borges.RepositoryID, _ borges.Mode) (borges.Repository, error)
- func (l *Location) GetOrInit(_ borges.RepositoryID) (borges.Repository, error)
- func (l *Location) Has(id borges.RepositoryID) (bool, error)
- func (l *Location) ID() borges.LocationID
- func (l *Location) Init(_ borges.RepositoryID) (borges.Repository, error)
- func (l *Location) Library() borges.Library
- func (l *Location) Repositories(_ borges.Mode) (borges.RepositoryIterator, error)
- type Repository
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Library ¶
type Library struct {
// contains filtered or unexported fields
}
Library represents a borges.Library implementation based on siva files archiving rooted repositories using an old structure. See https://github.com/src-d/borges/blob/master/docs/using-borges/key-concepts.md#rooted-repository. It only supports read operations on the repositories and it doesn't support transactionality. Each siva file is managed as a single repository.
func NewLibrary ¶
func NewLibrary( id string, fs billy.Filesystem, options *LibraryOptions, ) (*Library, error)
NewLibrary builds a new Library.
func (*Library) Get ¶
Get implements the borges.Library interface. It only retrieves repositories in borges.ReadOnlyMode ignoring the given parameter.
func (*Library) ID ¶
func (l *Library) ID() borges.LibraryID
ID implements the borges.Library interface.
func (*Library) Repositories ¶
Repositories implements the borges.Library interface. It only retrieves repositories in borges.ReadOnlyMode ignoring the given parameter.
type LibraryOptions ¶
type LibraryOptions struct { // RegistryCache is the maximum number of locations in the cache. A // value of 0 will be set a default value of 10000. RegistryCache int // Bucket level to use to search and create siva files. Bucket int // Cache specifies the shared cache used in repositories. If not defined // a new default cache will be created for each repository. Cache cache.Object // Timeout set a timeout for library operations. Some operations could // potentially take long so timing out them will make an error be // returned. A 0 value sets a default value of 20 seconds. Timeout time.Duration }
LibraryOptions hold configuration options for the library.
type Location ¶
type Location struct {
// contains filtered or unexported fields
}
Location represents a siva file archiving several git repositories using an old rooted repository structure see https://github.com/src-d/borges/blob/master/docs/using-borges/key-concepts.md#rooted-repository.
func (*Location) Get ¶
Get implements the borges.Location interface. It only retrieves repositories in borges.ReadOnlyMode ignoring the given parameter.
func (*Location) ID ¶
func (l *Location) ID() borges.LocationID
ID implements the borges.Location interface.
func (*Location) Library ¶
func (l *Location) Library() borges.Library
Library implements the borges.Location interface.
func (*Location) Repositories ¶
Repositories implements the borges.Location interface. It only retrieves repositories in borges.ReadOnlyMode ignoring the given parameter.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
Repository is an implementation of borges.Repository interface based on siva files archiving rooted repositories using an old structure. See https://github.com/src-d/borges/blob/master/docs/using-borges/key-concepts.md#rooted-repository. It only supports read operations on the repositories and it doesn't support transactionality.
func (*Repository) Close ¶
func (r *Repository) Close() error
Close implements the borges.Repository interface.
func (*Repository) Commit ¶
func (r *Repository) Commit() error
Commit implements the borges.Repository interface. It always returns an borges.ErrNonTransactional error.
func (*Repository) FS ¶
func (r *Repository) FS() billy.Filesystem
FS implements the borges.Repository interface.
func (*Repository) ID ¶
func (r *Repository) ID() borges.RepositoryID
ID implements the borges.Repository interface.
func (*Repository) Location ¶
func (r *Repository) Location() borges.Location
Location implements the borges.Repository interface.
func (*Repository) Mode ¶
func (r *Repository) Mode() borges.Mode
Mode implements the borges.Repository interface. It always returns borges.ReadOnlyMode.
func (*Repository) R ¶
func (r *Repository) R() *git.Repository
R implements the borges.Repository interface.