Skip to content
/ gitobj Public template
forked from git-lfs/gitobj

gitobj reads and writes Git objects.

License

Notifications You must be signed in to change notification settings

ANDREWPUL/gitobj

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gitobj

CI status

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.

About

gitobj reads and writes Git objects.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%