model

package
v0.0.0-...-dba7d8a Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BranchDir = "refs/heads/"
)
View Source
const GitDir = ".mgit"

Variables

View Source
var (
	ERROR_READ_OBJECT = errors.New("failed to read object's format")
)
View Source
var HashRegx = regexp.MustCompile("^[0-9A-Fa-f]{4,40}$")

Functions

func CheckIgnore

func CheckIgnore(p string, rules *GitIgnore) bool

func CreateRef

func CreateRef(repo *Repository, name, sha string)

func FindObject

func FindObject(repo *Repository, name, format string, follow bool) string

If name is HEAD, it will just resolve .git/HEAD; If name is a full hash, this hash is returned unmodified. If name looks like a short hash, it will collect objects whose full hash begin with this short hash. At last, it will resolve tags and branches matching name.

func GetActiveBranch

func GetActiveBranch(repo *Repository) string

func GetRefSha

func GetRefSha(repo *Repository, ref string) string

func Index2Tree

func Index2Tree(repo *Repository, index *Index) string

func ListRef

func ListRef(repo *Repository, p string) map[string]any

func Tree2Map

func Tree2Map(repo *Repository, ref string, prefix string) map[string]string

树扁平化

func WriteIndex

func WriteIndex(repo *Repository, index *Index)

func WriteObject

func WriteObject(repo *Repository, obj Object) string

Types

type BlobObj

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

存储用户文件数据,不需要特殊处理

func (*BlobObj) Deserialize

func (b *BlobObj) Deserialize(data []byte)

func (*BlobObj) Format

func (b *BlobObj) Format() string

func (*BlobObj) Serialize

func (b *BlobObj) Serialize(_ *Repository) []byte

type CommitObj

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

func CreateCommit

func CreateCommit(repo *Repository, tree, parent, author, msg string, ts time.Time) *CommitObj

func NewCommitObj

func NewCommitObj() *CommitObj

func (*CommitObj) Deserialize

func (c *CommitObj) Deserialize(data []byte)

func (*CommitObj) Format

func (c *CommitObj) Format() string

func (*CommitObj) KV

func (c *CommitObj) KV() *kvlm

func (*CommitObj) Serialize

func (c *CommitObj) Serialize(_ *Repository) []byte

type GitIgnore

type GitIgnore struct {
	Absolute []*IgnoreRule            // 不在项目源码路径下的 .gitignore 文件,例如 ~/.config/git/ignore 或 .git/info/exclude
	Scoped   map[string][]*IgnoreRule // 存在于各个目录下的 .gitignore
}

func ReadGitignore

func ReadGitignore(repo *Repository) *GitIgnore

type IgnoreRule

type IgnoreRule struct {
	Rule     string
	Excluded bool
}

type Index

type Index struct {
	Version int
	Entries []*IndexEntry
}

func NewIndex

func NewIndex(ver int, entries []*IndexEntry) *Index

func ReadIndex

func ReadIndex(repo *Repository) *Index

type IndexEntry

type IndexEntry struct {
	Ctime          TimePair
	Mtime          TimePair
	Device         int64 // the ID of device containing this file
	Inode          int64 // inode
	ModeType       int   // The object type, either b1000 (regular), b1010 (symlink), b1110 (gitlink)
	ModePerms      int   // The object permissions, an integer
	Uid            int
	Gid            int
	Fsize          int64
	Sha            string
	FlagAssumValid bool
	FlagStage      int64
	Name           string // full path
}

type Object

type Object interface {
	Format() string
	Serialize(repo *Repository) []byte
	Deserialize(data []byte)
}

func NewBlobObj

func NewBlobObj() Object

func ReadObject

func ReadObject(repo *Repository, sha string) Object

type Repository

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

func CreateRepository

func CreateRepository(p string) (*Repository, error)

func FindRepo

func FindRepo(p string) *Repository

func (*Repository) GitDir

func (r *Repository) GitDir() string

func (*Repository) RepoFile

func (r *Repository) RepoFile(mkdir bool, paths ...string) (string, error)

组装 .git/** 文件字符串,如果父目录缺失则创建目录结构

func (*Repository) SetGitDir

func (r *Repository) SetGitDir(p string)

func (*Repository) SetWorktree

func (r *Repository) SetWorktree(p string)

func (*Repository) Worktree

func (r *Repository) Worktree() string

type TagObj

type TagObj struct {
	CommitObj
}

func NewTagObj

func NewTagObj() *TagObj

type TimePair

type TimePair struct {
	S  int64
	NS int64
}

type TreeObj

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

func NewTreeObj

func NewTreeObj() *TreeObj

func (*TreeObj) Deserialize

func (t *TreeObj) Deserialize(data []byte)

func (*TreeObj) Format

func (t *TreeObj) Format() string

func (*TreeObj) Items

func (t *TreeObj) Items() []*treeLeaf

func (*TreeObj) Serialize

func (t *TreeObj) Serialize(repo *Repository) []byte

Jump to

Keyboard shortcuts

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