gig

package module
v0.0.0-...-6d784b4 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2017 License: BSD-3-Clause Imports: 15 Imported by: 1

README

gig

gig is (some) Git in Go

Documentation

Index

Constants

View Source
const (
	DeltaOpInsert = 1 //insert data from the delta data into dest
	DeltaOpCopy   = 2 //copy data from the original source into dest
)

DeltaOpCode values.

View Source
const (
	ObjCommit = ObjectType(iota)
	ObjTree
	ObjBlob
	ObjTag

	ObjOFSDelta = ObjectType(0x6)
	ObjRefDelta = ObjectType(0x7)
)

The defined bits match the ones used in the git pack file format.

Variables

This section is empty.

Functions

func IsBareRepository

func IsBareRepository(path string) bool

IsBareRepository checks if path is a bare git repository.

func IsBranchRef

func IsBranchRef(r Ref) bool

func IsDeltaObject

func IsDeltaObject(ot ObjectType) bool

IsDeltaObject checks if an object is a delta object, i.e. OFSDelta or RefDelta

func IsStandardObject

func IsStandardObject(ot ObjectType) bool

IsStandardObject checks if an object is one of the four common objects such as commit, tree, blob, tag.

Types

type Blob

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

Blob represents a git blob object.

func MakeAnnexBlob

func MakeAnnexBlob(fp *os.File, size int64) *Blob

func (*Blob) Close

func (o *Blob) Close() error

func (*Blob) Read

func (b *Blob) Read(data []byte) (n int, err error)

func (*Blob) Size

func (o *Blob) Size() int64

func (*Blob) Type

func (o *Blob) Type() ObjectType

func (*Blob) WriteTo

func (b *Blob) WriteTo(writer io.Writer) (int64, error)

WriteTo writes the blob object to the writer in the on-disk format i.e. as it would be stored in the git objects dir (although uncompressed).

type Commit

type Commit struct {
	Tree      SHA1
	Parent    []SHA1
	Author    Signature
	Committer Signature
	Message   string
	GPGSig    string
	// contains filtered or unexported fields
}

Commit represents one git commit.

func (*Commit) Close

func (o *Commit) Close() error

func (*Commit) Date

func (c *Commit) Date() time.Time

Date returns the commit timestamps (with the correct location).

func (*Commit) Size

func (o *Commit) Size() int64

func (*Commit) Type

func (o *Commit) Type() ObjectType

func (*Commit) WriteTo

func (c *Commit) WriteTo(writer io.Writer) (int64, error)

WriteTo writes the commit object to the writer in the on-disk format i.e. as it would be stored in the git objects dir (although uncompressed).

type CommitSummary

type CommitSummary struct {
	Commit       string
	Committer    string
	Author       string
	DateIso      string
	DateRelative string
	Subject      string
	Changes      []string
}

CommitSummary represents a subset of information from a git commit.

type Delta

type Delta struct {
	BaseRef    SHA1
	BaseOff    int64
	SizeSource int64
	SizeTarget int64
	// contains filtered or unexported fields
}

Delta represents a git delta representation. Either BaseRef or BaseOff are valid fields, depending on its Type().

func (*Delta) Close

func (o *Delta) Close() error

func (*Delta) Err

func (d *Delta) Err() error

Err retrieves the current error state, if any

func (*Delta) NextOp

func (d *Delta) NextOp() bool

NextOp reads the next DeltaOp from the delta data stream. Returns false when there are no operations left or on error; use Err() to decide between the two cases.

func (*Delta) Op

func (d *Delta) Op() DeltaOp

Op returns the current operations

func (*Delta) Patch

func (d *Delta) Patch(r io.ReadSeeker, w io.Writer) error

Patch applies the delta data onto r and writes the result to w.

func (*Delta) Size

func (o *Delta) Size() int64

func (*Delta) SkipOp

func (d *Delta) SkipOp()

SkipOp prepares the delta stream to move to the next operation without actually carrying out the delta operation. Useful for printing the delta stream.

func (*Delta) Type

func (o *Delta) Type() ObjectType

func (*Delta) WriteTo

func (d *Delta) WriteTo(w io.Writer) (int64, error)

WriteTo would write the object to disk in the git object representation. It is not NOT IMPLEMENTED for the delta object.

type DeltaOp

type DeltaOp struct {
	Op     DeltaOpCode
	Size   int64
	Offset int64
}

DeltaOp represents the delta compression operation. Offset is only valid for DeltaOpCopy operations.

type DeltaOpCode

type DeltaOpCode byte

DeltaOpCode is the operation code for delta compression instruction set.

type FanOut

type FanOut [256]uint32

FanOut table where the "N-th entry of this table records the number of objects in the corresponding pack, the first byte of whose object name is less than or equal to N.

func (FanOut) Bounds

func (fo FanOut) Bounds(b byte) (s, e int)

Bounds returns the how many objects whose first byte has a value of b-1 (in s) and b (returned in e) are contained in the fanout table

type IDRef

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

IDRef is a reference that points via a sha1 directly to a git object

func (*IDRef) Fullname

func (r *IDRef) Fullname() string

func (*IDRef) Name

func (r *IDRef) Name() string

func (*IDRef) Namespace

func (r *IDRef) Namespace() string

func (*IDRef) Repo

func (r *IDRef) Repo() *Repository

func (*IDRef) Resolve

func (r *IDRef) Resolve() (SHA1, error)

Resolve for IDRef returns the stored object id (SHA1)

type Object

type Object interface {
	Type() ObjectType
	Size() int64

	io.WriterTo
	io.Closer
}

Object represents a git object. It has information common to all git objects, like their type and their size. Also, all git objects should be closed via Close().

type ObjectType

type ObjectType byte

ObjectType is to the git object type

func ParseObjectType

func ParseObjectType(s string) (ObjectType, error)

ParseObjectType takes a string and converts it to the corresponding ObjectType or error if the string doesn't match any type.

func (ObjectType) String

func (ot ObjectType) String() string

type PackFile

type PackFile struct {
	*os.File

	Version  uint32
	ObjCount uint32
}

PackFile is git pack file with the actual data in it. It should normally not be used directly.

func OpenPackFile

func OpenPackFile(path string) (*PackFile, error)

OpenPackFile opens the git pack file at the given path It will check the pack file header and version. Currently only version 2 is supported. NB: This is low-level API and should most likely not be used directly.

func (*PackFile) OpenObject

func (pf *PackFile) OpenObject(offset int64) (Object, error)

OpenObject reads the git object header at offset and then parses the data as the corresponding object type.

type PackHeader

type PackHeader struct {
	Sig     [4]byte
	Version uint32
	Objects uint32
}

PackHeader stores version and number of objects in the packfile all data is in network-byte order (big-endian)

type PackIndex

type PackIndex struct {
	*os.File

	Version uint32
	FO      FanOut
	// contains filtered or unexported fields
}

PackIndex represents the git pack file index. It is the main object to use for opening objects contained in packfiles vai OpenObject

func PackIndexOpen

func PackIndexOpen(path string) (*PackIndex, error)

PackIndexOpen opens the git pack file with the given path. The ".idx" if missing will be appended.

func (*PackIndex) FindOffset

func (pi *PackIndex) FindOffset(target SHA1) (int64, error)

FindOffset tries to find object with the id target and if if found returns the offset of the object in the pack file. Returns an error that can be detected by os.IsNotExist if the object could not be found.

func (*PackIndex) OpenObject

func (pi *PackIndex) OpenObject(id SHA1) (Object, error)

OpenObject will try to find the object with the given id in it is index and then reach out to its corresponding pack file to open the actual git Object. If the object cannot be found it will return an error the can be detected via os.IsNotExist() Delta objects will returned as such and not be resolved.

func (*PackIndex) OpenPackFile

func (pi *PackIndex) OpenPackFile() (*PackFile, error)

OpenPackFile opens the corresponding pack file.

func (*PackIndex) ReadOffset

func (pi *PackIndex) ReadOffset(pos int) (int64, error)

ReadOffset returns the offset in the pack file of the object at position pos in the FanOut table.

func (*PackIndex) ReadSHA1

func (pi *PackIndex) ReadSHA1(chksum *SHA1, pos int) error

ReadSHA1 reads the SHA1 stared at position pos (in the FanOut table).

type Ref

type Ref interface {
	Repo() *Repository
	Name() string
	Fullname() string
	Namespace() string
	Resolve() (SHA1, error)
}

type Repository

type Repository struct {
	Path string
}

Repository represents an on disk git repository.

func DiscoverRepository

func DiscoverRepository() (*Repository, error)

DiscoverRepository returns the git repository that contains the current working directory, or and error if the current working dir does not lie inside one.

func InitBareRepository

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

InitBareRepository creates a bare git repository at path.

func OpenRepository

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

OpenRepository opens the repository at path. Currently verifies that it is a (bare) repository and returns an error if the check fails.

func (*Repository) BranchExists

func (repo *Repository) BranchExists(branch string) (bool, error)

BranchExists runs the "git branch <branchname> --list" command. It will return an error, if the command fails, true, if the result is not empty and false otherwise.

func (*Repository) CommitsForRef

func (repo *Repository) CommitsForRef(ref string) ([]CommitSummary, error)

CommitsForRef executes a custom git log command for the specified ref of the associated git repository and returns the resulting byte array.

func (*Repository) DeleteCollaborator

func (repo *Repository) DeleteCollaborator(username string) error

DeleteCollaborator removes a collaborator file from the repositories sharing folder.

func (*Repository) GetBlobsForCommit

func (repo *Repository) GetBlobsForCommit(commit *Commit, blobs map[SHA1]*Blob) error

func (*Repository) GetBlobsForTree

func (repo *Repository) GetBlobsForTree(tree *Tree, blobs map[SHA1]*Blob) error

func (*Repository) ObjectForPath

func (repo *Repository) ObjectForPath(root Object, pathstr string) (Object, error)

ObjectForPath will resolve the path to an object for the file tree starting in the node root. The root object can be either a Commit, Tree or Tag.

func (*Repository) OpenObject

func (repo *Repository) OpenObject(id SHA1) (Object, error)

OpenObject returns the git object for a give id (SHA1).

func (*Repository) OpenRef

func (repo *Repository) OpenRef(name string) (Ref, error)

OpenRef returns the Ref with the given name or an error if either no maching could be found or in case the match was not unique.

func (*Repository) ReadDescription

func (repo *Repository) ReadDescription() string

ReadDescription returns the contents of the description file.

func (repo *Repository) Readlink(id SHA1) (string, error)

Readlink returns the destination of a symbilc link blob object

func (*Repository) WalkRef

func (repo *Repository) WalkRef(refname string, goOn func(SHA1) bool) (map[SHA1]*Commit, error)

func (*Repository) WriteDescription

func (repo *Repository) WriteDescription(description string) error

WriteDescription writes the contents of the description file.

type SHA1

type SHA1 [20]byte

SHA1 is the object identifying checksum of the object data

func ParseSHA1

func ParseSHA1(input string) (sha SHA1, err error)

ParseSHA1 expects a string with a hex encoded sha1. It will trim the string of newline and space before parsing.

func (SHA1) String

func (oid SHA1) String() string

type Signature

type Signature struct {
	Name   string
	Email  string
	Date   time.Time
	Offset *time.Location
}

Signature is a combination of who (Name, Email) and when (Date, Offset). Used by Commit, Tag to link an action (committer, author, tagger, ...) with a person in a point in time.

func (Signature) String

func (s Signature) String() string

type SymbolicRef

type SymbolicRef struct {
	Symbol string
	// contains filtered or unexported fields
}

SymbolicRef is a reference that points to another reference

func (*SymbolicRef) Fullname

func (r *SymbolicRef) Fullname() string

func (*SymbolicRef) Name

func (r *SymbolicRef) Name() string

func (*SymbolicRef) Namespace

func (r *SymbolicRef) Namespace() string

func (*SymbolicRef) Repo

func (r *SymbolicRef) Repo() *Repository

func (*SymbolicRef) Resolve

func (r *SymbolicRef) Resolve() (SHA1, error)

Resolve will resolve the symbolic reference into an object id.

type Tag

type Tag struct {
	Object  SHA1
	ObjType ObjectType
	Tag     string
	Tagger  Signature
	Message string
	GPGSig  string
	// contains filtered or unexported fields
}

Tag represents a git tag object.

func (*Tag) Close

func (o *Tag) Close() error

func (*Tag) Size

func (o *Tag) Size() int64

func (*Tag) Type

func (o *Tag) Type() ObjectType

func (*Tag) WriteTo

func (t *Tag) WriteTo(writer io.Writer) (int64, error)

WriteTo writes the tag object to the writer in the on-disk format i.e. as it would be stored in the git objects dir (although uncompressed).

type Tree

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

Tree represents the git tree object.

func (*Tree) Close

func (o *Tree) Close() error

func (*Tree) Entry

func (tree *Tree) Entry() *TreeEntry

Entry returns the current TreeEntry.

func (*Tree) Err

func (tree *Tree) Err() error

Err returns the last error non-EOF error encountered.

func (*Tree) Next

func (tree *Tree) Next() bool

Next advances the pointer to the next TreeEntry within the Tree object. Returns false if it was pointing to the last element (EOF condition), or if there was an error while advacing. Use Err() to resolve between the to conditions.

func (*Tree) Size

func (o *Tree) Size() int64

func (*Tree) Type

func (o *Tree) Type() ObjectType

func (*Tree) WriteTo

func (t *Tree) WriteTo(writer io.Writer) (int64, error)

WriteTo writes the tree object to the writer in the on-disk format i.e. as it would be stored in the git objects dir (although uncompressed).

type TreeEntry

type TreeEntry struct {
	Mode os.FileMode
	Type ObjectType
	ID   SHA1
	Name string
}

TreeEntry holds information about a single entry in the git Tree object.

Jump to

Keyboard shortcuts

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