gitobj reads and writes Git objects.
Switch branches/tags
Nothing to show
Clone or download
bk2204 Merge pull request #8 from bk2204/missing-pack-idx
pack/set: ignore packs without indices
Latest commit f0db732 Dec 4, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
errors errors: add an error for nonexistent objects Sep 6, 2018
pack pack/set: ignore packs without indices Nov 29, 2018
storage storage: implement a wrapper for multiple storage implementations Sep 6, 2018
vendor go.mod: initial commit Aug 30, 2018
.travis.yml go.mod: initial commit Aug 30, 2018
LICENSE.md gitobj: initial commit Jul 5, 2018
README.md README.md: add links to functions Jul 5, 2018
backend.go backend: improve error handling Nov 15, 2018
backend_test.go backend: add standard backend types for filesystem and memory Sep 6, 2018
blob.go *: rename 'git/odb' to 'gitobj' Jul 5, 2018
blob_test.go git/odb: teach '(*Blob).Equal()' to compare other blobs Jul 5, 2018
commit.go git/odb: do not remove trailing newline Jul 5, 2018
commit_test.go git/odb: retain newlines when parsing commit messages Jul 5, 2018
errors.go *: rename 'git/odb' to 'gitobj' Jul 5, 2018
errors_test.go *: rename 'git/odb' to 'gitobj' Jul 5, 2018
file_storer.go errors: use NoSuchObject error whenever object is missing Sep 6, 2018
go.mod go.mod: initial commit Aug 30, 2018
go.sum go.mod: initial commit Aug 30, 2018
memory_storer.go errors: use NoSuchObject error whenever object is missing Sep 6, 2018
memory_storer_test.go errors: use NoSuchObject error whenever object is missing Sep 6, 2018
object.go git/odb: introduce odb.Object interface Jul 5, 2018
object_db.go object_db: use ReadCloser for uncompressed objects Nov 7, 2018
object_db_test.go object_db: use storage abstraction Sep 6, 2018
object_reader.go *: rename 'git/odb' to 'gitobj' Jul 5, 2018
object_reader_test.go git/odb: remove empty var decls Jul 5, 2018
object_type.go git/odb: add new ObjectType for annotated tags Jul 5, 2018
object_type_test.go git/odb: add new ObjectType for annotated tags Jul 5, 2018
object_writer.go *: rename 'git/odb' to 'gitobj' Jul 5, 2018
object_writer_test.go *: rename 'git/odb' to 'gitobj' Jul 5, 2018
storer.go storer: change Open to return io.ReadCloser Sep 6, 2018
tag.go *: rename 'git/odb' to 'gitobj' Jul 5, 2018
tag_test.go git/odb: add implementation of annotated Tag object Jul 5, 2018
tree.go *: rename 'git/odb' to 'gitobj' Jul 5, 2018
tree_test.go *: rename 'git/odb' to 'gitobj' Jul 5, 2018

README.md

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 <jane@example.com>",
	})

	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.