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 ¶
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) ParentCount ¶
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 .
type OdbObject ¶
type OdbObject struct {
// contains filtered or unexported fields
}
OdbObject provides safe wrapper over git2go.OdbObject .
func (*OdbObject) Type ¶
func (o *OdbObject) Type() ObjectType
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 .
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 Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree provides safe wrapper over git2go.Tree .