hvrt

package
v0.0.0-...-1bd926a Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: 0BSD Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const HashValueDelimiter = ":"
View Source
const (
	WorkTreeConfigDir = ".hvrt"
)

Variables

View Source
var (
	NotImplementedError error = errors.New("feature not yet implemented")
	MissingDSNError     error = errors.New("DSN is empty")
)
View Source
var BareVersion string
View Source
var FSError = errors.New("Could not initialize due to issue with error")
View Source
var FormattedVersion string
View Source
var SQLDialectToDrivers = map[string]string{
	"sqlite":   sqliteshim.ShimName,
	"postgres": "postgresql",
}
View Source
var SQLFiles embed.FS

SQL files for all operations for all supported DB dialects

View Source
var SQLStrings_sqlite_work_tree_read_head_commit string
View Source
var SqliteDefaultOpts = map[string][]string{

	"mode": {"rwc"},

	"_txlock": {"immediate"},

	"_pragma": {"journal_mode(WAL)", "case_sensitive_like(1)", "foreign_keys(1)"},
}
View Source
var WorkTreeDBName = "work_tree_state.sqlite"

Functions

func AddFile

func AddFile(file_to_add io.ReadSeeker, file_path string, tx *sql.Tx) error

FIXME: pass prepared statements as a map or something, so that they can be bound to the transaction and be reused/cached across multiple calls to the singular `AddFile` function, instead of being prepared again each time the function is called. Reusing prepared statements this way, we should see a big performance increase, which will make a difference when we are adding lots of files within a single transaction.

func AddFiles

func AddFiles(work_tree string, file_paths []string) error

func AddParmsToDSN

func AddParmsToDSN(dsn_url *url.URL, parms map[string][]string) (*url.URL, error)

func CommitWorktree

func CommitWorktree(work_tree, message, author, committer string) error

func CopyOps

func CopyOps(ops map[string][]string) map[string][]string

func GetExistingRepoDB

func GetExistingRepoDB(work_tree string) (*sql.DB, error)

func GetExistingWorktreeDB

func GetExistingWorktreeDB(work_tree string) (*sql.DB, error)

func GetRepoDBUri

func GetRepoDBUri(work_tree string) (db_uri, db_type string, err error)

func GetWorktreeDBPath

func GetWorktreeDBPath(work_tree string) string

func InitLocal

func InitLocal(repo_file, default_branch string, inner_thunk ThunkErr) error

func InitLocalAll

func InitLocalAll(repo_file, work_tree, default_branch string) error

func InitWorkTree

func InitWorkTree(work_tree, default_branch string, inner_thunk ThunkErr) error

func InitWorkTreeConfig

func InitWorkTreeConfig(work_tree string, inner_thunk ThunkErr) error

func NilThunk

func NilThunk()

func NilThunkAny

func NilThunkAny() any

func NilThunkErr

func NilThunkErr() error

func SliceContains

func SliceContains[T comparable](slc []T, comp T) bool

func SqliteDSN

func SqliteDSN(path string, parms map[string][]string) string

Types

type Commit

type Commit struct {
	Headers HeaderMap
	Tree    Tree
}

func (*Commit) HashBytes

func (c *Commit) HashBytes() []byte

type FileHashPair

type FileHashPair struct {
	HashAlgo  string
	HexDigest string
	FilePath  string
}

func HashFile

func HashFile(file_path string) (FileHashPair, error)

type HashAlgorithm

type HashAlgorithm string
const (
	SHA3_256 HashAlgorithm = "sha3-256"
)

HashAlgorithm constants

type HashType

type HashType string
const (
	CHUNK_TYPE   HashType = "chunk"
	BLOB_TYPE    HashType = "blob"
	FILE_ID_TYPE HashType = "file_id"
	TREE_TYPE    HashType = "tree"
	COMMIT_TYPE  HashType = "commit"
	BUNDLE_TYPE  HashType = "bundle"
)

HashType constants

type HashValue

type HashValue struct {
	Type      HashType
	Algorithm HashAlgorithm
	HexDigest string
}

func CalculateBlob

func CalculateBlob(blob io.Reader, hasher NamedHash) (HashValue, error)

func CalculateFileID

func CalculateFileID(path string, commit HashValue, parents []HashValue) (HashValue, error)

func (HashValue) HashBytes

func (hv HashValue) HashBytes() []byte

func (HashValue) ToString

func (hv HashValue) ToString() string

func (HashValue) ToStringSlice

func (hv HashValue) ToStringSlice() []string

type HashValueGenerator

type HashValueGenerator interface {
	GenerateHashValue() (HashValue, error)
}

type Hashable

type Hashable interface {
	// bytes to pass to a hash.Hash instance
	HashBytes() []byte
}

type HavartiState

type HavartiState struct {

	// Flag to allow potentially unsafe operations that could lose history
	AllowUnsafe bool

	// Verbosity level
	Verbosity int
	// contains filtered or unexported fields
}

Struct definition that contains all state required to run an instance of Havarti

func NewHavartiState

func NewHavartiState(workTreeFS fs.FS, cwd *string, workTree *string, dataSourceName string, dbDriverName string) (*HavartiState, error)

Function to return a new HavartiState

func (*HavartiState) AllowUnsafeTemporarily

func (hs *HavartiState) AllowUnsafeTemporarily(thnk ThunkErr) error

Set HavartState to allow potentially unsafe operations during the duration of the thunk. When the thunk returns, the state will be restored to its previous value. If the value is changed during the duration of the thunk, that value will be overwritten by the restored previous value. Any error returned by the thunk is returned by this method.

func (*HavartiState) ConnectToRepoDB

func (hs *HavartiState) ConnectToRepoDB(writable, create bool) (*sql.DB, error)

func (*HavartiState) GetDSN

func (hs *HavartiState) GetDSN() (*url.URL, error)

func (*HavartiState) GetOriginalWorkDir

func (hs *HavartiState) GetOriginalWorkDir() (string, error)

func (*HavartiState) GetWorkTree

func (hs *HavartiState) GetWorkTree() (string, error)

func (*HavartiState) InitLocalAll

func (hs *HavartiState) InitLocalAll(default_branch string) error

func (*HavartiState) SetWorkTree

func (hs *HavartiState) SetWorkTree(workTree string)

Set HavartState workTree

func (*HavartiState) Status

func (hs *HavartiState) Status() (*RepoStat, error)

Method that returns the status of a repo given a HavartiState struct pointer

type HeaderMap

type HeaderMap map[string]string

func (HeaderMap) HashBytes

func (hm HeaderMap) HashBytes() []byte

type HvrtConfig

type HvrtConfig struct {
	Worktree struct {
		Repo struct {
			Type string
			URI  string
		}
	}
}

type NamedHash

type NamedHash interface {
	hash.Hash
	Name() HashAlgorithm
	HashBytes(t HashType, b []byte) HashValue
	HashReader(r io.Reader) HashValue
}

Implements `hash.Hash` interface, but also returns the name of the algorithm used for the hash.

func NewNamedHash

func NewNamedHash(name HashAlgorithm) (NamedHash, error)

type RepoStat

type RepoStat struct {
	DelPaths []string
	ModPaths []string
	NewPaths []string
	UnkPaths []string
}

type Thunk

type Thunk func()

type ThunkAny

type ThunkAny func() any

type ThunkErr

type ThunkErr func() error

type Tree

type Tree struct {
	Members []TreeMember
}

func (*Tree) HashBytes

func (t *Tree) HashBytes() []byte

type TreeMember

type TreeMember struct {
	Path   string
	FileId HashValue
	Blob   HashValue
}

func (*TreeMember) HashBytes

func (t *TreeMember) HashBytes() []byte

Jump to

Keyboard shortcuts

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