gitpipe

package
v14.3.5 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ObjectTypeCommit is the type of a Git commit.
	ObjectTypeCommit = ObjectType("commit")
	// ObjectTypeBlob is the type of a Git blob.
	ObjectTypeBlob = ObjectType("blob")
	// ObjectTypeTree is the type of a Git tree.
	ObjectTypeTree = ObjectType("tree")
	// ObjectTypeTag is the type of a Git tag.
	ObjectTypeTag = ObjectType("tag")
)
View Source
const (
	// OrderNone is the default ordering, which is reverse chronological order.
	OrderNone = Order(iota)
	// OrderTopo will cause no parents to be shown before all of its children are shown.
	// Furthermore, multiple lines of history will not be intermixed.
	OrderTopo
	// OrderDate order will cause no parents to be shown before all of its children are shown.
	// Otherwise, commits are shown in commit timestamp order. This can cause history to be
	// shown intermixed.
	OrderDate
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CatfileInfoIterator

type CatfileInfoIterator interface {
	// Next iterates to the next item. Returns `false` in case there are no more results left.
	Next() bool
	// Err returns the first error that was encountered.
	Err() error
	// Result returns the current item.
	Result() CatfileInfoResult
}

CatfileInfoIterator is an iterator returned by the Revlist function.

func CatfileInfo

func CatfileInfo(ctx context.Context, catfile catfile.Batch, revisionIterator RevisionIterator) CatfileInfoIterator

CatfileInfo processes revlistResults from the given channel and extracts object information via `git cat-file --batch-check`. The returned channel will contain all processed catfile info results. Any error received via the channel or encountered in this step will cause the pipeline to fail. Context cancellation will gracefully halt the pipeline.

func CatfileInfoAllObjects

func CatfileInfoAllObjects(ctx context.Context, repo *localrepo.Repo) CatfileInfoIterator

CatfileInfoAllObjects enumerates all Git objects part of the repository's object directory and extracts their object info via `git cat-file --batch-check`. The returned channel will contain all processed results. Any error encountered during execution of this pipeline step will cause the pipeline to fail. Context cancellation will gracefully halt the pipeline. Note that with this pipeline step, the resulting catfileInfoResults will never have an object name.

func CatfileInfoFilter

func CatfileInfoFilter(ctx context.Context, it CatfileInfoIterator, filter func(CatfileInfoResult) bool) CatfileInfoIterator

CatfileInfoFilter filters the catfileInfoResults from the provided channel with the filter function: if the filter returns `false` for a given item, then it will be dropped from the pipeline. Errors cannot be filtered and will always be passed through.

func NewCatfileInfoIterator

func NewCatfileInfoIterator(items []CatfileInfoResult) CatfileInfoIterator

NewCatfileInfoIterator returns a new CatfileInfoIterator for the given items.

type CatfileInfoResult

type CatfileInfoResult struct {

	// ObjectName is the object name as received from the revlistResultChan.
	ObjectName []byte
	// ObjectInfo is the object info of the object.
	ObjectInfo *catfile.ObjectInfo
	// contains filtered or unexported fields
}

CatfileInfoResult is a result for the CatfileInfo pipeline step.

type CatfileObjectIterator

type CatfileObjectIterator interface {
	// Next iterates to the next item. Returns `false` in case there are no more results left.
	Next() bool
	// Err returns the first error that was encountered.
	Err() error
	// Result returns the current item.
	Result() CatfileObjectResult
}

CatfileObjectIterator is an iterator returned by the Revlist function.

func CatfileObject

func CatfileObject(
	ctx context.Context,
	catfileProcess catfile.Batch,
	it CatfileInfoIterator,
) CatfileObjectIterator

CatfileObject processes catfileInfoResults from the given channel and reads associated objects into memory via `git cat-file --batch`. The returned channel will contain all processed objects. Any error received via the channel or encountered in this step will cause the pipeline to fail. Context cancellation will gracefully halt the pipeline. The returned object readers must always be fully consumed by the caller.

func NewCatfileObjectIterator

func NewCatfileObjectIterator(items []CatfileObjectResult) CatfileObjectIterator

NewCatfileObjectIterator returns a new CatfileObjectIterator for the given items.

type CatfileObjectResult

type CatfileObjectResult struct {

	// ObjectName is the object name as received from the revlistResultChan.
	ObjectName []byte
	// ObjectInfo is the object info of the object.
	ObjectInfo *catfile.ObjectInfo
	// obbjectReader is the reader for the raw object data. The reader must always be consumed
	// by the caller.
	ObjectReader io.Reader
	// contains filtered or unexported fields
}

CatfileObjectResult is a result for the CatfileObject pipeline step.

type ObjectType

type ObjectType string

ObjectType is a Git object type used for filtering objects.

type Order

type Order int

Order is the order in which objects are printed.

type RevisionIterator

type RevisionIterator interface {
	// Next iterates to the next item. Returns `false` in case there are no more results left.
	Next() bool
	// Err returns the first error that was encountered.
	Err() error
	// Result returns the current item.
	Result() RevisionResult
}

RevisionIterator is an iterator returned by the Revlist function.

func ForEachRef

func ForEachRef(
	ctx context.Context,
	repo *localrepo.Repo,
	patterns []string,
	sortField string,
) RevisionIterator

ForEachRef runs git-for-each-ref(1) with the given patterns and returns a RevisionIterator for found references. Patterns must always refer to fully qualified reference names. Patterns for which no branch is found do not result in an error. The iterator's object name is set to the reference, while its object ID is the target object the reference points to. Cancelling the context will cause the pipeline to be cancelled, too.

func NewRevisionIterator

func NewRevisionIterator(items []RevisionResult) RevisionIterator

NewRevisionIterator returns a new RevisionIterator for the given items.

func RevisionFilter

func RevisionFilter(ctx context.Context, it RevisionIterator, filter func(RevisionResult) bool) RevisionIterator

RevisionFilter filters the RevisionResult from the provided iterator with the filter function: if the filter returns `false` for a given item, then it will be dropped from the pipeline. Errors cannot be filtered and will always be passed through.

func RevisionTransform

func RevisionTransform(ctx context.Context, it RevisionIterator, transform func(RevisionResult) []RevisionResult) RevisionIterator

RevisionTransform transforms each RevisionResult from the provided iterator with the transforming function. Instead of sending the original RevisionResult, it will instead send transformed results.

func Revlist

func Revlist(
	ctx context.Context,
	repo *localrepo.Repo,
	revisions []string,
	options ...RevlistOption,
) RevisionIterator

Revlist runs git-rev-list(1) with objects and object names enabled. The returned channel will contain all object IDs listed by this command. Cancelling the context will cause the pipeline to be cancelled, too.

type RevisionResult

type RevisionResult struct {

	// OID is the object ID of an object printed by git-rev-list(1).
	OID git.ObjectID
	// ObjectName is the name of the object. This is typically the path of the object if it was
	// traversed via either a tree or a commit. The path depends on the order in which objects
	// are traversed: if e.g. two different trees refer to the same blob with different names,
	// the blob's path depends on which of the trees was traversed first.
	ObjectName []byte
	// contains filtered or unexported fields
}

RevisionResult is a result for the revlist pipeline step.

type RevlistOption

type RevlistOption func(cfg *revlistConfig)

RevlistOption is an option for the revlist pipeline step.

func WithAfter

func WithAfter(t time.Time) RevlistOption

WithAfter will cause git-rev-list(1) to only show commits newer than the specified time.

func WithAuthor

func WithAuthor(author []byte) RevlistOption

WithAuthor will cause git-rev-list(1) to only show commits created by an author matching the given pattern.

func WithBefore

func WithBefore(t time.Time) RevlistOption

WithBefore will cause git-rev-list(1) to only show commits older than the specified time.

func WithBlobLimit

func WithBlobLimit(limit int) RevlistOption

WithBlobLimit sets up a size limit for blobs. Only blobs whose size is smaller than this limit will be returned by the pipeline step.

func WithDisabledWalk

func WithDisabledWalk() RevlistOption

WithDisabledWalk will cause git-rev-list(1) to not do a graph walk beyond the immediate specified tips.

func WithFirstParent

func WithFirstParent() RevlistOption

WithFirstParent will cause git-rev-list(1) to only walk down the first-parent chain of commits.

func WithMaxParents

func WithMaxParents(p uint) RevlistOption

WithMaxParents will cause git-rev-list(1) to list only commits with at most p parents. If set to 1, then merge commits will be skipped. While the zero-value for git-rev-list(1) would cause it to only print the root commit, we use it as the default value and simply print all commits in that case.

func WithObjectTypeFilter

func WithObjectTypeFilter(t ObjectType) RevlistOption

WithObjectTypeFilter will set up a `--filter=object:type=` filter for git-rev-list(1). This will cause it to filter out any objects which do not match the given type. Because git-rev-list(1) by default never filters provided arguments, this option also sets up the `--filter-provided` flag. Note that this option is only supported starting with Git v2.32.0 or later.

func WithObjects

func WithObjects() RevlistOption

WithObjects will cause git-rev-list(1) to not only list commits, but also objects referenced by those commits.

func WithOrder

func WithOrder(o Order) RevlistOption

WithOrder will change the ordering of how objects are listed.

func WithReverse

func WithReverse() RevlistOption

WithReverse will reverse the ordering of commits.

Jump to

Keyboard shortcuts

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