Documentation ¶
Overview ¶
Package object contains methods and objects to work with git objects
Index ¶
- Variables
- type Blob
- type Commit
- func (c *Commit) Author() Signature
- func (c *Commit) Committer() Signature
- func (c *Commit) GPGSig() string
- func (c *Commit) ID() ginternals.Oid
- func (c *Commit) Message() string
- func (c *Commit) ParentIDs() []ginternals.Oid
- func (c *Commit) ToObject() *Object
- func (c *Commit) TreeID() ginternals.Oid
- type CommitOptions
- type Object
- func (o *Object) AsBlob() *Blob
- func (o *Object) AsCommit() (*Commit, error)
- func (o *Object) AsTag() (*Tag, error)
- func (o *Object) AsTree() (*Tree, error)
- func (o *Object) Bytes() []byte
- func (o *Object) Compress() (data []byte, err error)
- func (o *Object) ID() ginternals.Oid
- func (o *Object) Size() int
- func (o *Object) Type() Type
- type Signature
- type Tag
- type TagParams
- type Tree
- type TreeEntry
- type TreeObjectMode
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( // ErrObjectUnknown represents an error thrown when encoutering an // unknown object ErrObjectUnknown = errors.New("invalid object type") // ErrObjectInvalid represents an error thrown when an object contains // unexpected data or when the wrong object is provided to a method. // Ex. Inserting a ObjectDeltaOFS in a tree // Ex.2 Creating a tag using a commit with no ID (commit not persisted // to the odb) ErrObjectInvalid = errors.New("invalid object") // ErrTreeInvalid represents an error thrown when parsing an invalid // tree object ErrTreeInvalid = errors.New("invalid tree") // ErrCommitInvalid represents an error thrown when parsing an invalid // commit object ErrCommitInvalid = errors.New("invalid commit") // ErrTagInvalid represents an error thrown when parsing an invalid // tag object ErrTagInvalid = errors.New("invalid tag") )
var ErrSignatureInvalid = errors.New("commit signature is invalid")
ErrSignatureInvalid is an error thrown when the signature of a commit couldn't be parsed
Functions ¶
This section is empty.
Types ¶
type Blob ¶
type Blob struct {
// contains filtered or unexported fields
}
Blob represents a blob object
type Commit ¶
type Commit struct {
// contains filtered or unexported fields
}
Commit represents a commit object
func NewCommit ¶
func NewCommit(treeID ginternals.Oid, author Signature, opts *CommitOptions) *Commit
NewCommit creates a new Commit object Any provided Oids won't be check
func NewCommitFromObject ¶
NewCommitFromObject creates a commit from a raw object
A commit has following format:
tree {sha} parent {sha} author {author_name} <{author_email}> {author_date_seconds} {author_date_timezone} committer {committer_name} <{committer_email}> {committer_date_seconds} {committer_date_timezone} gpgsig -----BEGIN PGP SIGNATURE----- {gpg key over multiple lines}
-----END PGP SIGNATURE-----
{a blank line} {commit message}
Note:
- A commit can have 0, 1, or many parents lines The very first commit of a repo has no parents A regular commit as 1 parent A merge commit has 2 or more parents
- The gpgsig is optional
func (*Commit) ParentIDs ¶
func (c *Commit) ParentIDs() []ginternals.Oid
ParentIDs returns the list of SHA of the parent commits (if any) - The first commit of an orphan branch has 0 parents - A regular commit or the result of a fast-forward merge has 1 parent - A true merge (no fast-forward) as 2 or more parents
func (*Commit) TreeID ¶
func (c *Commit) TreeID() ginternals.Oid
TreeID returns the SHA of the commit's tree
type CommitOptions ¶
type CommitOptions struct { Message string GPGSig string // Committer represent the person creating the commit. // If not provided, the author will be used as committer Committer Signature ParentsID []ginternals.Oid }
CommitOptions represents all the optional data available to create a commit
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object represents a git object. An object can be of multiple types but they all share similarities (same storage system, same header, etc.). Object are stored in .git/objects, and may be stored in a packfile (kind of an optimized git database) located in .git/objects/packs https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
func (*Object) Compress ¶
Compress return the object zlib compressed, alongside its oid. The format of the compressed data is: [type] [size][NULL][content] The type in ascii, followed by a space, followed by the size in ascii, followed by a null character (0), followed by the object data maybe we can move some code around
type Signature ¶
Signature represents the author/committer and time of a commit
func NewSignature ¶
NewSignature generates a signature at the current date and time
func NewSignatureFromBytes ¶
NewSignatureFromBytes returns a signature from an array of byte
A signature has the following format: User Name <user.email@domain.tld> timestamp timezone Ex: Melvin Laplanche <melvin.wont.reply@gmail.com> 1566115917 -0700
type Tag ¶
type Tag struct {
// contains filtered or unexported fields
}
Tag represents a Tag object
func NewTagFromObject ¶
NewTagFromObject creates a new Tag from a raw git object
A tag has following format:
object {sha} type {target_object_type} tag {tag_name} tagger {author_name} <{author_email}> {author_date_seconds} {author_date_timezone} gpgsig -----BEGIN PGP SIGNATURE----- {gpg key over multiple lines}
-----END PGP SIGNATURE-----
{a blank line} {tag message}
Note: - The gpgsig is optional
func (*Tag) Target ¶
func (t *Tag) Target() ginternals.Oid
Target returns the ID of the object targeted by the tag
type TagParams ¶
type TagParams struct { Target *Object Name string Tagger Signature Message string OptGPGSig string }
TagParams represents all the data needed to create a Tag Params starting by Opt are optionals
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree represents a git tree object
func NewTreeFromObject ¶
NewTreeFromObject returns a new tree from an object
A tree has following format:
{octal_mode} {path_name}\0{encoded_sha}
Note: - a Tree may have multiple entries
func (*Tree) ID ¶
func (t *Tree) ID() ginternals.Oid
ID returns the object's ID ginternals.NullOid is returned if the object doesn't have an ID yet
type TreeEntry ¶
type TreeEntry struct { Path string ID ginternals.Oid Mode TreeObjectMode }
TreeEntry represents an entry inside a git tree
type TreeObjectMode ¶
type TreeObjectMode int32
TreeObjectMode represents the mode of an object inside a tree Non-standard modes (like 0o100664) are not supported
const ( // ModeFile represents the mode to use for a regular file ModeFile TreeObjectMode = 0o100644 // ModeExecutable represents the mode to use for a executable file ModeExecutable TreeObjectMode = 0o100755 // ModeDirectory represents the mode to use for a directory ModeDirectory TreeObjectMode = 0o040000 // ModeSymLink represents the mode to use for a symbolic link ModeSymLink TreeObjectMode = 0o120000 // ModeGitLink represents the mode to use for a gitlink (submodule) ModeGitLink TreeObjectMode = 0o160000 )
func (TreeObjectMode) IsValid ¶
func (m TreeObjectMode) IsValid() bool
IsValid returns whether the mode is a supported mode or not
func (TreeObjectMode) ObjectType ¶
func (m TreeObjectMode) ObjectType() Type
ObjectType returns the object type associated to a mode
type Type ¶
type Type int8
Type represents the type of an object as stored in a packfile
const ( TypeCommit Type = 1 TypeTree Type = 2 TypeBlob Type = 3 TypeTag Type = 4 // 5 is reserved for future use ObjectDeltaOFS Type = 6 ObjectDeltaRef Type = 7 )
List of all the possible object types
func NewTypeFromString ¶
NewTypeFromString returns an Type from its string representation