gitpipe

package
v14.10.5 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: MIT Imports: 13 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 {
	ObjectIterator
	// Result returns the current item.
	Result() CatfileInfoResult
}

CatfileInfoIterator is an iterator returned by the Revlist function.

func CatfileInfo

func CatfileInfo(
	ctx context.Context,
	objectInfoReader catfile.ObjectInfoReader,
	it ObjectIterator,
	opts ...CatfileInfoOption,
) (CatfileInfoIterator, error)

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,
	opts ...CatfileInfoOption,
) 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 NewCatfileInfoIterator

func NewCatfileInfoIterator(items []CatfileInfoResult) CatfileInfoIterator

NewCatfileInfoIterator returns a new CatfileInfoIterator for the given items.

type CatfileInfoOption added in v14.5.0

type CatfileInfoOption func(cfg *catfileInfoConfig)

CatfileInfoOption is an option for the CatfileInfo and CatfileInfoAllObjects pipeline steps.

func WithSkipCatfileInfoResult added in v14.5.0

func WithSkipCatfileInfoResult(skipResult func(*catfile.ObjectInfo) bool) CatfileInfoOption

WithSkipCatfileInfoResult will execute the given function for each ObjectInfo processed by the pipeline. If the callback returns `true`, then the object will be skipped and not passed down the pipeline.

type CatfileInfoResult

type CatfileInfoResult struct {

	// ObjectName is the object name as received from the revlistResultChan.
	ObjectName []byte
	// ObjectInfo provides information about the object.
	git.ObjectInfo
	// contains filtered or unexported fields
}

CatfileInfoResult is a result for the CatfileInfo pipeline step.

type CatfileObjectIterator

type CatfileObjectIterator interface {
	ObjectIterator
	// Result returns the current item.
	Result() CatfileObjectResult
}

CatfileObjectIterator is an iterator returned by the Revlist function.

func CatfileObject

func CatfileObject(
	ctx context.Context,
	objectReader catfile.ObjectReader,
	it ObjectIterator,
) (CatfileObjectIterator, error)

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
	// Object is the object returned by the CatfileObject pipeline step. The object must
	// be fully consumed.
	git.Object
	// contains filtered or unexported fields
}

CatfileObjectResult is a result for the CatfileObject pipeline step.

type ForEachRefOption added in v14.5.0

type ForEachRefOption func(cfg *forEachRefConfig)

ForEachRefOption is an option that can be passed to ForEachRef.

func WithCount added in v14.5.0

func WithCount(count int) ForEachRefOption

WithCount is an option for ForEachRef to limit the number of results

func WithForEachRefFormat added in v14.5.0

func WithForEachRefFormat(format string) ForEachRefOption

WithForEachRefFormat is the format used by git-for-each-ref. Note that each line _must_ be of format "%(objectname) %(refname)" such that the pipeline can parse it correctly. You may use conditional format statements though to potentially produce multiple such lines.

func WithPointsAt added in v14.5.0

func WithPointsAt(pointsAt string) ForEachRefOption

WithPointsAt is an option for ForEachRef to only list refs that point to an object id

func WithSortField added in v14.5.0

func WithSortField(sortField string) ForEachRefOption

WithSortField is an option for ForEachRef that determines the field by which results will be sorted

type ObjectIterator added in v14.5.0

type ObjectIterator interface {
	// Next iterates to the next item. Returns `false` in case there are no more results left,
	// or if an error happened during iteration. The caller must call `Err()` after `Next()` has
	// returned `false`.
	Next() bool
	// Err returns the first error that was encountered.
	Err() error
	// ObjectID returns the object ID of the current object.
	ObjectID() git.ObjectID
	// ObjectName returns the object name of the current object. This is a
	// implementation-specific field and may not be set.
	ObjectName() []byte
}

ObjectIterator is a common interface that is shared across the pipeline steps that work with objects.

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 {
	ObjectIterator
	// 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,
	opts ...ForEachRefOption,
) 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 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.

func WithSkipRevlistResult added in v14.5.0

func WithSkipRevlistResult(skipResult func(*RevisionResult) bool) RevlistOption

WithSkipRevlistResult will execute the given function for each RevisionResult processed by the pipeline. If the callback returns `true`, then the object will be skipped and not passed down the pipeline.

Jump to

Keyboard shortcuts

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