Documentation
¶
Index ¶
- Variables
- type BatchHeader
- type BatchObjectIter
- type Combiner
- type Commit
- type Config
- type ConfigEntry
- type OID
- type ObjectHeaderIter
- type ObjectIter
- type ObjectRecord
- type ObjectType
- type Reference
- type ReferenceFilter
- type ReferenceIter
- type Repository
- func (repo *Repository) ConfigBoolDefault(key string, defaultValue bool) (bool, error)
- func (repo *Repository) ConfigIntDefault(key string, defaultValue int) (int, error)
- func (repo *Repository) ConfigStringDefault(key string, defaultValue string) (string, error)
- func (repo *Repository) GetConfig(prefix string) (*Config, error)
- func (repo *Repository) GitCommand(callerArgs ...string) *exec.Cmd
- func (repo *Repository) NewBatchObjectIter(ctx context.Context) (*BatchObjectIter, error)
- func (repo *Repository) NewObjectIter(ctx context.Context) (*ObjectIter, error)
- func (repo *Repository) NewReferenceIter(ctx context.Context) (*ReferenceIter, error)
- func (repo *Repository) Path() string
- type Tag
- type Tree
- type TreeEntry
- type TreeIter
Constants ¶
This section is empty.
Variables ¶
var AllReferencesFilter allReferencesFilter
var Exclude exclude
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 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()`.
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 OIDFromBytes ¶
OIDFromBytes converts a byte slice containing an object ID in binary format into an `OID`.
func (OID) MarshalJSON ¶
MarshalJSON expresses `oid` as a JSON string with its enclosing quotation marks.
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.
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
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 ¶
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.
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`.
type Tag ¶
type Tag struct { Size counts.Count32 Referent OID ReferentType ObjectType }
Tag represents the information that we need about a Git tag object.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree represents a Git tree object.
func ParseTree ¶
ParseTree parses the tree object whose contents are contained in `data`. `oid` is currently unused.
type TreeEntry ¶
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.