versionmgr

package
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: Apache-2.0, MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrActionNotMatch = errors.New("change action not match")
	ErrConflict       = errors.New("conflict dected but not found resolver")
)
View Source
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")
)
View Source
var EmptyDirEntry = models.TreeEntry{
	Name: "",
	Hash: hash.Hash([]byte{}),
}
View Source
var EmptyRoot = &models.TreeNode{
	Hash:       hash.Hash([]byte{}),
	Type:       models.TreeObject,
	SubObjects: make([]models.TreeEntry, 0),
}
View Source
var (
	ErrStop = errors.New("stop iter")
)

Functions

func AdapterFromConfig

func AdapterFromConfig(ctx context.Context, jsonParams string) (block.Adapter, error)

func CleanPath

func CleanPath(fullPath string) string

CleanPath clean path 1. replace \\ to / 2. trim space 3. trim first or last /

Types

type BaseChange

type BaseChange struct {
	Action merkletrie.Action
	Hash   hash.Hash
}

type Change

type Change struct {
	merkletrie.Change
}

Change wrap merkletrie changes for test

func (*Change) From

func (c *Change) From() noder.Path

From return change from

func (*Change) Path

func (c *Change) Path() string

Path return change path

func (*Change) To

func (c *Change) To() noder.Path

To return change to

type ChangePair

type ChangePair struct {
	Left       IChange
	Right      IChange
	IsConflict bool
}

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

func NewChanges

func NewChanges(changes []IChange) *Changes

NewChanges create a change set

func (*Changes) Back

func (c *Changes) Back()

Back a element in array

func (*Changes) Changes

func (c *Changes) Changes() []IChange

Changes return all changes

func (*Changes) ForEach

func (c *Changes) ForEach(fn func(IChange) error) error

func (*Changes) Has

func (c *Changes) Has() bool

Has check whether all element was consumed

func (*Changes) Index

func (c *Changes) Index(idx int) IChange

Index get change by array index

func (*Changes) Next

func (c *Changes) Next() (IChange, error)

Next get element in array

func (*Changes) Num

func (c *Changes) Num() int

Num return change number

func (*Changes) Reset

func (c *Changes) Reset()

Reset result change iter

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) Has

func (cw *ChangesMergeIter) Has() bool

Has check if any changes exit

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

func (*ChangesMergeIter) Reset

func (cw *ChangesMergeIter) Reset()

Reset reset changes

type ChangesPairIter

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

func NewChangesPairIter

func NewChangesPairIter(leftChanges *Changes, rightChanges *Changes) *ChangesPairIter

func (*ChangesPairIter) Has

func (cw *ChangesPairIter) Has() bool

Has check if any changes

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

func (*ChangesPairIter) Reset

func (cw *ChangesPairIter) Reset()

Reset reset changes

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

type ConflictResolver func(left IChange, right IChange) (IChange, error)

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 FullTreeEntry struct {
	Name  string    `json:"name"`
	IsDir bool      `json:"is_dir"`
	Hash  hash.Hash `json:"hash"`
	Size  int64     `json:"size"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type IChange

type IChange interface {
	Action() (merkletrie.Action, error)
	From() noder.Path
	To() noder.Path
	Path() string
	String() string
}

func ForbidResolver

func ForbidResolver(_ IChange, _ IChange) (IChange, error)

func LeastHashResolve

func LeastHashResolve(left IChange, right IChange) (IChange, error)

LeastHashResolve use the least hash change for test

type TreeNode

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

func NewTreeNode

func NewTreeNode(ctx context.Context, entry models.TreeEntry, object models.IFileTreeRepo) (*TreeNode, error)

func (TreeNode) Children

func (n TreeNode) Children() ([]noder.Noder, error)

func (TreeNode) Equal

func (n TreeNode) Equal(other noder.Noder) bool

func (TreeNode) Hash

func (n TreeNode) Hash() []byte

func (TreeNode) IsDir

func (n TreeNode) IsDir() bool

func (TreeNode) Name

func (n TreeNode) Name() string

func (TreeNode) NumChildren

func (n TreeNode) NumChildren() (int, error)

func (TreeNode) Properties

func (n TreeNode) Properties() models.Property

func (TreeNode) Skip

func (n TreeNode) Skip() bool

func (TreeNode) String

func (n TreeNode) String() string

func (TreeNode) SubDir

func (n TreeNode) SubDir(ctx context.Context, name string) (*TreeNode, error)

func (TreeNode) SubEntry

func (n TreeNode) SubEntry(_ context.Context, name string) (models.TreeEntry, error)

func (TreeNode) SubFile

func (n TreeNode) SubFile(ctx context.Context, name string) (*models.Blob, error)

func (TreeNode) SubObjects

func (n TreeNode) SubObjects() []models.TreeEntry

func (TreeNode) TreeNode

func (n TreeNode) TreeNode() *models.TreeNode

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 NewWorkRepositoryFromAdapter

func NewWorkRepositoryFromAdapter(_ context.Context, operator *models.User, repoModel *models.Repository, repo models.IRepo, adapter block.Adapter) *WorkRepository

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 (repository *WorkRepository) GetCommitChanges(ctx context.Context, pathPrefix string) (*Changes, error)

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

func (*WorkRepository) RootTree

func (repository *WorkRepository) RootTree(ctx context.Context) (*WorkTree, error)

RootTree return worktree at root

func (*WorkRepository) WriteBlob

func (repository *WorkRepository) WriteBlob(ctx context.Context, body io.Reader, contentLength int64, properties models.Property) (*models.Blob, error)

WriteBlob write blob content to storage

type WorkTree

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

func NewWorkTree

func NewWorkTree(ctx context.Context, object models.IFileTreeRepo, root models.TreeEntry) (*WorkTree, error)

func (*WorkTree) AddLeaf

func (workTree *WorkTree) AddLeaf(ctx context.Context, fullPath string, blob *models.Blob) error

AddLeaf insert new leaf in entry, if path not exit, create new

func (*WorkTree) AppendDirectEntry

func (workTree *WorkTree) AppendDirectEntry(ctx context.Context, treeEntry models.TreeEntry) (*models.TreeNode, error)

func (*WorkTree) ApplyOneChange

func (workTree *WorkTree) ApplyOneChange(ctx context.Context, change IChange) error

func (*WorkTree) DeleteDirectEntry

func (workTree *WorkTree) DeleteDirectEntry(ctx context.Context, name string) (*models.TreeNode, bool, error)

func (*WorkTree) Diff

func (workTree *WorkTree) Diff(ctx context.Context, rootTreeHash hash.Hash, prefix string) (*Changes, error)

func (*WorkTree) FindBlob

func (workTree *WorkTree) FindBlob(ctx context.Context, fullPath string) (*models.Blob, string, error)

func (*WorkTree) Ls

func (workTree *WorkTree) Ls(ctx context.Context, fullPath string) ([]FullTreeEntry, error)

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

func (workTree *WorkTree) RemoveEntry(ctx context.Context, fullPath string) error

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 *WorkTree) ReplaceSubTreeEntry(ctx context.Context, treeEntry models.TreeEntry) (*models.TreeNode, error)

func (*WorkTree) RepositoryID

func (workTree *WorkTree) RepositoryID() uuid.UUID

func (*WorkTree) Root

func (workTree *WorkTree) Root() *TreeNode

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.

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

Jump to

Keyboard shortcuts

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