Categorygithub.com/src-d/go-borges
modulepackage
0.1.3
Repository: https://github.com/src-d/go-borges.git
Documentation: pkg.go.dev

# README

GoDoc Build Status codecov.io Go Report Card

go-borges

This library abstracts read and write access to a set of go-git repositories. It comes with several implementations to support different storage methods:

  • plain: stored in the filesystem, supports transactions.
  • siva: rooted repositories in siva files, supports transactions. These files can be generated with gitcollector.
  • legacysiva: siva file generated by borges. This implementation only supports reading and does not support transactions.

When transactions are supported the writes to the repositories will be atomic and could only be seen by new readers when Commit function is called. That is, after opening a repository in read only mode any writes to it by another thread or process won't modify its contents. This is useful when the storage that is being used for reading repositories is being updated at the same time. More information and example in siva package documentation.

Installation

go-borges supports go modules and can be added to your project with:

$ go get github.com/src-d/go-borges

Example of utilization

This example lists the repositories downloaded by gitcollector.

package main

import (
	"fmt"
	"os"

	"github.com/src-d/go-borges"
	"github.com/src-d/go-borges/siva"
	"gopkg.in/src-d/go-billy.v4/osfs"
)

func main() {
	if len(os.Args) != 2 {
		fmt.Println("you need to provide the path of your siva files")
		os.Exit(1)
	}
	fs := osfs.New(os.Args[1])

	lib, err := siva.NewLibrary("library", fs, &siva.LibraryOptions{
		Bucket:        2,
		RootedRepo:    true,
		Transactional: true,
	})
	if err != nil {
		panic(err)
	}

	repos, err := lib.Repositories(borges.ReadOnlyMode)
	if err != nil {
		panic(err)
	}

	err = repos.ForEach(func(r borges.Repository) error {
		id := r.ID().String()
		head, err := r.R().Head()
		if err != nil {
			return err
		}

		fmt.Printf("repository: %v, HEAD: %v\n", id, head.Hash().String())
		return nil
	})
}

Contribute

Contributions are more than welcome, if you are interested please take a look to our Contributing Guidelines.

Code of Conduct

All activities under source{d} projects are governed by the source{d} code of conduct.

License

Apache License Version 2.0, see LICENSE.

# Packages

Package legacysiva implements a go-borges library that uses siva files as its storage backend.
No description provided by the author
No description provided by the author
Package siva implements a go-borges library that uses siva files as its storage backend.
No description provided by the author
No description provided by the author

# Functions

NewRepositoryID returns a new RepositoryID based on a given endpoint.

# Constants

ReadOnlyMode allows only read-only operations over a repository.
RWMode allows to perform read and write operations over a repository.

# Variables

ErrLibraryNotExists when a Library is requested and can't be found.
ErrLocationNotExists when a Location is requested and can't be found.
ErrModeNotSupported is returned in the case of a request to open a repository with a Mode not supported.
ErrNonTransactional returned when Repository.Commit is called on a repository that not support transactions.
ErrNotImplemented is returned by method of any implementation that are not implemented on this specific implementation.
ErrRepositoryExists an error returned on a request of Init on a location with a repository with this RepositoryID already exists.
ErrRepositoryNotExists when a Repository is requested and can't be found.
ErrStop is used to stop a ForEach function in an Iter.

# Interfaces

Library interface represents a group of different libraries and locations, it allows access to any repository stored on any library or location.
LibraryIterator represents a Location iterator.
Location interface represents a physical location where the repositories are stored, it allows access only to the repositories contained in this location.
LocationIterator represents a Location iterator.
Repository interface represents a git.Repository, with information about how it was open and where is located.
RepositoryIterator represents a Repository iterator.

# Type aliases

LibraryID represents a Library identifier.
LocationID represents a Location identifier.
Mode is the different modes to open a Repository.
RepositoryID represents a Repository identifier, these IDs regularly are based on a http or git remore URL, but can be based on any other concept.