tinygit

package module
v0.0.0-...-f64af9c Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: MIT Imports: 17 Imported by: 0

README

tinygit

A tiny Git

Reference: pygit

Documentation

Index

Constants

View Source
const (
	// RepoRootPath root repo folder.
	RepoRootPath = ".tinygit"
	// ObjectsFolder objects folder.
	ObjectsFolder = "objects"
)

Variables

This section is empty.

Functions

func Add

func Add(path string) error

Add add file contents to the index.

func FindObject

func FindObject(sha1Prefix string) (string, error)

FindObject find object with given SHA-1 prefix and return path to object in object store, or raise ValueError if there are no objects or multiple objects with this prefix.

func HashObject

func HashObject(param HashParam) (string, string, error)

HashObject compute hash of object data of given type and write to object store if "WriteFile" is True. Return SHA-1 object hash as hex string.

func Initail

func Initail(repo string) error

Initail create directory for repo and initialize .tinygit directory.

func PrintHelp

func PrintHelp()

PrintHelp print the help message.

func Version

func Version() string

Version gets the version

func WriteIndex

func WriteIndex(indexes []Index) error

WriteIndex write list of Index objects to tinygit index file.

Types

type HashParam

type HashParam struct {
	Data      []byte
	ObjType   ObjType
	WriteFile bool
}

HashParam hash object params.

type Index

type Index struct {
	CTimeS int64
	CTimeN int64
	MTimeS int64
	MTimeN int64
	Dev    int32
	INO    uint64
	Mode   uint16
	UID    uint32
	GID    uint32
	Size   int64
	Sha1   string
	Flags  uint32
	Path   string
}

Index represents a index struct.

func (Index) Head

func (i Index) Head() ([]byte, error)

Head pack the head message.

type Indexes

type Indexes []Index

Indexes represents a index slice for sort.

func ReadIndex

func ReadIndex() (Indexes, error)

ReadIndex read tinygit index file and return list of Index objects.

func (Indexes) Len

func (idxs Indexes) Len() int

func (Indexes) Less

func (idxs Indexes) Less(i, j int) bool

func (Indexes) Sort

func (idxs Indexes) Sort() []Index

Sort sort the index.

func (Indexes) Swap

func (idxs Indexes) Swap(i, j int)

type ObjType

type ObjType = string

ObjType obejct type alias.

const (
	Blob   ObjType = "blob"
	Commit ObjType = "commit"
	Tree   ObjType = "tree"
)

There are three types of objects in the Git model: blobs (ordinary files), commits, and trees (these represent the state of a single directory).

type Object

type Object struct {
	Type ObjType
	Size int
	Data []byte
}

Object represents a tinygit object.

func NewObject

func NewObject(typ ObjType, data []byte) Object

NewObject creates a tinygit object.

func ReadObject

func ReadObject(sha1Prefix string) (Object, error)

ReadObject read object with given SHA-1 prefix.

func (Object) FormatData

func (o Object) FormatData() []byte

FormatData structs data.

func (Object) String

func (o Object) String() string

Directories

Path Synopsis
cmd
shared

Jump to

Keyboard shortcuts

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