plumbing

package
v0.0.32 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRefNotFound = fmt.Errorf("reference not found")
	ErrNoCommits   = fmt.Errorf("no commits")
)
View Source
var (
	IssueBranchPrefix        = "issues"
	MergeRequestBranchPrefix = "merges"
)
View Source
var (
	ErrFailedToGetTagPointedObject = fmt.Errorf("failed to get pointed object of tag")
)

Functions

func BytesToHash

func BytesToHash(bz []byte) plumbing.Hash

BytesToHash converts a byte slice to plumbing.Hash.

func BytesToHex

func BytesToHex(bz []byte) string

HashToBytes decodes an object hash to bytes

func ChangesOpt

func ChangesOpt(ch *types.Changes) types.KVOption

Changes creates a KVOption with 'changes' as key

func CreatePostCommit

func CreatePostCommit(r types.LocalRepo, args *CreatePostCommitArgs) (isNew bool, reference string, err error)

CreatePostCommit creates a new post reference or adds a comment commit to an existing one.

func EmptyChangeResult

func EmptyChangeResult() *types.ChangeResult

EmptyChangeResult returns an empty ChangeResult

func GetChanges

func GetChanges(old, update types.Items) *types.ChangeResult

GetChanges takes one old collection of items and an updated collection of items and attempts to determine the changes that must be executed against the old collection before it is equal to the updated collection.

func GetCommentPreview

func GetCommentPreview(comment *Comment) string

GetCommentPreview returns a preview of a comment

func GetFreePostID

func GetFreePostID(repo types.LocalRepo, startID int, postRefType string) (int, error)

GetFreePostID finds and returns an ID that is unused within the post reference type

func GetKVOpt

func GetKVOpt(key string, options []types.KVOption) interface{}

GetKVOpt finds and returns an option matching the given key

func GetObjectFromPack

func GetObjectFromPack(pack io.ReadSeeker, hash string) (res object.Object, err error)

GetObjectFromPack finds and returns an object from a given pack.

func GetPackableObjects

func GetPackableObjects(
	repo types.LocalRepo,
	obj object.Object,
	objFilter ...func(hash plumbing.Hash) bool) (objs []plumbing.Hash, err error)

GetPackableObjects gets objects related to the given object for creating object-specific packfiles. Commit -> commit object, tree object, tree entries object. Blob -> blob object. Tree -> tree object, tree entries object. Tag -> tag object, pointed object [, objects of pointed object].

func GetReactionsForComment

func GetReactionsForComment(reactions ReactionMap, hash string) map[string]int

GetReactionsForComment returns summed reactions of a comment.

func GetReferenceShortName

func GetReferenceShortName(name string) string

GetReferenceShortName returns the short name of a reference

func GetRepoState

func GetRepoState(repo types.LocalRepo, options ...types.KVOption) types.RepoRefsState

GetRepoState returns the state of the repository repo: The target repository options: Allows the caller to configure how and what state are gathered

func GetTreeEntries

func GetTreeEntries(repo types.LocalRepo, treeHash string) ([]string, error)

GetTreeEntries returns all entries in a tree.

func HashToBytes

func HashToBytes(hexStr string) []byte

HashToBytes decodes an object hash to bytes

func IsBranch

func IsBranch(name string) bool

isBranch checks whether a reference name indicates a branch

func IsIssueReference

func IsIssueReference(name string) bool

IsIssueReference checks whether a branch is an issue branch

func IsIssueReferencePath

func IsIssueReferencePath(name string) bool

IsIssueReferencePath checks if the specified reference matches an issue reference path

func IsMergeRequestReference

func IsMergeRequestReference(name string) bool

IsMergeRequestReference checks whether a branch is a merge request branch

func IsMergeRequestReferencePath

func IsMergeRequestReferencePath(name string) bool

IsMergeRequestReferencePath checks if the specified reference matches a merge request reference path

func IsNote

func IsNote(name string) bool

isNote checks whether a reference name indicates a tag

func IsPostReference

func IsPostReference(name string) bool

IsPostReference checks whether a reference is a post reference

func IsReference

func IsReference(name string) bool

isReference checks the given name is a reference path or full reference name

func IsTag

func IsTag(name string) bool

isTag checks whether a reference name indicates a tag

func IsZeroHash

func IsZeroHash(h string) bool

isZeroHash checks whether a given hash is a zero git hash

func MakeCommitHash

func MakeCommitHash(data string) plumbing.Hash

MakeCommitHash creates and returns a commit hash from the specified data

func MakeIssueReference

func MakeIssueReference(id interface{}) string

MakeIssueReference creates an issue reference

func MakeIssueReferencePath

func MakeIssueReferencePath() string

MakeIssueReferencePath returns the full issue reference path

func MakeMergeRequestReference

func MakeMergeRequestReference(id interface{}) string

MakeMergeRequestReference creates a merge request reference

func MakeMergeRequestReferencePath

func MakeMergeRequestReferencePath() string

MakeIssueReferencePath returns the full merge request reference path

func MatchOpt

func MatchOpt(val string) types.KVOption

MatchOpt creates a KVOption with 'match' as key

func PackObject

func PackObject(repo types.LocalRepo, args *PackObjectArgs) (pack io.Reader, objs []plumbing.Hash, err error)

PackObject creates a packfile from the given object. A commit is packed along with its tree and blobs. An annotated tag is packed along with its referenced commit object. Caller must ensure commit exist in the repo's object database.

func PostBodyToString

func PostBodyToString(body *PostBody) string

PostBodyToString creates a formatted post body from an PostBody object

func Revert

func Revert(
	repo types.LocalRepo,
	prevState types.RepoRefsState,
	options ...types.KVOption) (*types.Changes, error)

Revert reverts the repository from its current state to the previous state. options: Additional options. prefixOpt forces the operation to ignore any reference that does not contain the provided prefix.

func SidebandErr

func SidebandErr(msg string) []byte

SidebandErr creates a sideband error message

func SidebandInfoln

func SidebandInfoln(msg string) []byte

SidebandInfoln creates a sideband progress info message with a newline prefix

func SidebandProgressln

func SidebandProgressln(msg string) []byte

SidebandProgressln creates a sideband progress message with a newline prefix

func SidebandYellowln

func SidebandYellowln(msg string) []byte

SidebandYellowln is like SidebandInfoln but with yellow colored text

func UnpackPackfile

func UnpackPackfile(pack io.ReadSeeker, cb UnpackCallback) (err error)

UnpackPackfile iterates through object headers in the given packfile, passing the callback the header and a function to read the current object.

The callback can return ErrExit to stop the iteration and exit with a nil error. If a different error is returned, then iteration ends with that error returned.

The packfile reader is reset, so it can be reused by the caller. The caller is responsible for closing the packfile reader.

func UnpackPackfileToRepo

func UnpackPackfileToRepo(repo types.LocalRepo, pack io2.ReadSeekerCloser) error

UnpackPackfileToRepo unpacks the packfile into the given repository.

func UpdateReactions

func UpdateReactions(newReactions []string, targetHash, pusherKeyID string, dest ReactionMap)

UpdateReactions calculates reactions for a target comment. newReactions: are new reactions from a comment. targetHash: the unique hash of the comment being reacted to. pusherKeyID: the unique push key ID of the reactor. dest: the map that contains the reaction data of which this function must update.

func WalkBack

func WalkBack(localRepo types.LocalRepo, startHash, endHash string, cb func(hash string) error) error

WalkBack traverses the history of a commit and returns all objects discovered up til the given end object. If start object is not a commit, no traversing operation happens. but the object, along with its related objects (trees, blobs or target) are returned. End object must exist locally; If it is a tag, its target must be a commit.

func WalkCommitHistory

func WalkCommitHistory(repo types.LocalRepo, commit *object.Commit, stopHash string) (hashes []string, err error)

WalkCommitHistory walks back a commit's history, returning its ancestors and other git objects they contain. stopHash stops the walk when an object matching the hash is found. Ancestors of the stop object will not be traversed.

func WalkCommitHistoryWithIteratee

func WalkCommitHistoryWithIteratee(repo types.LocalRepo, args *WalkCommitHistoryArgs) error

WalkCommitHistoryWithIteratee walks back a commit's history, returning its ancestors and other git objects they contain. repo: The target repository args.Commit: The target/start commit args.StopHash: Stops the walk when an object matching the hash is found. Ancestors

of the stop object will not be traversed.

args.Res: A callback that will be called with any found object. Return ErrExit to stop immediately without error or return other error types to end immediately with the specified error.

Types

type Action

type Action struct {
	Data     string
	DataItem types.Item
	Type     ActionType
}

Action describes a repo action to be effected on a repo object

func GetBranchRevertActions

func GetBranchRevertActions(branchRef *types.ItemChange, oldRef types.Item) ([]*Action, error)

GetBranchRevertActions returns a set of actions to be executed against repo in other to bring its branch state to a specific target.

branchRef: The reference that was changed in the repo. oldRef: The version of ref that was in the old state (this one we want to Revert to)

func GetNoteRevertActions

func GetNoteRevertActions(noteRef *types.ItemChange, oldRef types.Item) ([]*Action, error)

GetNoteRevertActions returns actions that represent instruction on how to Revert a repo to a previous state

noteRef: The note reference that was changed in the repo. oldRef: The version of ref that was in the old state (this one we want to Revert to)

func GetTagRevertActions

func GetTagRevertActions(tagRef *types.ItemChange, oldRef types.Item) ([]*Action, error)

GetTagRevertActions returns a set of actions to be executed against repo in other to bring its tag state to a specific target.

tagRef: The reference that was changed in the repo. oldRef: The version of ref that was in the old state (this one we want to Revert to)

type ActionType

type ActionType int

ActionType represents a repo altering action

const (
	// ActionTypeBranchDelete represents an action to delete a branch reference
	ActionTypeBranchDelete ActionType = iota
	// ActionTypeBranchUpdate represents an action to update a branch reference
	ActionTypeBranchUpdate
	// ActionTypeTagDelete represents an action to delete an annotated tag
	ActionTypeTagDelete
	// ActionTypeTagRefUpdate represents an action to update a tag's reference hash
	ActionTypeTagRefUpdate
	// ActionTypeNoteDelete represents an action to delete a note
	ActionTypeNoteDelete
	// ActionTypeNoteUpdate represents an action to update a note reference
	ActionTypeNoteUpdate
)

type Comment

type Comment struct {
	Created      time.Time
	Reference    string
	Hash         string
	Author       string
	AuthorEmail  string
	Signature    string
	Pusher       string
	Body         *PostBody
	GetReactions func() map[string]int
}

Comment represent a reference post comment

type Comments

type Comments []*Comment

Comments is a collection of Comment objects

func (*Comments) Reverse

func (c *Comments) Reverse()

Reverse reverse the posts

type CommitPacker

type CommitPacker func(repo types.LocalRepo, args *PackObjectArgs) (io.Reader, []plumbing.Hash, error)

CommitPacker describes a function for packing an object into a packfile.

type CreatePostCommitArgs

type CreatePostCommitArgs struct {

	// Type is the type of post reference
	Type string

	// ID is the unique ID of the target post reference.
	// If unset, a free ID will be used.
	// If ID is a string, it is expected that the call
	// passed a full post reference path.
	ID interface{}

	// Body is the post's body file content
	Body string

	// IsComment indicates that the post is intended to be a comment
	IsComment bool

	// Force indicates that uncommitted changes can be ignored and lost
	Force bool

	// GetFreePostID is used to find a free post ID
	GetFreePostID FreePostIDFinder
}

CreatePostCommitArgs includes argument for CreatePostCommit

type FreePostIDFinder

type FreePostIDFinder func(repo types.LocalRepo, startID int, postRefType string) (int, error)

type Obj

type Obj struct {
	Type string
	Name string
	Data string
}

Obj implements Item. It represents a repository item.

func (*Obj) Equal

func (ob *Obj) Equal(o interface{}) bool

Equal checks whether r and o are equal

func (*Obj) GetData

func (ob *Obj) GetData() string

GetData returns the data

func (*Obj) GetName

func (ob *Obj) GetName() string

GetName returns the name

func (*Obj) GetType

func (ob *Obj) GetType() string

GetType returns the type

type ObjCol

type ObjCol struct {
	// contains filtered or unexported fields
}

ObjCol implements Items. It is a collection of objects.

func NewObjCol

func NewObjCol(r map[string]types.Item) *ObjCol

NewObjCol creates an ObjCol instance

func (*ObjCol) Bytes

func (oc *ObjCol) Bytes() []byte

Bytes serializes the collection

func (*ObjCol) Equal

func (oc *ObjCol) Equal(o interface{}) bool

Equal checks whether oc and o are equal

func (*ObjCol) ForEach

func (oc *ObjCol) ForEach(iteratee func(i types.Item) bool)

ForEach iterates through the collection. Each item is passed as the only argument to the callback. Return true to break immediately

func (*ObjCol) Get

func (oc *ObjCol) Get(name interface{}) types.Item

Get gets an object by name

func (*ObjCol) Has

func (oc *ObjCol) Has(name interface{}) bool

Has returns true if an object by the given name exists

func (*ObjCol) Hash

func (oc *ObjCol) Hash() util.Bytes32

Hash returns 32-bytes blake2b hash of the collection

func (*ObjCol) Len

func (oc *ObjCol) Len() int64

Len returns the size of the collection

type PackObjectArgs

type PackObjectArgs struct {
	// Obj is the target object to pack
	Obj object.Object

	// Filter selects objects that should be packed by returning true.
	Filter func(hash plumbing.Hash) bool
}

PackObjectArgs contains arguments for PackObject.

type PackObjectFinder

type PackObjectFinder func(pack io.ReadSeeker, hash string) (res object.Object, err error)

PackObjectFinder describes a function for finding a given object in a packfile

type PackToRepoUnpacker

type PackToRepoUnpacker func(repo types.LocalRepo, pack io2.ReadSeekerCloser) error

PackToRepoUnpacker describes a function for writing a packfile into a repository

type PackfileUnpacker

type PackfileUnpacker func(pack io.ReadSeeker, cb UnpackCallback) (err error)

PackfileUnpacker describes a function for unpacking a packfile.

type Post

type Post struct {
	Repo types.LocalRepo

	// Title is the title of the post
	Title string

	// Name is the full reference name of the post
	Name string

	// First is the first comment in the post (main comment).
	First *Comment
}

Post represents a reference post

func (*Post) Comment

func (p *Post) Comment() *Comment

func (*Post) GetComments

func (p *Post) GetComments() (comments Comments, err error)

GetComment returns the comments in the post

func (*Post) GetName

func (p *Post) GetName() string

func (*Post) GetTitle

func (p *Post) GetTitle() string

func (*Post) IsClosed

func (p *Post) IsClosed() (bool, error)

IsClosed tells whether the post is closed by checking if the last comment includes a "closed" directive.

type PostBody

type PostBody struct {

	// Content is the post's main content
	Content []byte `yaml:"-" msgpack:"content,omitempty"`

	// Title is the post's title
	Title string `yaml:"title,omitempty" msgpack:"title,omitempty"`

	// ReplyTo is used to set the comment commit hash to reply to.
	ReplyTo string `yaml:"replyTo,omitempty" msgpack:"replyTo,omitempty"`

	// Reactions are emoji directed at a comment being replied to
	Reactions []string `yaml:"reactions,flow,omitempty" msgpack:"reactions,omitempty"`

	// Close indicates that the post's thread should be closed.
	Close *bool `yaml:"close,omitempty" msgpack:"close,omitempty"`

	// Issue Specific Fields
	types.IssueFields `yaml:",omitempty,inline" msgpack:",omitempty"`

	// Merge Request Fields
	types.MergeRequestFields `yaml:",omitempty,inline" msgpack:",omitempty"`
}

func PostBodyFromContentFrontMatter

func PostBodyFromContentFrontMatter(cfm *pageparser.ContentFrontMatter) *PostBody

PostBodyFromContentFrontMatter attempts to load the instance from the specified content front matter object; It will find expected fields and try to cast the their expected type. It will not validate or return any error.

func ReadPostBody

func ReadPostBody(repo types.LocalRepo, hash string) (*PostBody, *object.Commit, error)

ReadPostBody reads the body file of a commit

func (*PostBody) IncludesAdminFields

func (b *PostBody) IncludesAdminFields() bool

IncludesAdminFields checks whether administrative fields where set

func (*PostBody) WantOpen

func (b *PostBody) WantOpen() bool

WantOpen checks whether close=false

type PostBodyReader

type PostBodyReader func(repo types.LocalRepo, hash string) (*PostBody, *object.Commit, error)

PostBodyReader represents a function for reading a commit's post body

type PostCommitCreator

type PostCommitCreator func(r types.LocalRepo, args *CreatePostCommitArgs) (isNew bool, reference string, err error)

PostCommitCreator is a function type for creating a post commit or adding comments to an existing post reference

type PostEntry

type PostEntry interface {
	GetComments() (comments Comments, err error)
	IsClosed() (bool, error)
	GetTitle() string
	GetName() string
	Comment() *Comment
}

type PostGetter

type PostGetter func(targetRepo types.LocalRepo, filter func(ref plumbing.ReferenceName) bool) (posts Posts, err error)

PostGetter describes a function for finding posts

type Posts

type Posts []PostEntry

Posts is a collection of Post

func GetPosts

func GetPosts(targetRepo types.LocalRepo, filter func(ref plumbing.ReferenceName) bool) (posts Posts, err error)

GetPosts returns references that conform to the post protocol filter is used to check whether a reference is a post reference. Returns a slice of posts

func (*Posts) Reverse

func (p *Posts) Reverse()

Reverse reverse the posts

func (*Posts) SortByFirstPostCreationTimeDesc

func (p *Posts) SortByFirstPostCreationTimeDesc()

SortByFirstPostCreationTimeDesc sorts the posts by their first post creation time in descending order

type ReactionMap

type ReactionMap map[string]map[string]map[string]int

ReactionMap represents mapping for reactions of posts. commentHash: (reactionName: (pusherKeyID: count))

type RevertFunc

type RevertFunc func(repo types.LocalRepo, prevState types.RepoRefsState, options ...types.KVOption) (*types.Changes, error)

type State

type State struct {
	util.CodecUtil
	References *ObjCol
}

GetState describes the current state of repository

func MakeStateFromItem

func MakeStateFromItem(item types.Item) *State

MakeStateFromItem creates a GetState object from an Item. If Item is nil, an empty GetState is returned

func (*State) GetChanges

func (s *State) GetChanges(y types.RepoRefsState) *types.Changes

GetChanges summarizes the changes between GetState s and y.

func (*State) GetReferences

func (s *State) GetReferences() types.Items

GetReferences returns the current repo references

func (*State) IsEmpty

func (s *State) IsEmpty() bool

IsEmpty checks whether the state is empty

type UnpackCallback

type UnpackCallback func(header *packfile.ObjectHeader, read func() (object.Object, error)) error

UnpackCallback is a function for reading and unpacking a packfile object within UnpackPackfile. header is the object header and read is a function for reading the corresponding object.

type WalkCommitHistoryArgs

type WalkCommitHistoryArgs struct {
	Commit   *object.Commit
	StopHash string
	Res      func(objHash string) error
}

WalkCommitHistoryArgs contains arguments for WalkCommitHistoryWithIteratee

Jump to

Keyboard shortcuts

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