ginternals

package
v0.0.0-...-2ee2aa9 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package ginternals contains objects and methods to work on git internals

Index

Constants

View Source
const (
	// Head is a reference to the current branch, or to a commit if
	// we're detached
	Head = "HEAD"
	// OrigHead is a backup reference of HEAD set during destructive commands
	// such as rebase, merge, etc. and can be used to revert an operation
	OrigHead = "ORIG_HEAD"
	// MergeHead is a reference to the commit that is being merged
	// into the current branch
	MergeHead = "MERGE_HEAD"
	// CherryPickHead is a reference to the commit that is being
	// cherry-picked
	CherryPickHead = "CHERRY_PICK_HEAD"
	// Master correspond to the default branch name if none was
	// specified
	Master = "master"
)

Common ref names

View Source
const (
	// OidSize is the length of an oid, in bytes
	OidSize = 20
)

Variables

View Source
var (
	// NullOid is the value of an empty Oid, or one that's all 0s
	NullOid = Oid{}

	// ErrInvalidOid is returned when a given value isn't a valid Oid
	ErrInvalidOid = errors.New("invalid Oid")
)
View Source
var (
	// ErrRefNotFound is an error thrown when trying to act on a
	// reference that doesn't exists
	ErrRefNotFound = errors.New("reference not found")

	// ErrRefExists is an error thrown when trying to act on a
	// reference that should not exist, but does
	ErrRefExists = errors.New("reference already exists")

	// ErrRefNameInvalid is an error thrown when the name of a reference
	// is not valid
	ErrRefNameInvalid = errors.New("reference name is not valid")

	// ErrRefInvalid is an error thrown when a reference is not valid
	ErrRefInvalid = errors.New("reference is not valid")

	// ErrPackedRefInvalid is an error thrown when the packed-refs
	// file cannot be parsed properly
	ErrPackedRefInvalid = errors.New("packed-refs file is invalid")

	// ErrUnknownRefType is an error thrown when the type of a reference
	// is unknown
	ErrUnknownRefType = errors.New("unknown reference type")
)
View Source
var ErrObjectNotFound = errors.New("object not found")

ErrObjectNotFound is an error corresponding to a git object not being found

Functions

func ConfigPath

func ConfigPath(cfg *config.Config) string

ConfigPath returns the path to the local config file

func DescriptionFilePath

func DescriptionFilePath(cfg *config.Config) string

DescriptionFilePath returns the path to the description file

func DotGitPath

func DotGitPath(cfg *config.Config) string

DotGitPath returns the path to the dotgit directory

func IsRefNameValid

func IsRefNameValid(name string) bool

IsRefNameValid returns whether the name of a reference is valid or not https://stackoverflow.com/a/12093994/382879

func LocalBranchFullName

func LocalBranchFullName(shortName string) string

LocalBranchFullName returns the full name of branch ex. for `main` returns `refs/heads/main`

func LocalBranchShortName

func LocalBranchShortName(fullName string) string

LocalBranchShortName returns the short name of a branch ex. for `refs/heads/main` returns `main`

func LocalBranchesPath

func LocalBranchesPath(cfg *config.Config) string

LocalBranchesPath returns the path to the directory containing the local branches

func LocalTagFullName

func LocalTagFullName(shortName string) string

LocalTagFullName returns the full name of a tag ex. for `my-tag` returns `refs/tags/my-tag`

func LocalTagShortName

func LocalTagShortName(fullName string) string

LocalTagShortName returns the short name of a tag ex. for refs/tags/my-tag returns my-tag

func LooseObjectPath

func LooseObjectPath(cfg *config.Config, sha string) string

LooseObjectPath returns the path of a loose object. Path is .git/objects/first_2_chars_of_sha/remaining_chars_of_sha

Ex. path of fcfe68a0e44e04bd7fd564fc0b75f1ae457e18b3 is: .git/objects/fc/fe68a0e44e04bd7fd564fc0b75f1ae457e18b3

func ObjectsInfoPath

func ObjectsInfoPath(cfg *config.Config) string

ObjectsInfoPath returns the path to the directory that contains the info about the objects

func ObjectsPacksPath

func ObjectsPacksPath(cfg *config.Config) string

ObjectsPacksPath returns the path to the directory that contains the packfiles

func ObjectsPath

func ObjectsPath(cfg *config.Config) string

ObjectsPath returns the path to the directory that contains the object

func PackedRefsPath

func PackedRefsPath(cfg *config.Config) string

PackedRefsPath return the local path of a the packed-refs file

func PackfilePath

func PackfilePath(cfg *config.Config, name string) string

PackfilePath returns the path of a packfiles

func RefFullName

func RefFullName(shortName string) string

RefFullName returns the UNIX path of a ref

func RefPath

func RefPath(cfg *config.Config, name string) string

RefPath return the path of a reference

func RefsPath

func RefsPath(cfg *config.Config) string

RefsPath return the path to the directory that contains all the refs

func TagsPath

func TagsPath(cfg *config.Config) string

TagsPath returns the path to the directory that contains the tags

Types

type Oid

type Oid [OidSize]byte

Oid represents an object id

func NewOidFromChars

func NewOidFromChars(id []byte) (Oid, error)

NewOidFromChars creates an Oid from the given char bytes For the SHA {'9', 'b', '9', '1', 'd', 'a', ...} the oid will be {0x9b, 0x91, 0xda, ...}

func NewOidFromContent

func NewOidFromContent(bytes []byte) Oid

NewOidFromContent returns the Oid of the given content. The oid will be the SHA1 sum of the content

func NewOidFromHex

func NewOidFromHex(id []byte) (Oid, error)

NewOidFromHex returns an Oid from the provided byte-encoded oid This basically cast a slice that contains an encoded oid into a Oid object

func NewOidFromStr

func NewOidFromStr(id string) (Oid, error)

NewOidFromStr creates an Oid from the given string For the SHA 9b91da06e69613397b38e0808e0ba5ee6983251b the oid will be {0x9b, 0x91, 0xda, ...}

func (Oid) Bytes

func (o Oid) Bytes() []byte

Bytes returns the raw Oid as []byte. This is different than doing []byte(oid.String()) For the oid 642480605b8b0fd464ab5762e044269cf29a60a3: oid.Bytes(): []byte{ 0x64, 0x24, 0x80, ... } []byte(oid.String()): []byte{ '6', '4', '2', '4', '8' '0', ... }

func (Oid) IsZero

func (o Oid) IsZero() bool

IsZero returns whether the oid has the zero value (NullOid)

func (Oid) String

func (o Oid) String() string

String converts an oid to a string

type RefContent

type RefContent func(name string) ([]byte, error)

RefContent represents a method that returns the content of reference This is used so we can do the process here, without depending on a specific backend or having circular dependencies

type Reference

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

Reference represents a git reference https://git-scm.com/book/en/v2/Git-Internals-Git-References

func NewReference

func NewReference(name string, target Oid) *Reference

NewReference return a new Reference object that targets an object

func NewSymbolicReference

func NewSymbolicReference(name, target string) *Reference

NewSymbolicReference return a new Reference object that targets another reference. Example HEAD targeting heads/master

func ResolveReference

func ResolveReference(name string, finder RefContent) (*Reference, error)

ResolveReference resolves symbolic references

func (*Reference) Name

func (ref *Reference) Name() string

Name returns the full name fo the reference: example: refs/heads/master

func (*Reference) SymbolicTarget

func (ref *Reference) SymbolicTarget() string

SymbolicTarget returns the symbolic target of a reference

func (*Reference) Target

func (ref *Reference) Target() Oid

Target returns the ID targeted by a reference

func (*Reference) Type

func (ref *Reference) Type() ReferenceType

Type returns the type of a reference

type ReferenceType

type ReferenceType int8

ReferenceType represents the type of a reference

const (
	// OidReference represents a reference that targets an Oid
	OidReference ReferenceType = 1
	// SymbolicReference represents a reference that targets another
	// reference
	SymbolicReference ReferenceType = 2
)

Directories

Path Synopsis
Package config contains structs to interact with git configuration as well as to configure the library
Package config contains structs to interact with git configuration as well as to configure the library
Package object contains methods and objects to work with git objects
Package object contains methods and objects to work with git objects
Package packfile contains methods and structs to read and write packfiles
Package packfile contains methods and structs to read and write packfiles

Jump to

Keyboard shortcuts

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