git

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2021 License: MIT Imports: 16 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllReferencesFilter allReferencesFilter
View Source
var Exclude exclude
View Source
var Include include

Functions

This section is empty.

Types

type BatchHeader added in v1.5.0

type BatchHeader struct {
	OID        OID
	ObjectType ObjectType
	ObjectSize counts.Count32
}

func ParseBatchHeader added in v1.5.0

func ParseBatchHeader(spec string, header string) (BatchHeader, error)

Parse a `cat-file --batch[-check]` output header line (including the trailing LF). `spec`, if not "", is used in error messages.

type BatchObjectIter

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

BatchObjectIter iterates over objects whose names are fed into its stdin. The output is buffered, so it has to be closed before you can be sure that you have gotten all of the objects.

func (*BatchObjectIter) Close

func (iter *BatchObjectIter) Close()

Close closes the iterator and frees up resources. Close must be called exactly once.

func (*BatchObjectIter) Next

func (iter *BatchObjectIter) Next() (ObjectRecord, bool, error)

Next either returns the next object (its header and contents), or a `false` boolean value if no more objects are left. Objects need to be read asynchronously, but the last objects won't necessarily show up here until `Close()` has been called.

func (*BatchObjectIter) RequestObject added in v1.5.0

func (iter *BatchObjectIter) RequestObject(oid OID) error

RequestObject requests that the object with the specified `oid` be processed. The objects registered via this method can be read using `Next()` in the order that they were requested.

type Combiner added in v1.5.0

type Combiner interface {
	Combine(f1, f2 ReferenceFilter) ReferenceFilter
	Inverted() Combiner
}

Combiner combines two `ReferenceFilter`s into one compound one. `f1` is allowed to be `nil`.

type Commit

type Commit struct {
	Size    counts.Count32
	Parents []OID
	Tree    OID
}

Commit represents the parts of a commit object that we need.

func ParseCommit

func ParseCommit(oid OID, data []byte) (*Commit, error)

ParseCommit parses the commit object whose contents are in `data`. `oid` is used only in error messages.

type Config added in v1.5.0

type Config struct {
	// Prefix is the key prefix that was read to fill this `Config`.
	Prefix string

	// Entries contains the configuration entries that matched
	// `Prefix`, in the order that they are reported by `git config
	// --list`.
	Entries []ConfigEntry
}

Config represents the gitconfig, or part of the gitconfig, read by `ReadConfig()`.

func (*Config) FullKey added in v1.5.0

func (config *Config) FullKey(key string) string

FullKey returns the full gitconfig key name for the relative key name `key`.

type ConfigEntry added in v1.5.0

type ConfigEntry struct {
	// Key is the entry's key, with any common `prefix` removed (see
	// `Config()`).
	Key string

	// Value is the entry's value, as a string.
	Value string
}

ConfigEntry represents an entry in the gitconfig.

type OID

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

OID represents the SHA-1 object ID of a Git object, in binary format.

var NullOID OID

NullOID is the null object ID; i.e., all zeros.

func NewOID

func NewOID(s string) (OID, error)

NewOID converts an object ID in hex format (i.e., `[0-9a-f]{40}`) into an `OID`.

func OIDFromBytes

func OIDFromBytes(oidBytes []byte) (OID, error)

OIDFromBytes converts a byte slice containing an object ID in binary format into an `OID`.

func (OID) Bytes

func (oid OID) Bytes() []byte

Bytes returns a byte slice view of `oid`, in binary format.

func (OID) MarshalJSON

func (oid OID) MarshalJSON() ([]byte, error)

MarshalJSON expresses `oid` as a JSON string with its enclosing quotation marks.

func (OID) String

func (oid OID) String() string

String formats `oid` as a string in hex format.

type ObjectHeaderIter

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

ObjectHeaderIter iterates over the headers within a commit or tag object.

func NewObjectHeaderIter

func NewObjectHeaderIter(name string, data []byte) (ObjectHeaderIter, error)

NewObjectHeaderIter returns an `ObjectHeaderIter` that iterates over the headers in a commit or tag object. `data` should be the object's contents, which is usually terminated by a blank line that separates the header from the comment. However, annotated tags don't always include comments, and Git even tolerates commits without comments, so don't insist on a blank line. `name` is used in error messages.

func (*ObjectHeaderIter) HasNext

func (iter *ObjectHeaderIter) HasNext() bool

HasNext returns true iff there are more headers to retrieve.

func (*ObjectHeaderIter) Next

func (iter *ObjectHeaderIter) Next() (string, string, error)

Next returns the key and value of the next header.

type ObjectIter

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

ObjectIter iterates over objects in a Git repository.

func (*ObjectIter) AddRoot added in v1.5.0

func (iter *ObjectIter) AddRoot(oid OID) error

AddRoot adds another OID to be included in the walk.

func (*ObjectIter) Close

func (iter *ObjectIter) Close()

Close closes the iterator and frees up resources.

func (*ObjectIter) Next

func (iter *ObjectIter) Next() (BatchHeader, bool, error)

Next returns either the next object (its OID, type, and size), or a `false` boolean value to indicate that there are no data left.

type ObjectRecord added in v1.5.0

type ObjectRecord struct {
	BatchHeader
	Data []byte
}

type ObjectType

type ObjectType string

ObjectType represents the type of a Git object ("blob", "tree", "commit", "tag", or "missing").

type Reference

type Reference struct {
	// Refname is the full reference name of the reference.
	Refname string

	// ObjectType is the type of the object referenced.
	ObjectType ObjectType

	// ObjectSize is the size of the referred-to object, in bytes.
	ObjectSize counts.Count32

	// OID is the OID of the referred-to object.
	OID OID
}

Reference represents a Git reference.

func ParseReference added in v1.5.0

func ParseReference(line string) (Reference, error)

ParseReference parses `line` (a non-LF-terminated line) into a `Reference`. It is assumed that `line` is formatted like the output of

git for-each-ref --format='%(objectname) %(objecttype) %(objectsize) %(refname)'

type ReferenceFilter

type ReferenceFilter interface {
	Filter(refname string) bool
}

func PrefixFilter

func PrefixFilter(prefix string) ReferenceFilter

PrefixFilter returns a `ReferenceFilter` that matches references whose names start with the specified `prefix`, which must match at a component boundary. For example,

  • Prefix "refs/foo" matches "refs/foo" and "refs/foo/bar" but not "refs/foobar".
  • Prefix "refs/foo/" matches "refs/foo/bar" but not "refs/foo" or "refs/foobar".

func RegexpFilter added in v1.4.0

func RegexpFilter(pattern string) (ReferenceFilter, error)

RegexpFilter returns a `ReferenceFilter` that matches references whose names match the specified `prefix`, which must match the whole reference name.

type ReferenceIter

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

ReferenceIter is an iterator that interates over references.

func (*ReferenceIter) Next

func (iter *ReferenceIter) Next() (Reference, bool, error)

Next returns either the next reference or a boolean `false` value indicating that the iteration is over. On errors, return an error (in this case, the caller must still call `Close()`).

type Repository

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

Repository represents a Git repository on disk.

func NewRepository

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

NewRepository creates a new repository object that can be used for running `git` commands within that repository.

func (*Repository) ConfigBoolDefault added in v1.5.0

func (repo *Repository) ConfigBoolDefault(key string, defaultValue bool) (bool, error)

func (*Repository) ConfigIntDefault added in v1.5.0

func (repo *Repository) ConfigIntDefault(key string, defaultValue int) (int, error)

func (*Repository) ConfigStringDefault added in v1.5.0

func (repo *Repository) ConfigStringDefault(key string, defaultValue string) (string, error)

func (*Repository) GetConfig added in v1.5.0

func (repo *Repository) GetConfig(prefix string) (*Config, error)

GetConfig returns the entries from gitconfig. If `prefix` is provided, then only include entries in that section, which must match the at a component boundary (as defined by `configKeyMatchesPrefix()`), and strip off the prefix in the keys that are returned.

func (*Repository) GitCommand added in v1.5.0

func (repo *Repository) GitCommand(callerArgs ...string) *exec.Cmd

func (*Repository) NewBatchObjectIter

func (repo *Repository) NewBatchObjectIter(ctx context.Context) (*BatchObjectIter, error)

NewBatchObjectIter returns a `*BatchObjectIterator` and an `io.WriteCloser`. The iterator iterates over objects whose names are fed into the `io.WriteCloser`, one per line. The `io.WriteCloser` should normally be closed and the iterator's output drained before `Close()` is called.

func (*Repository) NewObjectIter

func (repo *Repository) NewObjectIter(ctx context.Context) (*ObjectIter, error)

NewObjectIter returns an iterator that iterates over objects in `repo`. The arguments are passed to `git rev-list --objects`. The second return value is the stdin of the `rev-list` command. The caller can feed values into it but must close it in any case.

func (*Repository) NewReferenceIter

func (repo *Repository) NewReferenceIter(ctx context.Context) (*ReferenceIter, error)

NewReferenceIter returns an iterator that iterates over all of the references in `repo`.

func (*Repository) Path

func (repo *Repository) Path() string

Path returns the path to `repo`.

type Tag

type Tag struct {
	Size         counts.Count32
	Referent     OID
	ReferentType ObjectType
}

Tag represents the information that we need about a Git tag object.

func ParseTag

func ParseTag(oid OID, data []byte) (*Tag, error)

ParseTag parses the Git tag object whose contents are contained in `data`. `oid` is used only in error messages.

type Tree

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

Tree represents a Git tree object.

func ParseTree

func ParseTree(oid OID, data []byte) (*Tree, error)

ParseTree parses the tree object whose contents are contained in `data`. `oid` is currently unused.

func (*Tree) Iter

func (tree *Tree) Iter() *TreeIter

Iter returns an iterator over the entries in `tree`.

func (Tree) Size

func (tree Tree) Size() counts.Count32

Size returns the size of the tree object.

type TreeEntry

type TreeEntry struct {
	Name     string
	OID      OID
	Filemode uint
}

TreeEntry represents an entry in a Git tree object. Note that Name shares memory with the tree data that were originally read; i.e., retaining a pointer to Name keeps the tree data reachable.

type TreeIter

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

TreeIter is an iterator over the entries in a Git tree object.

func (*TreeIter) NextEntry

func (iter *TreeIter) NextEntry() (TreeEntry, bool, error)

NextEntry returns either the next entry in a Git tree, or a `false` boolean value if there are no more entries.

Jump to

Keyboard shortcuts

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