Beispiel #1
0
// iterateCommitTrees iterate all reachable trees from the given commit
func iterateCommitTrees(
	s storer.EncodedObjectStorer,
	commit *object.Commit,
	cb func(h plumbing.Hash) error) error {

	tree, err := commit.Tree()
	if err != nil {
		return err
	}
	if err := cb(tree.Hash); err != nil {
		return err
	}

	treeWalker := object.NewTreeWalker(tree, true)

	for {
		_, e, err := treeWalker.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			return err
		}
		if err := cb(e.Hash); err != nil {
			return err
		}
	}

	return nil
}
Beispiel #2
0
func newWithEmpty(a, b *object.Tree) (Changes, error) {
	changes := newEmpty()

	var action Action
	var tree *object.Tree
	if a == nil {
		action = Insert
		tree = b
	} else {
		action = Delete
		tree = a
	}

	w := object.NewTreeWalker(tree, true)
	defer w.Close()

	for {
		path, entry, err := w.Next()
		if err == io.EOF {
			break
		} else if err != nil {
			return nil, fmt.Errorf("cannot get next file: %s", err)
		}

		if entry.Mode.IsDir() {
			continue
		}

		c := &Change{Action: action}

		if action == Insert {
			c.To.Name = path
			c.To.TreeEntry = entry
			c.To.Tree = tree
		} else {
			c.From.Name = path
			c.From.TreeEntry = entry
			c.From.Tree = tree
		}

		changes = append(changes, c)
	}

	return changes, nil
}