Documentation ¶
Overview ¶
Package object provides types for Git objects and functions for parsing and serializing those objects. For an overview, see https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
Index ¶
- func AppendPrefix(dst []byte, typ Type, n int64) []byte
- func BlobSum(r io.Reader, size int64) (githash.SHA1, error)
- type Commit
- type Mode
- type Tag
- type Tree
- func (tree Tree) Len() int
- func (tree Tree) Less(i, j int) bool
- func (tree Tree) MarshalBinary() ([]byte, error)
- func (tree Tree) SHA1() githash.SHA1
- func (tree Tree) Search(name string) *TreeEntry
- func (tree Tree) Sort() error
- func (tree Tree) String() string
- func (tree Tree) Swap(i, j int)
- func (tree *Tree) UnmarshalBinary(src []byte) error
- type TreeEntry
- type Type
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendPrefix ¶
AppendPrefix appends a Git object prefix (e.g. "blob 42\x00") to a byte slice.
Types ¶
type Commit ¶
type Commit struct { // Tree is the hash of the commit's tree object. Tree githash.SHA1 // Parents are the hashes of the commit's parents. Parents []githash.SHA1 // Author identifies the person who wrote the code. Author User // AuthorTime is the time the code was written. // The Location is significant. AuthorTime time.Time // Committer identifies the person who committed the code to the repository. Committer User // CommitTime is the time the code was committed to the repository. // The Location is significant. CommitTime time.Time // If GPGSignature is not empty, then it is the ASCII-armored signature of // the commit. GPGSignature []byte // Message is the commit message. Message string }
A Commit is a parsed Git commit object.
func ParseCommit ¶
ParseCommit deserializes a commit in the Git object format. It is the same as calling UnmarshalText on a new commit.
func (*Commit) MarshalText ¶
MarshalText serializes a commit into the Git object format.
func (*Commit) SHA1 ¶
SHA1 computes the SHA-1 hash of the commit object. This is commonly known as the "commit hash" and uniquely identifies the commit.
func (*Commit) UnmarshalText ¶
UnmarshalText deserializes a commit from the Git object format.
type Mode ¶
type Mode uint32
Mode is a tree entry file mode. It is similar to os.FileMode, but is limited to a specific set of modes.
const ( // ModePlain indicates a non-executable file. ModePlain Mode = 0o100644 // ModeExecutable indicates an executable file. ModeExecutable Mode = 0o100755 // ModeDir indicates a subdirectory. ModeDir Mode = 0o040000 // ModeSymlink indicates a symbolic link. ModeSymlink Mode = 0o120000 // ModeGitlink indicates a Git submodule. ModeGitlink Mode = 0o160000 // ModePlainGroupWritable indicates a non-executable file. // This is equivalent to ModePlain, but was sometimes generated by // older versions of Git. ModePlainGroupWritable Mode = 0o100664 )
Git tree entry modes.
func (Mode) FileMode ¶
FileMode converts the Git mode into an os.FileMode, if possible. ModeGitlink will have both os.ModeDir and os.ModeSymlink set.
func (Mode) Format ¶
Format implements fmt.Formatter to make %x and %X format the number rather than the string.
type Tag ¶
type Tag struct { // ObjectID is the hash of the object that the tag refers to. ObjectID githash.SHA1 // ObjectType is the type of the object that the tag refers to. ObjectType Type // Name is the name of the tag. Name string // Tagger identifies the person who created the tag. Tagger User // Time is the time the tag was created. // The Location is significant. Time time.Time // Message is the tag message. Message string }
A Tag is a parsed Git tag object. These are referred to as "annotated tags" in the Git documentation.
func ParseTag ¶
ParseTag deserializes a tag in the Git object format. It is the same as calling UnmarshalText on a new tag.
func (*Tag) MarshalText ¶
MarshalText serializes a tag into the Git object format.
func (*Tag) UnmarshalText ¶
UnmarshalText deserializes a tag from the Git object format.
type Tree ¶
type Tree []*TreeEntry
A Tree is a Git tree object: a flat list of files in a directory. The entries must be sorted by name and contain no duplicates. The zero value is an empty tree.
func ParseTree ¶
ParseTree deserializes a tree in the Git object format. It is the same as calling UnmarshalBinary on a new tree.
func (Tree) MarshalBinary ¶
MarshalBinary serializes the tree into the Git tree object format. It returns an error if the tree is not sorted or contains duplicates.
func (Tree) SHA1 ¶
SHA1 computes the SHA-1 hash of the tree object. It panics if the tree is not sorted or contains duplicates.
func (Tree) Search ¶
Search returns the entry with the given name in the tree or nil if not found. It may return incorrect results if the tree is not sorted.
func (*Tree) UnmarshalBinary ¶
UnmarshalBinary deserializes a tree from the Git object format. If UnmarshalBinary does not return an error, the tree will always be sorted.
type Type ¶
type Type string
Type is an enumeration of Git object types.