git

package module
v0.0.0-...-16c3751 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2017 License: Apache-2.0 Imports: 24 Imported by: 89

README

GoGits - Git

Package GoGits - Git is a pure Go implementation of Git manipulation.

History

  • This repository was a fork but it's now completely no relation with the upstream.

Requirements

  • Git: In order to not affects development of Gogs, some of APIs use Git commands, but will eventually rewritten in Go.

License

Go Walker is under Apache v2 License. See the LICENSE file for the full license text.

Documentation

Overview

Package GoGits - Git is a pure Go implementation of Git manipulation.

Index

Constants

View Source
const (
	ItemsPerPage   = 50
	ItemsPerSearch = 100
)

Variables

View Source
var (
	ErrBranchExisted = errors.New("branch has existed")
)
View Source
var (
	ErrNotExist = errors.New("error not exist")
)
View Source
var (
	IdNotExist = errors.New("sha1 id not exist")
)
View Source
var TreeEntryRe = regexp.MustCompile("^([0-9]+) ([^\x00]+)\x00")

Functions

func CreateBranch

func CreateBranch(repoPath, branchName, id string) error

func CreateRef

func CreateRef(head, repoPath, branchName, id string) error

func CreateTag

func CreateTag(repoPath, tagName, id string) error

func IntToStr

func IntToStr(n int) string

func IsBranchExist

func IsBranchExist(repoPath, branchName string) bool

func IsSha1

func IsSha1(sha1 string) bool

func NewId

func NewId(b []byte) (sha1, error)

Create a new sha1 from a 20 byte slice.

func NewIdFromString

func NewIdFromString(s string) (sha1, error)

Create a new sha1 from a Sha1 string of length 40.

func ParseModeType

func ParseModeType(modeString string) (EntryMode, ObjectType, error)

func PrependObjectHeader

func PrependObjectHeader(objectType ObjectType, r io.ReadSeeker) (io.Reader, error)

Add '<type> <size>\x00' to beginning of `r`.

func RefEndName

func RefEndName(refStr string) string

func ScanTreeEntry

func ScanTreeEntry(
	data []byte,
	atEOF bool,
) (
	advance int, token []byte, err error,
)

func StoreObjectSHA

func StoreObjectSHA(
	objectType ObjectType,
	w io.Writer,
	r io.ReadSeeker,
) (sha1, error)

Write an the object contents in `r` in compressed form to `w` and return the hash. Special case: if `w` is `ioutil.Discard`, the data is not compressed, since the data is not consumed anywhere.

func StrToInt

func StrToInt(str string) (int, error)

func UnpackRefs

func UnpackRefs(repoPath string) error

UnpackRefs unpacks 'packed-refs' to git repository.

Types

type ArchiveType

type ArchiveType int
const (
	AT_ZIP ArchiveType = iota + 1
	AT_TARGZ
)

type Blob

type Blob struct {
	*TreeEntry
}

func (*Blob) Data

func (b *Blob) Data() (io.ReadCloser, error)

type Commit

type Commit struct {
	Tree
	Id            sha1 // The id of this commit object
	Author        *Signature
	Committer     *Signature
	CommitMessage string
	// contains filtered or unexported fields
}

Commit represents a git commit.

func (*Commit) CommitsBefore

func (c *Commit) CommitsBefore() (*list.List, error)

func (*Commit) CommitsBeforeUntil

func (c *Commit) CommitsBeforeUntil(commitId string) (*list.List, error)

func (*Commit) CommitsByRange

func (c *Commit) CommitsByRange(page int) (*list.List, error)

func (*Commit) CommitsCount

func (c *Commit) CommitsCount() (int, error)

func (*Commit) CreateArchive

func (c *Commit) CreateArchive(path string, archiveType ArchiveType) error

func (*Commit) GetCommitOfRelPath

func (c *Commit) GetCommitOfRelPath(relPath string) (*Commit, error)

func (*Commit) Message

func (c *Commit) Message() string

Return the commit message. Same as retrieving CommitMessage directly.

func (*Commit) Parent

func (c *Commit) Parent(n int) (*Commit, error)

Return parent number n (0-based index)

func (*Commit) ParentCount

func (c *Commit) ParentCount() int

Return the number of parents of the commit. 0 if this is the root commit, otherwise 1,2,...

func (*Commit) ParentId

func (c *Commit) ParentId(n int) (id sha1, err error)

Return oid of the parent number n (0-based index). Return nil if no such parent exists.

func (*Commit) SearchCommits

func (c *Commit) SearchCommits(keyword string) (*list.List, error)

func (*Commit) Summary

func (c *Commit) Summary() string

func (*Commit) TreeId

func (c *Commit) TreeId() sha1

Return oid of the (root) tree of this commit.

type CommitComparator

type CommitComparator func(current, parent *Commit) bool

CommitComparator defines callback type for checking commit equalty. If it returns true then commits are considered equal. See "History Simplification" chapter of git-log man for details

type CommitWalkCallback

type CommitWalkCallback func(*Commit) (HistoryWalkerAction, error)

type Entries

type Entries []*TreeEntry

func (Entries) Len

func (bs Entries) Len() int

func (Entries) Less

func (bs Entries) Less(i, j int) bool

func (Entries) Sort

func (bs Entries) Sort()

func (Entries) Swap

func (bs Entries) Swap(i, j int)

type EntryMode

type EntryMode int
const (
	ModeBlob    EntryMode = 0100644
	ModeExec    EntryMode = 0100755
	ModeSymlink EntryMode = 0120000
	ModeCommit  EntryMode = 0160000
	ModeTree    EntryMode = 0040000
)

There are only a few file modes in Git. They look like unix file modes, but they can only be one of these.

type HistoryWalkerAction

type HistoryWalkerAction int
const (
	// drop commit and do not follow parents
	HWDrop HistoryWalkerAction = 0
	// take commit but not traverse parents
	HWTakeCommit HistoryWalkerAction = 1 << iota
	// drop commit but traverse parents
	HWFollowParents
	// stop traverse
	HWStop

	// take commit and follow parents
	HWTakeAndFollow = HWTakeCommit | HWFollowParents
)

type ObjectType

type ObjectType int

Who am I?

const (
	ObjectCommit ObjectType = 0x10
	ObjectTree   ObjectType = 0x20
	ObjectBlob   ObjectType = 0x30
	ObjectTag    ObjectType = 0x40
)

func (ObjectType) String

func (t ObjectType) String() string

type Repository

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

A Repository is the base of all other actions. If you need to lookup a commit, tree or blob, you do it from here.

func OpenRepository

func OpenRepository(path string) (*Repository, error)

Open the repository at the given path.

func (*Repository) CommitsBefore

func (repo *Repository) CommitsBefore(commitId string) (*list.List, error)

CommitsBefore returns a list of all commits before commitId and *also* includes the *Commit representing commitId in the list.

The (list.Element).Value of the list returned if of type *Commit.

func (*Repository) CommitsBetween

func (repo *Repository) CommitsBetween(last *Commit, before *Commit) (*list.List, error)

used only for single tree, (]

func (*Repository) CommitsByFileAndRange

func (repo *Repository) CommitsByFileAndRange(branch, file string, page int) (*list.List, error)

func (*Repository) CommitsByRange

func (repo *Repository) CommitsByRange(commitId string, page int) (*list.List, error)

GetCommitsByRange returns certain number of commits with given page of repository.

func (*Repository) CommitsCount

func (repo *Repository) CommitsCount(commitId string) (int, error)

func (*Repository) CreateBranch

func (repo *Repository) CreateBranch(branchName, idStr string) error

func (*Repository) CreateTag

func (repo *Repository) CreateTag(tagName, idStr string) error

func (*Repository) FileCommitsCount

func (repo *Repository) FileCommitsCount(branch, file string) (int, error)

func (*Repository) GetBranches

func (repo *Repository) GetBranches() ([]string, error)

func (*Repository) GetCommit

func (repo *Repository) GetCommit(commitId string) (*Commit, error)

Find the commit object in the repository.

func (*Repository) GetCommitIdOfBranch

func (repo *Repository) GetCommitIdOfBranch(branchName string) (string, error)

func (*Repository) GetCommitIdOfTag

func (repo *Repository) GetCommitIdOfTag(tagName string) (string, error)

func (*Repository) GetCommitOfBranch

func (repo *Repository) GetCommitOfBranch(branchName string) (*Commit, error)

get branch's last commit or a special commit by id string

func (*Repository) GetCommitOfRelPath

func (repo *Repository) GetCommitOfRelPath(commitId, relPath string) (*Commit, error)

func (*Repository) GetCommitOfTag

func (repo *Repository) GetCommitOfTag(tagName string) (*Commit, error)

func (*Repository) GetTag

func (repo *Repository) GetTag(tagName string) (*Tag, error)

func (*Repository) GetTags

func (repo *Repository) GetTags() ([]string, error)

GetTags returns all tags of given repository.

func (*Repository) GetTree

func (repo *Repository) GetTree(idStr string) (*Tree, error)

Find the tree object in the repository.

func (*Repository) HaveObject

func (repo *Repository) HaveObject(idStr string) (found, packed bool, err error)

func (*Repository) HaveObjectFromReadSeeker

func (repo *Repository) HaveObjectFromReadSeeker(
	objectType ObjectType,
	r io.ReadSeeker,
) (found bool, id sha1, err error)

Returns true if the content in `io.ReadSeeker` is aleady present in the object database. Leaves the initial seek position of `r` intact.

func (*Repository) IsBranchExist

func (repo *Repository) IsBranchExist(branchName string) bool

func (*Repository) IsTagExist

func (repo *Repository) IsTagExist(tagName string) bool

func (*Repository) SearchCommits

func (repo *Repository) SearchCommits(commitId, keyword string) (*list.List, error)

SearchCommits searches commits in given commitId and keyword of repository.

func (*Repository) StoreObjectLoose

func (repo *Repository) StoreObjectLoose(
	objectType ObjectType,
	r io.ReadSeeker,
) (sha1, error)

Write an object into git's loose database. If the object already exists in the database, it is not overwritten, though the compression is still performed. To avoid the compression, call HaveObjectFromReader first, which is fast and just does the SHA.

func (*Repository) TagPath

func (repo *Repository) TagPath(tagName string) string

type Signature

type Signature struct {
	Email string
	Name  string
	When  time.Time
}

Author and Committer information

func (Signature) String

func (s Signature) String() string

Outputs the author signature in the same format as git log: "Author <email>". If needed, the "When" must be manually added to the string.

type Tag

type Tag struct {
	Name string
	Id   sha1

	Object     sha1 // The id of this commit object
	Type       string
	Tagger     *Signature
	TagMessage string
	// contains filtered or unexported fields
}

Tag

func (*Tag) Commit

func (tag *Tag) Commit() (*Commit, error)

type Tree

type Tree struct {
	Id sha1
	// contains filtered or unexported fields
}

A tree is a flat directory listing.

func NewTree

func NewTree(repo *Repository, id sha1) *Tree

func (*Tree) GetBlobByPath

func (t *Tree) GetBlobByPath(rpath string) (*Blob, error)

func (*Tree) GetTreeEntryByPath

func (t *Tree) GetTreeEntryByPath(rpath string) (*TreeEntry, error)

func (*Tree) ListEntries

func (t *Tree) ListEntries() Entries

func (*Tree) Scanner

func (t *Tree) Scanner() (*TreeScanner, error)

func (*Tree) SubTree

func (t *Tree) SubTree(rpath string) (*Tree, error)

type TreeEntry

type TreeEntry struct {
	Id   sha1
	Type ObjectType
	// contains filtered or unexported fields
}

func (*TreeEntry) Blob

func (te *TreeEntry) Blob() *Blob

func (*TreeEntry) EntryMode

func (te *TreeEntry) EntryMode() EntryMode

func (*TreeEntry) IsDir

func (te *TreeEntry) IsDir() bool

func (*TreeEntry) ModTime

func (te *TreeEntry) ModTime() time.Time

func (*TreeEntry) Mode

func (te *TreeEntry) Mode() (mode os.FileMode)

func (*TreeEntry) Name

func (te *TreeEntry) Name() string

func (*TreeEntry) Size

func (te *TreeEntry) Size() int64

func (*TreeEntry) Sys

func (te *TreeEntry) Sys() interface{}

type TreeScanner

type TreeScanner struct {
	*bufio.Scanner
	// contains filtered or unexported fields
}

func NewTreeScanner

func NewTreeScanner(parent *Tree, rc io.ReadCloser) *TreeScanner

func (*TreeScanner) Err

func (t *TreeScanner) Err() error

func (*TreeScanner) Scan

func (t *TreeScanner) Scan() bool

func (*TreeScanner) TreeEntry

func (t *TreeScanner) TreeEntry() *TreeEntry

type TreeWalkCallback

type TreeWalkCallback func(string, *TreeEntry) int

Jump to

Keyboard shortcuts

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