object

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2021 License: Apache-2.0 Imports: 11 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendPrefix

func AppendPrefix(dst []byte, typ Type, n int64) []byte

AppendPrefix appends a Git object prefix (e.g. "blob 42\x00") to a byte slice.

func BlobSum

func BlobSum(r io.Reader, size int64) (githash.SHA1, error)

BlobSum computes the Git SHA-1 object ID of the blob with the given content. This includes the Git object prefix as part of the hash input. It returns an error if the blob does not match the provided size in bytes.

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

func ParseCommit(data []byte) (*Commit, error)

ParseCommit deserializes a commit in the Git object format. It is the same as calling UnmarshalText on a new commit.

func (*Commit) MarshalBinary added in v0.9.0

func (c *Commit) MarshalBinary() ([]byte, error)

MarshalBinary serializes a commit into the Git object format.

func (*Commit) MarshalText

func (c *Commit) MarshalText() ([]byte, error)

MarshalText serializes a commit into the Git object format. It is the same as calling MarshalBinary.

func (*Commit) SHA1

func (c *Commit) SHA1() githash.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) Summary

func (c *Commit) Summary() string

Summary returns the first line of the message.

func (*Commit) UnmarshalBinary added in v0.9.0

func (c *Commit) UnmarshalBinary(data []byte) error

UnmarshalBinary deserializes a commit from the Git object format.

func (*Commit) UnmarshalText

func (c *Commit) UnmarshalText(data []byte) error

UnmarshalText deserializes a commit from the Git object format. It is the same as calling UnmarshalBinary.

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

func (m Mode) FileMode() (f os.FileMode, ok bool)

FileMode converts the Git mode into an os.FileMode, if possible. ModeGitlink will have both os.ModeDir and os.ModeSymlink set.

func (Mode) Format

func (m Mode) Format(f fmt.State, c rune)

Format implements fmt.Formatter to make %x and %X format the number rather than the string.

func (Mode) IsDir

func (m Mode) IsDir() bool

IsDir reports whether m describes a directory.

func (Mode) IsRegular

func (m Mode) IsRegular() bool

IsRegular reports whether m describes a file.

func (Mode) String

func (m Mode) String() string

String formats the mode as zero-padded octal.

type Prefix added in v0.9.0

type Prefix struct {
	Type Type
	Size int64
}

Prefix is a parsed Git object prefix like "blob 42\x00".

func (Prefix) MarshalBinary added in v0.9.0

func (p Prefix) MarshalBinary() ([]byte, error)

MarshalBinary returns the result of AppendPrefix.

func (Prefix) String added in v0.9.0

func (p Prefix) String() string

String returns the prefix without the trailing NUL byte.

func (*Prefix) UnmarshalBinary added in v0.9.0

func (p *Prefix) UnmarshalBinary(data []byte) error

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

func ParseTag(data []byte) (*Tag, error)

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

func (t *Tag) MarshalBinary() ([]byte, error)

MarshalBinary serializes a tag into the Git object format.

func (*Tag) MarshalText

func (t *Tag) MarshalText() ([]byte, error)

MarshalText serializes a tag into the Git object format. It is the same as calling MarshalBinary.

func (*Tag) SHA1

func (t *Tag) SHA1() githash.SHA1

SHA1 computes the SHA-1 hash of the tag object.

func (*Tag) Summary

func (t *Tag) Summary() string

Summary returns the first line of the message.

func (*Tag) UnmarshalBinary added in v0.9.0

func (t *Tag) UnmarshalBinary(data []byte) error

UnmarshalBinary deserializes a tag from the Git object format.

func (*Tag) UnmarshalText

func (t *Tag) UnmarshalText(data []byte) error

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 entries must be sorted by name and contain no duplicates. The zero value is an empty tree.

func ParseTree

func ParseTree(src []byte) (Tree, error)

ParseTree deserializes a tree in the Git object format. It is the same as calling UnmarshalBinary on a new tree.

func (Tree) Len

func (tree Tree) Len() int

Len returns the number of entries in the tree.

func (Tree) Less

func (tree Tree) Less(i, j int) bool

Less reports whether the i'th entry name is less than the j'th entry name.

func (Tree) MarshalBinary

func (tree Tree) MarshalBinary() ([]byte, error)

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

func (tree Tree) SHA1() githash.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

func (tree Tree) Search(name string) *TreeEntry

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

func (tree Tree) Sort() error

Sort sorts the tree, returning an error if there are any duplicates.

func (Tree) String

func (tree Tree) String() string

String formats the tree in an ASCII-clean debugging format.

func (Tree) Swap

func (tree Tree) Swap(i, j int)

Swap swaps the i'th entry with the j'th entry.

func (*Tree) UnmarshalBinary

func (tree *Tree) UnmarshalBinary(src []byte) error

UnmarshalBinary deserializes a tree from the Git object format. If UnmarshalBinary does not return an error, the tree will always be sorted.

type TreeEntry

type TreeEntry struct {
	Name     string
	Mode     Mode
	ObjectID githash.SHA1
}

A TreeEntry represents a single file in a Git tree object.

func (*TreeEntry) String

func (ent *TreeEntry) String() string

String formats the entry in an ASCII-clean format similar to the Git tree object format.

type Type

type Type string

Type is an enumeration of Git object types.

const (
	TypeBlob   Type = "blob"
	TypeTree   Type = "tree"
	TypeCommit Type = "commit"
	TypeTag    Type = "tag"
)

Object types.

func (Type) IsValid

func (typ Type) IsValid() bool

IsValid reports whether typ is one of the known constants.

type User

type User string

User identifies an author or committer as a string like "Octocat <octocat@example.com>".

func MakeUser

func MakeUser(name, email string) (User, error)

MakeUser constructs a User string from a name and an email address.

func (User) Email

func (u User) Email() string

Email returns the user's email address, if they have one.

func (User) Name

func (u User) Name() string

Name returns the user's name.

Jump to

Keyboard shortcuts

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