gitoutput

package
v0.0.0-...-0a43815 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package gitoutput reads the output of calls to `git`.

Index

Constants

This section is empty.

Variables

View Source
var (
	LsTreeFields  = []Field{ObjectMode, ObjectType, ObjectName, Path}
	LsFilesFields = []Field{ObjectMode, ObjectName, ObjectStage, Path}
	StatusFields  = []Field{StatusX, StatusY, Path}
)

These describe the structure of fields in the output of `git` commands.

View Source
var (
	ErrInvalidObjectMode    = errors.New("object mode is not valid")
	ErrInvalidObjectType    = errors.New("object type is not valid")
	ErrInvalidObjectName    = errors.New("object name is not valid")
	ErrInvalidObjectStage   = errors.New("object stage is not valid")
	ErrInvalidObjectStatusX = errors.New("object status x is not valid")
	ErrInvalidObjectStatusY = errors.New("object status y is not valid")
	ErrInvalidPath          = errors.New("path is not valid")
	ErrUnknownField         = errors.New("unknown field")
)

These are the errors that can be returned in ParseError.Err.

Functions

func CheckObjectName

func CheckObjectName(value []byte) error

CheckObjectName asserts that a byte slice looks like a SHA hash.

Types

type Field

type Field int

Field is the type for fields available in outputs to `git`. Used for naming and sensible call sites.

const (
	// ObjectMode is the mode field from `git` outputs. e.g. 100644
	ObjectMode Field = iota + 1
	// ObjectType is the set of allowed types from `git` outputs: blob, tree, commit
	ObjectType
	// ObjectName is the 40-character SHA hash
	ObjectName
	// ObjectStage is a value 0-3.
	ObjectStage
	// StatusX is the first character of the two-character output from `git status`.
	StatusX
	// StatusY is the second character of the two-character output from `git status`.
	StatusY
	// Path is the file path under version control in `git`.
	Path
)

type LsFilesEntry

type LsFilesEntry []string

LsFilesEntry is the result from call `git ls-tree`

func (LsFilesEntry) GetField

func (e LsFilesEntry) GetField(field Field) string

GetField returns the value of the specified field.

type LsTreeEntry

type LsTreeEntry []string

LsTreeEntry is the result from call `git ls-files`

func (LsTreeEntry) GetField

func (e LsTreeEntry) GetField(field Field) string

GetField returns the value of the specified field.

type ParseError

type ParseError struct {
	Entry  int   // Entry where the error occurred
	Column int   // Column where the error occurred
	Err    error // The actual error
}

A ParseError is returned for parsing errors. Entries and columns are both 1-indexed.

func (*ParseError) Error

func (e *ParseError) Error() string

Error creates a string for a parse error.

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

Unwrap returns the raw error.

type Reader

type Reader struct {
	// ReuseRecord controls whether calls to Read may return a slice sharing
	// the backing array of the previous call's returned slice for performance.
	// By default, each call to Read returns newly allocated memory owned by the caller.
	ReuseRecord bool

	// Fields specifies the type of each field.
	Fields []Field
	// contains filtered or unexported fields
}

A Reader reads records from `git`'s output`.

func NewLSFilesReader

func NewLSFilesReader(reader io.Reader) *Reader

NewLSFilesReader returns a new Reader that reads from reader.

func NewLSTreeReader

func NewLSTreeReader(reader io.Reader) *Reader

NewLSTreeReader returns a new Reader that reads from reader.

func NewStatusReader

func NewStatusReader(reader io.Reader) *Reader

NewStatusReader returns a new Reader that reads from reader.

func (*Reader) FieldPos

func (r *Reader) FieldPos(field int) (entry int, column int)

FieldPos returns the entry and column corresponding to the start of the field with the given index in the slice most recently returned by Read. Numbering of entries and columns starts at 1; columns are counted in bytes, not runes.

If this is called with an out-of-bounds index, it panics.

func (*Reader) Read

func (r *Reader) Read() (record []string, err error)

Read reads one record from `reader`. Read always returns either a non-nil record or a non-nil error, but not both.

If there is no data left to be read, Read returns nil, io.EOF.

If ReuseRecord is true, the returned slice may be shared between multiple calls to Read.

func (*Reader) ReadAll

func (r *Reader) ReadAll() (records [][]string, err error)

ReadAll reads all the records from reader until EOF.

A successful call returns err == nil, not err == io.EOF. Because ReadAll is defined to read until EOF, it does not treat end of file as an error to be reported.

type StatusEntry

type StatusEntry []string

StatusEntry is the result from call `git status`

func (StatusEntry) GetField

func (e StatusEntry) GetField(field Field) string

GetField returns the value of the specified field.

Jump to

Keyboard shortcuts

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