git

package
v0.0.0-...-a621b9a Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2025 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package internal/git wraps package git2go with providing unconditional safety.

For example git2go.Object.Data() returns []byte that aliases unsafe memory that can go away from under []byte if original Object is garbage collected. The following code snippet is thus _not_ correct:

obj = odb.Read(sha1)
data = obj.Data()
... use data

because obj can be garbage-collected right after `data = obj.Data()` but before `use data` leading to either crashes or memory corruption. A runtime.KeepAlive(obj) needs to be added to the end of the snippet - after `use data` - to make that code correct.

Given that obj.Data() is not "speaking" by itself as unsafe, and that there are many similar methods, it is hard to see which places in the code needs special attention.

For this reason git-backup took decision to localize git2go-related code in one small place here, and to expose only safe things to outside. That is we make data copies when reading object data and similar things to provide unconditional safety to the caller via that copy cost.

The copy cost is smaller compared to the cost of either spawning e.g. `git cat-file` for every object, or interacting with `git cat-file --batch` server spawned once, but still spending context switches on every request and still making the copy on socket or pipe transfer. But most of all the copy cost is negligible to the cost of catching hard to reproduce crashes or data corruptions in the production environment.

Index

Constants

View Source
const (
	ObjectAny     = git2go.ObjectAny
	ObjectInvalid = git2go.ObjectInvalid
	ObjectCommit  = git2go.ObjectCommit
	ObjectTree    = git2go.ObjectTree
	ObjectBlob    = git2go.ObjectBlob
	ObjectTag     = git2go.ObjectTag
)

constants are safe to propagate as is.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	// contains filtered or unexported fields
}

Commit provides safe wrapper over git2go.Commit .

func (*Commit) Message

func (c *Commit) Message() string

func (*Commit) ParentCount

func (c *Commit) ParentCount() uint

func (*Commit) ParentId

func (c *Commit) ParentId(n uint) *Oid

func (*Commit) Tree

func (c *Commit) Tree() (*Tree, error)

type ObjectType

type ObjectType = git2go.ObjectType // int

types that are safe to propagate as is.

type Odb

type Odb struct {
	// contains filtered or unexported fields
}

Odb provides safe wrapper over git2go.Odb .

func (*Odb) Read

func (o *Odb) Read(oid *Oid) (*OdbObject, error)

func (*Odb) Write

func (o *Odb) Write(data []byte, otype ObjectType) (*Oid, error)

type OdbObject

type OdbObject struct {
	// contains filtered or unexported fields
}

OdbObject provides safe wrapper over git2go.OdbObject .

func (*OdbObject) Data

func (o *OdbObject) Data() []byte

func (*OdbObject) Id

func (o *OdbObject) Id() *Oid

func (*OdbObject) Type

func (o *OdbObject) Type() ObjectType

type Oid

type Oid = git2go.Oid // [20]byte             ; cloned when retrieved

types that are safe to propagate as is.

type Reference

type Reference struct {
	// contains filtered or unexported fields
}

Reference provides safe wrapper over git2go.Reference .

type ReferenceCollection

type ReferenceCollection struct {
	// contains filtered or unexported fields
}

ReferenceCollection provides safe wrapper over git2go.ReferenceCollection .

func (*ReferenceCollection) Create

func (rdb *ReferenceCollection) Create(name string, id *Oid, force bool, msg string) (*Reference, error)

type Repository

type Repository struct {
	References *ReferenceCollection
	// contains filtered or unexported fields
}

Repository provides safe wrapper over git2go.Repository .

func OpenRepository

func OpenRepository(path string) (*Repository, error)

func (*Repository) DefaultSignature

func (r *Repository) DefaultSignature() (*Signature, error)

func (*Repository) LookupCommit

func (r *Repository) LookupCommit(id *Oid) (*Commit, error)

func (*Repository) Odb

func (r *Repository) Odb() (*Odb, error)

func (*Repository) Path

func (r *Repository) Path() string

type Signature

type Signature = git2go.Signature // struct with strings  ; strings are cloned when retrieved

types that are safe to propagate as is.

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

Tree provides safe wrapper over git2go.Tree .

func (*Tree) EntryByName

func (t *Tree) EntryByName(filename string) *TreeEntry

type TreeEntry

type TreeEntry = git2go.TreeEntry // struct with sting, Oid, ...  ; strings and oids are cloned when retrieved

types that are safe to propagate as is.

Jump to

Keyboard shortcuts

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