gitpipe

package
v16.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: MIT Imports: 14 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(ctx context.Context, items []CatfileInfoResult) CatfileInfoIterator

NewCatfileInfoIterator returns a new CatfileInfoIterator for the given items.

type CatfileInfoOption

type CatfileInfoOption func(cfg *catfileInfoConfig)

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

func WithDiskUsageSize

func WithDiskUsageSize() CatfileInfoOption

WithDiskUsageSize will cause the size of the object to be returned to be the size it takes up on disk. This value will override the existing size field.

func WithSkipCatfileInfoResult

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.ObjectContentReader,
	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(ctx context.Context, 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 DiffTreeOption

type DiffTreeOption func(cfg *diffTreeConfig)

DiffTreeOption is an option for the DiffTree pipeline step.

func DiffTreeWithIgnoreSubmodules

func DiffTreeWithIgnoreSubmodules() DiffTreeOption

DiffTreeWithIgnoreSubmodules causes git-diff-tree(1) to exclude submodule changes.

func DiffTreeWithRecursive

func DiffTreeWithRecursive() DiffTreeOption

DiffTreeWithRecursive will make DiffTree recurse into subtrees.

func DiffTreeWithSkip

func DiffTreeWithSkip(skipResult func(*RevisionResult) (bool, error)) DiffTreeOption

DiffTreeWithSkip 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.

type ForEachRefOption

type ForEachRefOption func(cfg *forEachRefConfig)

ForEachRefOption is an option that can be passed to ForEachRef.

func WithCount

func WithCount(count int) ForEachRefOption

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

func WithForEachRefFormat

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

func WithPointsAt(pointsAt string) ForEachRefOption

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

func WithSortField

func WithSortField(sortField string) ForEachRefOption

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

type LsTreeOption

type LsTreeOption func(cfg *lsTreeConfig)

LsTreeOption is an option for the LsTree pipeline step.

func LsTreeWithBlobFilter

func LsTreeWithBlobFilter() LsTreeOption

LsTreeWithBlobFilter configures LsTree to only pass through blob objects.

func LsTreeWithRecursive

func LsTreeWithRecursive() LsTreeOption

LsTreeWithRecursive will make LsTree recursive into subtrees.

func LsTreeWithSkip

func LsTreeWithSkip(skipResult func(*RevisionResult) (bool, error)) LsTreeOption

LsTreeWithSkip 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.

type ObjectIterator

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 DiffTree

func DiffTree(
	ctx context.Context,
	repo *localrepo.Repo,
	leftRevision, rightRevision string,
	options ...DiffTreeOption,
) RevisionIterator

DiffTree runs git-diff-tree(1) between the two given revisions. The returned channel will contain the new object IDs listed by this command. For deleted files this would be the all-zeroes object ID. Cancelling the context will cause the pipeline to be cancelled, too. By default, it will not recurse into subtrees.

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 LsTree

func LsTree(
	ctx context.Context,
	repo *localrepo.Repo,
	revision string,
	options ...LsTreeOption,
) RevisionIterator

LsTree runs git-ls-tree(1) for the given revisions. The returned channel will contain all object IDs listed by this command. This might include:

  • Blobs
  • Trees, unless you're calling it with LsTreeWithRecursive()
  • Submodules, referring to the commit of the submodule

func NewRevisionIterator

func NewRevisionIterator(ctx context.Context, 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 WithCommitMessagePatterns

func WithCommitMessagePatterns(commitMessagePatterns [][]byte) RevlistOption

WithCommitMessagePatterns causes git-rev-list(1) to only show commits whose message matches any of the regex patterns in commitMessagePatterns.

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 WithIgnoreCase

func WithIgnoreCase(ignoreCase bool) RevlistOption

WithIgnoreCase causes git-rev-list(1) to apply regex patterns in case-insensitive manner.

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

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