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 CommitFields
- type Mode
- type Prefix
- 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, // and its name may be used for serialization if it meets the correct format. 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, // and its name may be used for serialization if it meets the correct format. CommitTime time.Time // Extra stores any lines in the commit object // between the committer line and the gpgsig line. // It will never begin or end with a newline, // nor will it contain blank lines. Extra CommitFields // 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 *Commit.UnmarshalBinary on a new commit.
func (*Commit) MarshalBinary ¶ added in v0.9.0
MarshalBinary serializes a commit into the Git object format.
func (*Commit) MarshalText ¶
MarshalText serializes a commit into the Git object format. It is the same as calling *Commit.MarshalBinary.
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) UnmarshalBinary ¶ added in v0.9.0
UnmarshalBinary deserializes a commit from the Git object format.
func (*Commit) UnmarshalText ¶
UnmarshalText deserializes a commit from the Git object format. It is the same as calling *Commit.UnmarshalBinary.
type CommitFields ¶ added in v0.10.0
type CommitFields string
CommitFields is a block of lines, conventionally in the form "key value". A value may span multiple lines by starting each continuation line with a space.
func (CommitFields) Cut ¶ added in v0.10.0
func (fields CommitFields) Cut() (head, tail CommitFields)
Cut slices fields around the first field.
func (CommitFields) First ¶ added in v0.10.0
func (fields CommitFields) First() (key, value string)
First returns the first field's key and value.
func (CommitFields) Get ¶ added in v0.10.0
func (fields CommitFields) Get(key string) string
Get returns the value of the first field in fields with the given key, or the empty string if no such field exists.
func (CommitFields) IsValid ¶ added in v0.10.0
func (fields CommitFields) IsValid() bool
IsValid reports whether fields can be serialized into a Git commit. Valid fields do not begin or end with a newline and do not contain blank lines.
type Mode ¶
type Mode uint32
Mode is a tree entry file mode. It is similar to fs.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 fs.FileMode, if possible. ModeGitlink will have both fs.ModeDir and fs.ModeSymlink set.
func (Mode) Format ¶
Format implements fmt.Formatter to make %x and %X format the number rather than the string.
type Prefix ¶ added in v0.9.0
Prefix is a parsed Git object prefix like "blob 42\x00".
func (Prefix) MarshalBinary ¶ added in v0.9.0
MarshalBinary returns the result of AppendPrefix.
func (*Prefix) UnmarshalBinary ¶ added in v0.9.0
UnmarshalBinary parses an object prefix.
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) MarshalBinary ¶ added in v0.9.0
MarshalBinary serializes a tag into the Git object format.
func (*Tag) MarshalText ¶
MarshalText serializes a tag into the Git object format. It is the same as calling MarshalBinary.
func (*Tag) UnmarshalBinary ¶ added in v0.9.0
UnmarshalBinary deserializes a tag from the Git object format.
func (*Tag) UnmarshalText ¶
UnmarshalText deserializes a tag from the Git object format. It is the same as calling UnmarshalBinary.
type Tree ¶
type Tree []*TreeEntry
A Tree is a Git tree object: a flat list of files in a directory. The zero value is an empty tree.
Tree methods generally assume elements of a Tree are sorted and contain no duplicates. Use *Tree.Sort to sort a tree and check for duplicates.
func ParseTree ¶
ParseTree deserializes a tree in the Git object format. It is the same as calling UnmarshalBinary on a new tree.
func (Tree) Less ¶
Less reports whether the i'th entry is ordered before the j'th entry in Git path ordering. Git path ordering is lexicographical, but directories are treated as if their name ends in a slash ("/").
Less is a part of sort.Interface.
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) Sort ¶
Sort sorts the tree, returning an error if there are any duplicates. See *Tree.Less for details regarding the sort order.
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.