repository

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package repository contains helper methods for working with the Git repo.

Package repository contains helper methods for working with a Git repo.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoConfigEntry       = errors.New("no config entry for the given key")
	ErrMultipleConfigEntry = errors.New("multiple config entry for the given key")
)
View Source
var (
	// ErrNotARepo is the error returned when the git repo root wan't be found
	ErrNotARepo = errors.New("not a git repository")
)

Functions

func CleanupTestRepos

func CleanupTestRepos(t testing.TB, repos ...Repo)

func NewMockRepoForTest

func NewMockRepoForTest() *mockRepoForTest

func ParseTimestamp

func ParseTimestamp(s string) (time.Time, error)

Types

type ClockedRepo

type ClockedRepo interface {
	Repo

	// LoadClocks read the clocks values from the on-disk repo
	LoadClocks() error

	// WriteClocks write the clocks values into the repo
	WriteClocks() error

	// CreateTime return the current value of the creation clock
	CreateTime() lamport.Time

	// CreateTimeIncrement increment the creation clock and return the new value.
	CreateTimeIncrement() (lamport.Time, error)

	// EditTime return the current value of the edit clock
	EditTime() lamport.Time

	// EditTimeIncrement increment the edit clock and return the new value.
	EditTimeIncrement() (lamport.Time, error)

	// WitnessCreate witness another create time and increment the corresponding
	// clock if needed.
	WitnessCreate(time lamport.Time) error

	// WitnessEdit witness another edition time and increment the corresponding
	// clock if needed.
	WitnessEdit(time lamport.Time) error
}

ClockedRepo is a Repo that also has Lamport clocks

type Config

type Config interface {
	// Store writes a single key/value pair in the config
	StoreString(key, value string) error

	// Store writes a key and timestamp value to the config
	StoreTimestamp(key string, value time.Time) error

	// Store writes a key and boolean value to the config
	StoreBool(key string, value bool) error

	// ReadAll reads all key/value pair matching the key prefix
	ReadAll(keyPrefix string) (map[string]string, error)

	// ReadBool read a single boolean value from the config
	// Return ErrNoConfigEntry or ErrMultipleConfigEntry if
	// there is zero or more than one entry for this key
	ReadBool(key string) (bool, error)

	// ReadBool read a single string value from the config
	// Return ErrNoConfigEntry or ErrMultipleConfigEntry if
	// there is zero or more than one entry for this key
	ReadString(key string) (string, error)

	// ReadTimestamp read a single timestamp value from the config
	// Return ErrNoConfigEntry or ErrMultipleConfigEntry if
	// there is zero or more than one entry for this key
	ReadTimestamp(key string) (time.Time, error)

	// RemoveAll removes all key/value pair matching the key prefix
	RemoveAll(keyPrefix string) error
}

Config represent the common function interacting with the repository config storage

type GitRepo

type GitRepo struct {
	Path string
	// contains filtered or unexported fields
}

GitRepo represents an instance of a (local) git repository.

func CreateTestRepo

func CreateTestRepo(bare bool) *GitRepo

func InitBareGitRepo

func InitBareGitRepo(path string) (*GitRepo, error)

InitBareGitRepo create a new --bare empty git repo at the given path

func InitGitRepo

func InitGitRepo(path string) (*GitRepo, error)

InitGitRepo create a new empty git repo at the given path

func NewGitRepo

func NewGitRepo(path string, witnesser Witnesser) (*GitRepo, error)

NewGitRepo determines if the given working directory is inside of a git repository, and returns the corresponding GitRepo instance if it is.

func SetupReposAndRemote

func SetupReposAndRemote(t testing.TB) (repoA, repoB, remote *GitRepo)

func (*GitRepo) AddRemote

func (repo *GitRepo) AddRemote(name string, url string) error

AddRemote add a new remote to the repository Not in the interface because it's only used for testing

func (*GitRepo) CopyRef

func (repo *GitRepo) CopyRef(source string, dest string) error

CopyRef will create a new reference with the same value as another one

func (*GitRepo) CreateTime

func (repo *GitRepo) CreateTime() lamport.Time

CreateTime return the current value of the creation clock

func (*GitRepo) CreateTimeIncrement

func (repo *GitRepo) CreateTimeIncrement() (lamport.Time, error)

CreateTimeIncrement increment the creation clock and return the new value.

func (*GitRepo) EditTime

func (repo *GitRepo) EditTime() lamport.Time

EditTime return the current value of the edit clock

func (*GitRepo) EditTimeIncrement

func (repo *GitRepo) EditTimeIncrement() (lamport.Time, error)

EditTimeIncrement increment the edit clock and return the new value.

func (*GitRepo) FetchRefs

func (repo *GitRepo) FetchRefs(remote, refSpec string) (string, error)

FetchRefs fetch git refs from a remote

func (*GitRepo) FindCommonAncestor

func (repo *GitRepo) FindCommonAncestor(hash1 git.Hash, hash2 git.Hash) (git.Hash, error)

FindCommonAncestor will return the last common ancestor of two chain of commit

func (*GitRepo) GetCoreEditor

func (repo *GitRepo) GetCoreEditor() (string, error)

GetCoreEditor returns the name of the editor that the user has used to configure git.

func (*GitRepo) GetPath

func (repo *GitRepo) GetPath() string

GetPath returns the path to the repo.

func (*GitRepo) GetRemotes

func (repo *GitRepo) GetRemotes() (map[string]string, error)

GetRemotes returns the configured remotes repositories.

func (*GitRepo) GetTreeHash

func (repo *GitRepo) GetTreeHash(commit git.Hash) (git.Hash, error)

GetTreeHash return the git tree hash referenced in a commit

func (*GitRepo) GetUserEmail

func (repo *GitRepo) GetUserEmail() (string, error)

GetUserEmail returns the email address that the user has used to configure git.

func (*GitRepo) GetUserName

func (repo *GitRepo) GetUserName() (string, error)

GetUserName returns the name the the user has used to configure git

func (*GitRepo) GlobalConfig

func (repo *GitRepo) GlobalConfig() Config

GlobalConfig give access to the git global configuration

func (*GitRepo) ListCommits

func (repo *GitRepo) ListCommits(ref string) ([]git.Hash, error)

ListCommits will return the list of commit hashes of a ref, in chronological order

func (*GitRepo) ListEntries

func (repo *GitRepo) ListEntries(hash git.Hash) ([]TreeEntry, error)

ListEntries will return the list of entries in a Git tree

func (*GitRepo) ListRefs

func (repo *GitRepo) ListRefs(refspec string) ([]string, error)

ListRefs will return a list of Git ref matching the given refspec

func (*GitRepo) LoadClocks

func (repo *GitRepo) LoadClocks() error

LoadClocks read the clocks values from the on-disk repo

func (*GitRepo) LocalConfig

func (repo *GitRepo) LocalConfig() Config

LocalConfig give access to the repository scoped configuration

func (*GitRepo) PushRefs

func (repo *GitRepo) PushRefs(remote string, refSpec string) (string, error)

PushRefs push git refs to a remote

func (*GitRepo) ReadData

func (repo *GitRepo) ReadData(hash git.Hash) ([]byte, error)

ReadData will attempt to read arbitrary data from the given hash

func (*GitRepo) RefExist

func (repo *GitRepo) RefExist(ref string) (bool, error)

RefExist will check if a reference exist in Git

func (*GitRepo) StoreCommit

func (repo *GitRepo) StoreCommit(treeHash git.Hash) (git.Hash, error)

StoreCommit will store a Git commit with the given Git tree

func (*GitRepo) StoreCommitWithParent

func (repo *GitRepo) StoreCommitWithParent(treeHash git.Hash, parent git.Hash) (git.Hash, error)

StoreCommitWithParent will store a Git commit with the given Git tree

func (*GitRepo) StoreData

func (repo *GitRepo) StoreData(data []byte) (git.Hash, error)

StoreData will store arbitrary data and return the corresponding hash

func (*GitRepo) StoreTree

func (repo *GitRepo) StoreTree(entries []TreeEntry) (git.Hash, error)

StoreTree will store a mapping key-->Hash as a Git tree

func (*GitRepo) UpdateRef

func (repo *GitRepo) UpdateRef(ref string, hash git.Hash) error

UpdateRef will create or update a Git reference

func (*GitRepo) WitnessCreate

func (repo *GitRepo) WitnessCreate(time lamport.Time) error

WitnessCreate witness another create time and increment the corresponding clock if needed.

func (*GitRepo) WitnessEdit

func (repo *GitRepo) WitnessEdit(time lamport.Time) error

WitnessEdit witness another edition time and increment the corresponding clock if needed.

func (*GitRepo) WriteClocks

func (repo *GitRepo) WriteClocks() error

WriteClocks write the clocks values into the repo

type MemConfig

type MemConfig struct {
	// contains filtered or unexported fields
}

func NewMemConfig

func NewMemConfig() *MemConfig

func (*MemConfig) ReadAll

func (mc *MemConfig) ReadAll(keyPrefix string) (map[string]string, error)

func (*MemConfig) ReadBool

func (mc *MemConfig) ReadBool(key string) (bool, error)

func (*MemConfig) ReadString

func (mc *MemConfig) ReadString(key string) (string, error)

func (*MemConfig) ReadTimestamp

func (mc *MemConfig) ReadTimestamp(key string) (time.Time, error)

func (*MemConfig) RemoveAll

func (mc *MemConfig) RemoveAll(keyPrefix string) error

RmConfigs remove all key/value pair matching the key prefix

func (*MemConfig) StoreBool

func (mc *MemConfig) StoreBool(key string, value bool) error

func (*MemConfig) StoreString

func (mc *MemConfig) StoreString(key, value string) error

func (*MemConfig) StoreTimestamp

func (mc *MemConfig) StoreTimestamp(key string, value time.Time) error

type ObjectType

type ObjectType int
const (
	Unknown ObjectType = iota
	Blob
	Tree
)

func ParseObjectType

func ParseObjectType(mode, objType string) (ObjectType, error)

func (ObjectType) Format

func (ot ObjectType) Format() string

type Repo

type Repo interface {
	RepoConfig
	RepoCommon

	// FetchRefs fetch git refs from a remote
	FetchRefs(remote string, refSpec string) (string, error)

	// PushRefs push git refs to a remote
	PushRefs(remote string, refSpec string) (string, error)

	// StoreData will store arbitrary data and return the corresponding hash
	StoreData(data []byte) (git.Hash, error)

	// ReadData will attempt to read arbitrary data from the given hash
	ReadData(hash git.Hash) ([]byte, error)

	// StoreTree will store a mapping key-->Hash as a Git tree
	StoreTree(mapping []TreeEntry) (git.Hash, error)

	// StoreCommit will store a Git commit with the given Git tree
	StoreCommit(treeHash git.Hash) (git.Hash, error)

	// StoreCommit will store a Git commit with the given Git tree
	StoreCommitWithParent(treeHash git.Hash, parent git.Hash) (git.Hash, error)

	// UpdateRef will create or update a Git reference
	UpdateRef(ref string, hash git.Hash) error

	// ListRefs will return a list of Git ref matching the given refspec
	ListRefs(refspec string) ([]string, error)

	// RefExist will check if a reference exist in Git
	RefExist(ref string) (bool, error)

	// CopyRef will create a new reference with the same value as another one
	CopyRef(source string, dest string) error

	// ListCommits will return the list of tree hashes of a ref, in chronological order
	ListCommits(ref string) ([]git.Hash, error)

	// ListEntries will return the list of entries in a Git tree
	ListEntries(hash git.Hash) ([]TreeEntry, error)

	// FindCommonAncestor will return the last common ancestor of two chain of commit
	FindCommonAncestor(hash1 git.Hash, hash2 git.Hash) (git.Hash, error)

	// GetTreeHash return the git tree hash referenced in a commit
	GetTreeHash(commit git.Hash) (git.Hash, error)
}

Repo represents a source code repository.

type RepoCommon

type RepoCommon interface {
	// GetPath returns the path to the repo.
	GetPath() string

	// GetUserName returns the name the the user has used to configure git
	GetUserName() (string, error)

	// GetUserEmail returns the email address that the user has used to configure git.
	GetUserEmail() (string, error)

	// GetCoreEditor returns the name of the editor that the user has used to configure git.
	GetCoreEditor() (string, error)

	// GetRemotes returns the configured remotes repositories.
	GetRemotes() (map[string]string, error)
}

RepoCommon represent the common function the we want all the repo to implement

type RepoConfig

type RepoConfig interface {
	// LocalConfig give access to the repository scoped configuration
	LocalConfig() Config

	// GlobalConfig give access to the git global configuration
	GlobalConfig() Config
}

RepoConfig access the configuration of a repository

type TreeEntry

type TreeEntry struct {
	ObjectType ObjectType
	Hash       git.Hash
	Name       string
}

func ParseTreeEntry

func ParseTreeEntry(line string) (TreeEntry, error)

func (TreeEntry) Format

func (entry TreeEntry) Format() string

Format the entry as a git ls-tree compatible line

type Witnesser

type Witnesser func(repo ClockedRepo) error

Witnesser is a function that will initialize the clocks of a repo from scratch

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL