Documentation ¶
Index ¶
- Variables
- func AdapterFromConfig(ctx context.Context, jsonParams string) (block.Adapter, error)
- func CleanPath(fullPath string) string
- type BaseChange
- type Change
- type ChangePair
- type Changes
- type ChangesMergeIter
- type ChangesPairIter
- type CommitFilter
- type CommitIter
- func NewCommitIterBSF(ctx context.Context, c *WrapCommitNode, seenExternal map[string]bool, ...) CommitIter
- func NewCommitIterCTime(ctx context.Context, c *WrapCommitNode, seenExternal map[string]bool, ...) CommitIter
- func NewCommitPostorderIter(ctx context.Context, c *WrapCommitNode, ignore []hash.Hash) CommitIter
- func NewCommitPreorderIter(ctx context.Context, c *WrapCommitNode, seenExternal map[string]bool, ...) CommitIter
- func NewFilterCommitIter(ctx context.Context, from *WrapCommitNode, isValid *CommitFilter, ...) CommitIter
- type Conflict
- type ConflictResolver
- type FullObject
- type FullTreeEntry
- type IChange
- type TreeNode
- func (n TreeNode) Children() ([]noder.Noder, error)
- func (n TreeNode) Equal(other noder.Noder) bool
- func (n TreeNode) Hash() []byte
- func (n TreeNode) IsDir() bool
- func (n TreeNode) Name() string
- func (n TreeNode) NumChildren() (int, error)
- func (n TreeNode) Properties() models.Property
- func (n TreeNode) Skip() bool
- func (n TreeNode) String() string
- func (n TreeNode) SubDir(ctx context.Context, name string) (*TreeNode, error)
- func (n TreeNode) SubEntry(_ context.Context, name string) (models.TreeEntry, error)
- func (n TreeNode) SubFile(ctx context.Context, name string) (*models.Blob, error)
- func (n TreeNode) SubObjects() []models.TreeEntry
- func (n TreeNode) TreeNode() *models.TreeNode
- func (n TreeNode) Type() models.ObjectType
- type WorkRepoState
- type WorkRepository
- func (repository *WorkRepository) ChangeAndCommit(ctx context.Context, msg string, changFn func(root *WorkTree) error) (*models.Commit, error)
- func (repository *WorkRepository) ChangeInWip(ctx context.Context, changFn func(root *WorkTree) error) error
- func (repository *WorkRepository) CheckOut(ctx context.Context, refType WorkRepoState, refName string) error
- func (repository *WorkRepository) CommitChanges(ctx context.Context, msg string) (*models.Commit, error)
- func (repository *WorkRepository) CreateBranch(ctx context.Context, branchName string) (*models.Branch, error)
- func (repository *WorkRepository) CurBranch() *models.Branch
- func (repository *WorkRepository) CurWip() *models.WorkingInProcess
- func (repository *WorkRepository) DeleteBranch(ctx context.Context) error
- func (repository *WorkRepository) DeleteWip(ctx context.Context) error
- func (repository *WorkRepository) DiffCommit(ctx context.Context, toCommitID hash.Hash, pathPrefix string) (*Changes, error)
- func (repository *WorkRepository) GetCommitChanges(ctx context.Context, pathPrefix string) (*Changes, error)
- func (repository *WorkRepository) GetMergeState(ctx context.Context, toMergeCommitHash hash.Hash) ([]*ChangePair, error)
- func (repository *WorkRepository) GetOrCreateWip(ctx context.Context) (*models.WorkingInProcess, bool, error)
- func (repository *WorkRepository) Merge(ctx context.Context, toMergeCommitHash hash.Hash, msg string, ...) (*models.Commit, error)
- func (repository *WorkRepository) ReadBlob(ctx context.Context, blob *models.Blob, rangeSpec *string) (io.ReadCloser, error)
- func (repository *WorkRepository) Reset()
- func (repository *WorkRepository) Revert(ctx context.Context, prefixPath string) error
- func (repository *WorkRepository) RootTree(ctx context.Context) (*WorkTree, error)
- func (repository *WorkRepository) WriteBlob(ctx context.Context, body io.Reader, contentLength int64, ...) (*models.Blob, error)
- type WorkTree
- func (workTree *WorkTree) AddLeaf(ctx context.Context, fullPath string, blob *models.Blob) error
- func (workTree *WorkTree) AppendDirectEntry(ctx context.Context, treeEntry models.TreeEntry) (*models.TreeNode, error)
- func (workTree *WorkTree) ApplyOneChange(ctx context.Context, change IChange) error
- func (workTree *WorkTree) DeleteDirectEntry(ctx context.Context, name string) (*models.TreeNode, bool, error)
- func (workTree *WorkTree) Diff(ctx context.Context, rootTreeHash hash.Hash, prefix string) (*Changes, error)
- func (workTree *WorkTree) FindBlob(ctx context.Context, fullPath string) (*models.Blob, string, error)
- func (workTree *WorkTree) Ls(ctx context.Context, fullPath string) ([]FullTreeEntry, error)
- func (workTree *WorkTree) RemoveEntry(ctx context.Context, fullPath string) error
- func (workTree *WorkTree) ReplaceLeaf(ctx context.Context, fullPath string, blob *models.Blob) error
- func (workTree *WorkTree) ReplaceSubTreeEntry(ctx context.Context, treeEntry models.TreeEntry) (*models.TreeNode, error)
- func (workTree *WorkTree) RepositoryID() uuid.UUID
- func (workTree *WorkTree) Root() *TreeNode
- type WrapCommitNode
- func (c *WrapCommitNode) Commit() *models.Commit
- func (c *WrapCommitNode) GetCommit(ctx context.Context, hash hash.Hash) (*WrapCommitNode, error)
- func (c *WrapCommitNode) GetCommits(ctx context.Context, hashes []hash.Hash) ([]*WrapCommitNode, error)
- func (c *WrapCommitNode) Hash() hash.Hash
- func (c *WrapCommitNode) IsAncestor(ctx context.Context, other *WrapCommitNode) (bool, error)
- func (c *WrapCommitNode) MergeBase(ctx context.Context, other *WrapCommitNode) ([]*WrapCommitNode, error)
- func (c *WrapCommitNode) Parents(ctx context.Context) ([]*WrapCommitNode, error)
- func (c *WrapCommitNode) RepoID() uuid.UUID
- func (c *WrapCommitNode) TreeHash() hash.Hash
Constants ¶
This section is empty.
Variables ¶
var ( ErrActionNotMatch = errors.New("change action not match") ErrConflict = errors.New("conflict dected but not found resolver") )
var ( ErrPathNotFound = fmt.Errorf("path not found") ErrEntryExit = fmt.Errorf("entry exit") ErrBlobMustBeLeaf = fmt.Errorf("blob must be leaf") ErrNotDirectory = fmt.Errorf("path must be a directory") )
var EmptyRoot = &models.TreeNode{ Hash: hash.Hash([]byte{}), Type: models.TreeObject, SubObjects: make([]models.TreeEntry, 0), }
var (
ErrStop = errors.New("stop iter")
)
Functions ¶
func AdapterFromConfig ¶
Types ¶
type BaseChange ¶
type BaseChange struct { Action merkletrie.Action Hash hash.Hash }
type ChangePair ¶
func (ChangePair) Path ¶
func (changePair ChangePair) Path() string
type Changes ¶
type Changes struct {
// contains filtered or unexported fields
}
Changes used to recored changes between commit, also provider iter function
type ChangesMergeIter ¶
type ChangesMergeIter struct {
// contains filtered or unexported fields
}
ChangesMergeIter walk two changes set and merge changes
func NewChangesMergeIter ¶
func NewChangesMergeIter(leftChanges *Changes, rightChanges *Changes, resolver ConflictResolver) *ChangesMergeIter
NewChangesMergeIter create a changes iter with two changes set and resolver function
func (*ChangesMergeIter) Next ¶
func (cw *ChangesMergeIter) Next() (IChange, error)
Next find change file, first sort each file in change, pop files from two changes, compare filename,
left file < right file, pop left change and put right file back to queue left file > right file, pop right file and put left file back to queue both file name match, try to resolve file changes if one of the queue consume up, pick left change in the other queue
type ChangesPairIter ¶
type ChangesPairIter struct {
// contains filtered or unexported fields
}
func NewChangesPairIter ¶
func NewChangesPairIter(leftChanges *Changes, rightChanges *Changes) *ChangesPairIter
func (*ChangesPairIter) Next ¶
func (cw *ChangesPairIter) Next() (*ChangePair, error)
Next find change file, first sort each file in change, pop files from two changes, compare filename,
left file < right file, pop left change and put right file back to queue left file > right file, pop right file and put left file back to queue both file name match, try to resolve file changes if one of the queue consume up, pick left change in the other queue
type CommitFilter ¶
type CommitFilter func(*WrapCommitNode) bool
CommitFilter returns a boolean for the passed Commit
type CommitIter ¶
type CommitIter interface { Next() (*WrapCommitNode, error) ForEach(func(*WrapCommitNode) error) error }
CommitIter is a generic closable interface for iterating over commits.
func NewCommitIterBSF ¶
func NewCommitIterBSF( ctx context.Context, c *WrapCommitNode, seenExternal map[string]bool, ignore []hash.Hash, ) CommitIter
NewCommitIterBSF returns a CommitIter that walks the commit history, starting at the given commit and visiting its parents in pre-order. The given callback will be called for each visited commit. Each commit will be visited only once. If the callback returns an error, walking will stop and will return the error. Other errors might be returned if the history cannot be traversed (e.g. missing objects). Ignore allows to skip some commits from being iterated.
func NewCommitIterCTime ¶
func NewCommitIterCTime( ctx context.Context, c *WrapCommitNode, seenExternal map[string]bool, ignore []hash.Hash, ) CommitIter
NewCommitIterCTime returns a CommitIter that walks the commit history, starting at the given commit and visiting its parents while preserving Committer Time order. this appears to be the closest order to `git log` The given callback will be called for each visited commit. Each commit will be visited only once. If the callback returns an error, walking will stop and will return the error. Other errors might be returned if the history cannot be traversed (e.g. missing objects). Ignore allows to skip some commits from being iterated.
func NewCommitPostorderIter ¶
func NewCommitPostorderIter(ctx context.Context, c *WrapCommitNode, ignore []hash.Hash) CommitIter
NewCommitPostorderIter returns a CommitIter that walks the commit history like WalkCommitHistory but in post-order. This means that after walking a merge commit, the merged commit will be walked before the base it was merged on. This can be useful if you wish to see the history in chronological order. Ignore allows to skip some commits from being iterated.
func NewCommitPreorderIter ¶
func NewCommitPreorderIter( ctx context.Context, c *WrapCommitNode, seenExternal map[string]bool, ignore []hash.Hash, ) CommitIter
NewCommitPreorderIter returns a CommitIter that walks the commit history, starting at the given commit and visiting its parents in pre-order. The given callback will be called for each visited commit. Each commit will be visited only once. If the callback returns an error, walking will stop and will return the error. Other errors might be returned if the history cannot be traversed (e.g. missing objects). Ignore allows to skip some commits from being iterated.
func NewFilterCommitIter ¶
func NewFilterCommitIter( ctx context.Context, from *WrapCommitNode, isValid *CommitFilter, isLimit *CommitFilter, ) CommitIter
NewFilterCommitIter returns a CommitIter that walks the commit history, starting at the passed commit and visiting its parents in Breadth-first order. The commits returned by the CommitIter will validate the passed CommitFilter. The history won't be transversed beyond a commit if isLimit is true for it. Each commit will be visited only once. If the commit history can not be traversed, or the Close() method is called, the CommitIter won't return more commits. If no isValid is passed, all ancestors of from commit will be valid. If no isLimit is limit, all ancestors of all commits will be visited.
type Conflict ¶
type Conflict struct { Path string Left BaseChange Right BaseChange }
type ConflictResolver ¶
ConflictResolver resolve conflict between two change
func OneSideResolver ¶
func OneSideResolver(useLeft bool) ConflictResolver
func ResolveFromSelector ¶
func ResolveFromSelector(resolveMsg map[string]string) ConflictResolver
type FullObject ¶
type FullObject struct {
// contains filtered or unexported fields
}
func (FullObject) Entry ¶
func (objectName FullObject) Entry() models.TreeEntry
func (FullObject) Node ¶
func (objectName FullObject) Node() *models.FileTree
type FullTreeEntry ¶
type IChange ¶
type TreeNode ¶
type TreeNode struct {
// contains filtered or unexported fields
}
func NewTreeNode ¶
func (TreeNode) NumChildren ¶
func (TreeNode) Properties ¶
func (TreeNode) SubObjects ¶
func (TreeNode) Type ¶
func (n TreeNode) Type() models.ObjectType
type WorkRepoState ¶
type WorkRepoState string
const ( InWip WorkRepoState = "wip" InBranch WorkRepoState = "branch" InCommit WorkRepoState = "commit" )
type WorkRepository ¶
type WorkRepository struct {
// contains filtered or unexported fields
}
func NewWorkRepositoryFromConfig ¶
func NewWorkRepositoryFromConfig(ctx context.Context, operator *models.User, repoModel *models.Repository, repo models.IRepo, publicAdapterConfig params.AdapterConfig) (*WorkRepository, error)
func (*WorkRepository) ChangeAndCommit ¶
func (repository *WorkRepository) ChangeAndCommit(ctx context.Context, msg string, changFn func(root *WorkTree) error) (*models.Commit, error)
ChangeAndCommit apply changes to tree, and create a new commit
func (*WorkRepository) ChangeInWip ¶
func (repository *WorkRepository) ChangeInWip(ctx context.Context, changFn func(root *WorkTree) error) error
ChangeInWip apply change to wip
func (*WorkRepository) CheckOut ¶
func (repository *WorkRepository) CheckOut(ctx context.Context, refType WorkRepoState, refName string) error
func (*WorkRepository) CommitChanges ¶
func (repository *WorkRepository) CommitChanges(ctx context.Context, msg string) (*models.Commit, error)
CommitChanges append a new commit to current headTree, read changes from wip, than create a new commit with parent point to current headTree, and replace tree hash with wip's currentTreeHash.
func (*WorkRepository) CreateBranch ¶
func (repository *WorkRepository) CreateBranch(ctx context.Context, branchName string) (*models.Branch, error)
CreateBranch create branch base on current head
func (*WorkRepository) CurBranch ¶
func (repository *WorkRepository) CurBranch() *models.Branch
func (*WorkRepository) CurWip ¶
func (repository *WorkRepository) CurWip() *models.WorkingInProcess
func (*WorkRepository) DeleteBranch ¶
func (repository *WorkRepository) DeleteBranch(ctx context.Context) error
DeleteBranch delete branch also delete wip belong this branch
func (*WorkRepository) DeleteWip ¶
func (repository *WorkRepository) DeleteWip(ctx context.Context) error
DeleteWip remove wip todo remove files
func (*WorkRepository) DiffCommit ¶
func (repository *WorkRepository) DiffCommit(ctx context.Context, toCommitID hash.Hash, pathPrefix string) (*Changes, error)
DiffCommit find file changes in two commit
func (*WorkRepository) GetCommitChanges ¶
func (*WorkRepository) GetMergeState ¶
func (repository *WorkRepository) GetMergeState(ctx context.Context, toMergeCommitHash hash.Hash) ([]*ChangePair, error)
func (*WorkRepository) GetOrCreateWip ¶
func (repository *WorkRepository) GetOrCreateWip(ctx context.Context) (*models.WorkingInProcess, bool, error)
func (*WorkRepository) Merge ¶
func (repository *WorkRepository) Merge(ctx context.Context, toMergeCommitHash hash.Hash, msg string, resolver ConflictResolver) (*models.Commit, error)
Merge implement merge like git, docs https://en.wikipedia.org/wiki/Merge_(version_control)
func (*WorkRepository) ReadBlob ¶
func (repository *WorkRepository) ReadBlob(ctx context.Context, blob *models.Blob, rangeSpec *string) (io.ReadCloser, error)
ReadBlob read blob content with range
func (*WorkRepository) Reset ¶
func (repository *WorkRepository) Reset()
func (*WorkRepository) Revert ¶
func (repository *WorkRepository) Revert(ctx context.Context, prefixPath string) error
Revert changes in wip, not a good algo, but maybe enough
type WorkTree ¶
type WorkTree struct {
// contains filtered or unexported fields
}
func NewWorkTree ¶
func (*WorkTree) AppendDirectEntry ¶
func (*WorkTree) ApplyOneChange ¶
func (*WorkTree) DeleteDirectEntry ¶
func (*WorkTree) Ls ¶
Ls list tree entry of specific path of specific root examples: a -> b a └── b
├── c.txt └── d.txt
Ls(ctx, root, "a") return b Ls(ctx, root, "a/b" return c.txt and d.txt
func (*WorkTree) RemoveEntry ¶
RemoveEntry remove tree entry from specific tree, if directory have only one entry, this directory was remove too examples: a -> b a └── b
├── c.txt └── d.txt
RemoveEntry(ctx, root, "a") return empty root RemoveEntry(ctx, root, "a/b/c.txt") return new root of(a/b/c.txt) RemoveEntry(ctx, root, "a/b") return empty root. a b c.txt d.txt all removed
func (*WorkTree) ReplaceLeaf ¶
func (workTree *WorkTree) ReplaceLeaf(ctx context.Context, fullPath string, blob *models.Blob) error
ReplaceLeaf replace leaf with a new blob, all parent directory updated
func (*WorkTree) ReplaceSubTreeEntry ¶
func (*WorkTree) RepositoryID ¶
type WrapCommitNode ¶
type WrapCommitNode struct {
// contains filtered or unexported fields
}
func Independents ¶
func Independents(ctx context.Context, commits []*WrapCommitNode) ([]*WrapCommitNode, error)
Independents returns a subset of the passed commits, that are not reachable the others It mimics the behavior of `git merge-base --independent commit...`.
func NewWrapCommitNode ¶
func NewWrapCommitNode(commitRepo models.ICommitRepo, commit *models.Commit) *WrapCommitNode
func (*WrapCommitNode) Commit ¶
func (c *WrapCommitNode) Commit() *models.Commit
func (*WrapCommitNode) GetCommit ¶
func (c *WrapCommitNode) GetCommit(ctx context.Context, hash hash.Hash) (*WrapCommitNode, error)
func (*WrapCommitNode) GetCommits ¶
func (c *WrapCommitNode) GetCommits(ctx context.Context, hashes []hash.Hash) ([]*WrapCommitNode, error)
func (*WrapCommitNode) Hash ¶
func (c *WrapCommitNode) Hash() hash.Hash
Hash returns the Hash in the commit.
func (*WrapCommitNode) IsAncestor ¶
func (c *WrapCommitNode) IsAncestor(ctx context.Context, other *WrapCommitNode) (bool, error)
IsAncestor returns true if the actual commit is ancestor of the passed one. It returns an error if the history is not transversable It mimics the behavior of `git merge --is-ancestor actual other`
func (*WrapCommitNode) MergeBase ¶
func (c *WrapCommitNode) MergeBase(ctx context.Context, other *WrapCommitNode) ([]*WrapCommitNode, error)
MergeBase mimics the behavior of `git merge-base actual other`, returning the best common ancestor between the actual and the passed one. The best common ancestors can not be reached from other common ancestors.
func (*WrapCommitNode) Parents ¶
func (c *WrapCommitNode) Parents(ctx context.Context) ([]*WrapCommitNode, error)
Parents return a CommitIter to the parent Commits.
func (*WrapCommitNode) RepoID ¶
func (c *WrapCommitNode) RepoID() uuid.UUID
func (*WrapCommitNode) TreeHash ¶
func (c *WrapCommitNode) TreeHash() hash.Hash
TreeHash returns the TreeHash in the commit.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package merkletrie provides support for n-ary trees that are at the same time Merkle trees and Radix trees (tries).
|
Package merkletrie provides support for n-ary trees that are at the same time Merkle trees and Radix trees (tries). |
internal/fsnoder
Package fsnoder allows to create merkletrie noders that resemble file systems, from human readable string descriptions.
|
Package fsnoder allows to create merkletrie noders that resemble file systems, from human readable string descriptions. |
noder
Package noder provide an interface for defining nodes in a merkletrie, their hashes and their paths (a noders and its ancestors).
|
Package noder provide an interface for defining nodes in a merkletrie, their hashes and their paths (a noders and its ancestors). |