Documentation ¶
Index ¶
- Constants
- Variables
- func CheckIgnore(p string, rules *GitIgnore) bool
- func CreateRef(repo *Repository, name, sha string)
- func FindObject(repo *Repository, name, format string, follow bool) string
- func GetActiveBranch(repo *Repository) string
- func GetRefSha(repo *Repository, ref string) string
- func Index2Tree(repo *Repository, index *Index) string
- func ListRef(repo *Repository, p string) map[string]any
- func Tree2Map(repo *Repository, ref string, prefix string) map[string]string
- func WriteIndex(repo *Repository, index *Index)
- func WriteObject(repo *Repository, obj Object) string
- type BlobObj
- type CommitObj
- type GitIgnore
- type IgnoreRule
- type Index
- type IndexEntry
- type Object
- type Repository
- type TagObj
- type TimePair
- type TreeObj
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 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 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 (*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 (*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 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 TreeObj ¶
type TreeObj struct {
// contains filtered or unexported fields
}
func NewTreeObj ¶
func NewTreeObj() *TreeObj
func (*TreeObj) Deserialize ¶
func (*TreeObj) Serialize ¶
func (t *TreeObj) Serialize(repo *Repository) []byte
Click to show internal directories.
Click to hide internal directories.