Categorygithub.com/git-lfs/gitobj/v2
modulepackage
2.1.1
Repository: https://github.com/git-lfs/gitobj.git
Documentation: pkg.go.dev

# README

gitobj

Package gitobj reads and writes loose and packed Git objects.

Getting Started

To access a repository's objects, begin by "opening" that repository for use:

package main

import (
	"github.com/git-lfs/gitobj"
)

func main() {
	repo, err := gitobj.FromFilesystem("/path/to/repo.git", "")
	if err != nil {
		panic(err)
	}
	defer repo.Close()
}

You can then open objects for inspection with the Blob(), Commit(), Tag(), or Tree() functions:

func main() {
	repo, err := gitobj.FromFilesystem("/path/to/repo.git", "")
	if err != nil {
		panic(err)
	}
	defer repo.Close()

	commit, err := repo.Commit([]byte{...})
	if err != nil {
		panic(err)
	}
}

Once an object is opened or an instance is held, it can be saved to the object database using the WriteBlob(), WriteCommit(), WriteTag(), or WriteTree() functions:

func main() {
	repo, err := gitobj.FromFilesystem("/path/to/repo.git", "")
	if err != nil {
		panic(err)
	}
	defer repo.Close()

	commit, err := repo.Commit([]byte{...})
	if err != nil {
		panic(err)
	}

	commit.Message = "Hello from gitobj!"
	commit.ExtraHeaders = append(commit.ExtraHeaders, &gitobj.ExtraHeader{
		K: "Signed-off-by",
		V: "Jane Doe <[email protected]>",
	})

	if _, err := repository.WriteCommit(commit); err != nil {
		panic(err)
	}
}

Packed Objects

Package gitobj has support for reading "packed" objects (i.e., objects found in packfiles) via package github.com/git-lfs/gitobj/pack. Package pack implements searching pack index (.idx) files and locating the corresponding delta-base chain in the appropriate pack file. It understands both version 1 and version 2 of the packfile specification.

gitobj will always try to locate a loose object first. If a loose object cannot be found with the appropriate SHA-1, the repository's packfile(s) will be searched. If an object is located in a packfile, that object will be reconstructed along its delta-base chain and then returned transparently.

More information

For more: https://godoc.org/github.com/git-lfs/gitobj.

License

MIT.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

Alternates is an Option to specify the string of alternate repositories that are searched for objects.
No description provided by the author
FromFilesystem constructs an *ObjectDatabase instance that is backed by a directory on the filesystem.
NewBlobFromBytes returns a new *Blob that yields the data given.
NewBlobFromFile returns a new *Blob that contains the contents of the file at location "path" on disk.
NewFilesystemBackend initializes a new filesystem-based backend, optionally with additional alternates as specified in the `alternates` variable.
NewMemoryBackend initializes a new memory-based backend.
NewObjectReadCloser takes a given io.Reader that yields zlib-compressed data, and returns an *ObjectReader wrapping it, or an error if one occurred during construction time.
NewObjectReader takes a given io.Reader that yields zlib-compressed data, and returns an *ObjectReader wrapping it, or an error if one occurred during construction time.
NewObjectWriter returns a new *ObjectWriter instance that drains incoming writes into the io.Writer given, "w".
NewObjectWriter returns a new *ObjectWriter instance that drains incoming writes into the io.Writer given, "w".
NewUncompressObjectReadCloser takes a given io.Reader that yields uncompressed data, and returns an *ObjectReader wrapping it, or an error if one occurred during construction time.
NewObjectReader takes a given io.Reader that yields uncompressed data and returns an *ObjectReader wrapping it, or an error if one occurred during construction time.
ObjectFormat is an Option to specify the hash algorithm (object format) in use in Git.
ObjectTypeFromString converts from a given string to an ObjectType enumeration instance.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Blob represents a Git object of type "blob".
Commit encapsulates a Git commit entry.
ExtraHeader encapsulates a key-value pairing of header key to header value.
ObjectDatabase enables the reading and writing of objects against a storage backend.
ObjectReader provides an io.Reader implementation that can read Git object headers, as well as provide an uncompressed view into the object contents itself.
ObjectWriter provides an implementation of io.Writer that compresses and writes data given to it, and keeps track of the SHA1 hash of the data as it is written.
Signature represents a commit signature, which can represent either committership or authorship of the commit that this signature belongs to.
No description provided by the author
Tree encapsulates a Git tree object.
TreeEntry encapsulates information about a single tree entry in a tree listing.
UnexpectedObjectType is an error type that represents a scenario where an object was requested of a given type "Wanted", and received as a different _other_ type, "Wanted".

# Interfaces

Object is an interface satisfied by any concrete type that represents a loose Git object.

# Type aliases

No description provided by the author
ObjectType is a constant enumeration type for identifying the kind of object type an implementing instance of the Object interface is.
No description provided by the author
SubtreeOrder is an implementation of sort.Interface that sorts a set of `*TreeEntry`'s according to "subtree" order.