repository

package
v0.0.0-...-5f9f762 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Objects     = "/objects/"
	Refs        = "/refs"
	Heads       = "/heads/"
	Head        = "/HEAD"
	Config      = "/config.json"
	Description = "Description"
	Index       = "/index"
)
View Source
const (
	FILE       Mode = "100644"
	EXECUTABLE      = "100755"
	DIR             = "04000"
)
View Source
const (
	BLOB   GitObjectType = "blob"
	TREE                 = "tree"
	COMMIT               = "commit"
)
View Source
const IndexParts = 5

Variables

View Source
var (
	//reader to read a raw content from given path
	Reader FileReader = func(path string) ([]byte, error) {
		return ioutil.ReadFile(path)
	}

	//reader to read raw content as git obj
	ObjReader ObjectReader = func(path string, formatter GitFileFormatter) (*DeserializedGitObject, error) {
		content, err := ioutil.ReadFile(path)
		if err != nil {
			return nil, err
		}
		return formatter.Deserialize(content)
	}
)

Functions

func ConfigPath

func ConfigPath(path string) string

func DefaultPath

func DefaultPath() string

func Exists

func Exists(path string) bool

Check if path exists

func GenerateHash

func GenerateHash(data []byte) (string, error)

func HeadPath

func HeadPath(path string) string

TODO:rename all path params to root

func HeadsPath

func HeadsPath(path string) string

func IndexPath

func IndexPath(path string) string

func Init

func Init(path string, userJson []byte) error

create git repository, returns an error if already exists

func ObjPath

func ObjPath(path string) string

func PathToBranch

func PathToBranch(branchName string) string

Types

type DefaultGitFileFormatter

type DefaultGitFileFormatter struct {
}

func (*DefaultGitFileFormatter) Deserialize

func (obj *DefaultGitFileFormatter) Deserialize(data []byte) (*DeserializedGitObject, error)

func (*DefaultGitFileFormatter) Save

func (obj *DefaultGitFileFormatter) Save(serialized *SerializedGitObject, objPath string) error

func (*DefaultGitFileFormatter) Serialize

func (obj *DefaultGitFileFormatter) Serialize(data []byte, objType GitObjectType) (*SerializedGitObject, error)

type DeserializedGitObject

type DeserializedGitObject struct {
	ObjType GitObjectType
	Content string
}

type FileReader

type FileReader func(path string) ([]byte, error)

type GitFileFormatter

type GitFileFormatter interface {
	Serialize(data []byte, objType GitObjectType) (*SerializedGitObject, error)
	Deserialize(data []byte) (*DeserializedGitObject, error)
	Save(serialized *SerializedGitObject, path string) error
}

type GitObjectType

type GitObjectType string

func AsGitObjectType

func AsGitObjectType(str string) (GitObjectType, error)

convert given string to git object type

func TypeByHash

func TypeByHash(
	objPath string,
	hash Hash,
	reader FileReader,
	fileFormatter GitFileFormatter,
) (GitObjectType, error)

Get type of a object by given hash

type Hash

type Hash string

func NewHash

func NewHash(hash string) (Hash, error)

func (Hash) Dir

func (h Hash) Dir() string

func (Hash) FileName

func (h Hash) FileName() string

func (Hash) Path

func (h Hash) Path(objPath string) string

returns the whole directory to the file with given hash

type IndexEntry

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

func NewIndex

func NewIndex(
	file string,
	mode Mode,
	hash Hash,
	objectPath string,
) (*IndexEntry, error)

file - the file's name to index plainMode - the files' type hash - the hash of this file to index objPath - path to object repository

func ParseLineToIndex

func ParseLineToIndex(line string) (*IndexEntry, error)

Parse given line to index entry

func (IndexEntry) BlobString

func (entry IndexEntry) BlobString(part int) string

String representation of a single file in a tree

func (IndexEntry) Depth

func (entry IndexEntry) Depth() int

Get the depth of a file for given index

func (IndexEntry) Path

func (entry IndexEntry) Path() string

func (IndexEntry) PathParts

func (entry IndexEntry) PathParts() []string

func (IndexEntry) String

func (entry IndexEntry) String() string

TODO: add test

type Mode

type Mode string

func AsMode

func AsMode(mode string) (Mode, error)

type ObjectReader

type ObjectReader func(
	path string,
	formatter GitFileFormatter,
) (*DeserializedGitObject, error)

type SerializedGitObject

type SerializedGitObject struct {
	Hash    Hash
	Content []byte
}

type TreeAlreadyExistError

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

func NewTreeAlreadyExistError

func NewTreeAlreadyExistError(message string) *TreeAlreadyExistError

func (*TreeAlreadyExistError) Error

func (err *TreeAlreadyExistError) Error() string

Jump to

Keyboard shortcuts

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