本文整理汇总了Golang中github.com/libgit2/git2go.Repository.TreeBuilderFromTree方法的典型用法代码示例。如果您正苦于以下问题:Golang Repository.TreeBuilderFromTree方法的具体用法?Golang Repository.TreeBuilderFromTree怎么用?Golang Repository.TreeBuilderFromTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/libgit2/git2go.Repository
的用法示例。
在下文中一共展示了Repository.TreeBuilderFromTree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: treeDel
// Removes a key from the tree.
func treeDel(repo *git.Repository, tree *git.Tree, key string) (*git.Tree, error) {
var err error
key = TreePath(key)
base, leaf := path.Split(key)
if tree != nil {
if tree, err = TreeScope(repo, tree, base); err != nil {
return nil, err
}
}
builder, err := repo.TreeBuilderFromTree(tree)
if err != nil {
return nil, err
}
if err := builder.Remove(leaf); err != nil {
return nil, err
}
treeId, err := builder.Write()
if err != nil {
return nil, err
}
newTree, err := lookupTree(repo, treeId)
if err != nil {
return nil, err
}
return newTree, err
}
示例2: treeAdd
// treeAdd creates a new Git tree by adding a new object
// to it at the specified path.
// Intermediary subtrees are created as needed.
// If an object already exists at key or any intermediary path,
// it is overwritten.
//
// - If merge is true, new trees are merged into existing ones at the
// file granularity (similar to 'cp -R').
// - If it is false, existing trees are completely shadowed (similar to 'mount')
//
// Since git trees are immutable, base is not modified. The new
// tree is returned.
// If an error is encountered, intermediary objects may be left
// behind in the git repository. It is the caller's responsibility
// to perform garbage collection, if any.
// FIXME: manage garbage collection, or provide a list of created
// objects.
func treeAdd(repo *git.Repository, tree *git.Tree, key string, valueId *git.Oid, merge bool) (t *git.Tree, err error) {
/*
** // Primitive but convenient tracing for debugging recursive calls to treeAdd.
** // Uncomment this block for debug output.
**
** var callString string
** if tree != nil {
** callString = fmt.Sprintf(" treeAdd %v:\t\t%s\t\t\t= %v", tree.Id(), key, valueId)
** } else {
** callString = fmt.Sprintf(" treeAdd %v:\t\t%s\t\t\t= %v", tree, key, valueId)
** }
** fmt.Printf(" %s\n", callString)
** defer func() {
** if t != nil {
** fmt.Printf("-> %s => %v\n", callString, t.Id())
** } else {
** fmt.Printf("-> %s => %v\n", callString, err)
** }
** }()
*/
if valueId == nil {
return tree, nil
}
key = TreePath(key)
base, leaf := path.Split(key)
o, err := repo.Lookup(valueId)
if err != nil {
return nil, err
}
var builder *git.TreeBuilder
if tree == nil {
builder, err = repo.TreeBuilder()
if err != nil {
return nil, err
}
} else {
builder, err = repo.TreeBuilderFromTree(tree)
if err != nil {
return nil, err
}
}
defer builder.Free()
// The specified path has only 1 component (the "leaf")
if base == "" || base == "/" {
// If val is a string, set it and we're done.
// Any old value is overwritten.
if _, isBlob := o.(*git.Blob); isBlob {
if err := builder.Insert(leaf, valueId, 0100644); err != nil {
return nil, err
}
newTreeId, err := builder.Write()
if err != nil {
return nil, err
}
newTree, err := lookupTree(repo, newTreeId)
if err != nil {
return nil, err
}
return newTree, nil
}
// If val is not a string, it must be a subtree.
// Return an error if it's any other type than Tree.
oTree, ok := o.(*git.Tree)
if !ok {
return nil, fmt.Errorf("value must be a blob or subtree")
}
var subTree *git.Tree
var oldSubTree *git.Tree
if tree != nil {
oldSubTree, err = TreeScope(repo, tree, leaf)
// FIXME: distinguish "no such key" error (which
// FIXME: distinguish a non-existing previous tree (continue with oldTree==nil)
// from other errors (abort and return an error)
if err == nil {
defer oldSubTree.Free()
}
}
// If that subtree already exists, merge the new one in.
if merge && oldSubTree != nil {
subTree = oldSubTree
for i := uint64(0); i < oTree.EntryCount(); i++ {
var err error
e := oTree.EntryByIndex(i)
//.........这里部分代码省略.........