Exemplo n.º 1
0
func (db *Database) Push(url string) error {
	catcher := grip.NewCatcher()
	for _, coll := range db.collections {
		catcher.Add(coll.Push(url))
	}
	return catcher.Resolve()
}
Exemplo n.º 2
0
func (db *Database) Update() error {
	catcher := grip.NewCatcher()
	for _, coll := range db.collections {
		catcher.Add(coll.Reset())
	}
	return catcher.Resolve()
}
Exemplo n.º 3
0
func treeRemove(repo *git.Repository, tree *git.Tree, keys []string) (t *git.Tree, err error) {
	builder, err := repo.TreeBuilderFromTree(tree)
	if err != nil {
		return tree, err
	}
	defer builder.Free()

	catcher := grip.NewCatcher()
	for _, fn := range keys {
		catcher.Add(builder.Remove(fn))
	}
	if catcher.HasErrors() {
		return tree, catcher.Resolve()
	}

	newTreeId, err := builder.Write()
	if err != nil {
		return nil, err
	}

	t, err = lookupTree(repo, newTreeId)
	if err != nil {
		return nil, err
	}
	return
}
Exemplo n.º 4
0
func (self *repository) Fetch(remote string) error {
	// TODO catche remotes in self
	// TODO make legit git signature constructor

	var remotes []*git.Remote

	remoteNames, err := self.repo.Remotes.List()
	if err != nil {
		return fmt.Errorf("no remotes defined")
	}

	for _, name := range remoteNames {
		r, err := self.repo.Remotes.Lookup(name)
		if err == nil {
			remotes = append(remotes, r)
		}
	}

	catcher := grip.NewCatcher()
	if remote == "all" {
		for _, remote := range remotes {
			catcher.Add(remote.Fetch([]string{}, &git.FetchOptions{}, ""))
		}
	}

	for _, remote := range remotes {
		if remote.Name() == remote.Name() {
			catcher.Add(remote.Fetch([]string{}, &git.FetchOptions{}, ""))
		}
	}

	return catcher.Resolve()
}
Exemplo n.º 5
0
func (self *repository) StageAllPath(path string) {
	oldCwd, err := os.Getwd()
	if err != nil {
		panic(err)
	}

	if oldCwd != path {
		err = os.Chdir(path)
		if err != nil {
			panic(err)
		}
	}

	deletedFiles, _ := self.runGitCommand("ls-files -d")

	catcher := grip.NewCatcher()
	rmArgs := []string{"rm", "--quiet"}
	rmArgs = append(rmArgs, deletedFiles...)
	catcher.Add(self.checkGitCommand(rmArgs...))
	catcher.Add(self.checkGitCommand("add", "."))

	if oldCwd != path {
		err = os.Chdir(oldCwd)
		if err != nil {
			panic(err)
		}
	}
}
Exemplo n.º 6
0
func (c *Collection) Update(url string) error {
	catcher := grip.NewCatcher()

	catcher.Add(c.Pull(url))
	catcher.Add(c.Reset())

	return catcher.Resolve()
}
Exemplo n.º 7
0
func (self *RstBuilder) Write(fn string) error {
	lines, err := self.GetLines()
	if err != nil {
		return err
	}

	dirName := filepath.Dir(fn)
	err = os.MkdirAll(dirName, 0755)
	if err == nil {
		grip.Noticeln("created directory:", dirName)
	} else {
		grip.Warning(err.Error())
	}

	file, err := os.Create(fn)
	if err != nil {
		return err
	}
	defer file.Close()

	w := bufio.NewWriter(file)
	catcher := grip.NewCatcher()
	var numBytes int
	for _, line := range lines {
		nb, err := fmt.Fprintln(w, line)
		numBytes += nb
		catcher.Add(err)
	}

	catcher.Add(w.Flush())

	if catcher.HasErrors() == false {
		grip.Debugf("wrote %d bytes to file '%f'.", numBytes, fn)
	}

	return catcher.Resolve()
}
Exemplo n.º 8
0
func (txn *Transaction) Run() (err error) {
	// get the transaction lock, and then the collection lock
	txn.Lock()
	defer txn.Unlock()
	txn.coll.Lock()
	defer txn.coll.Unlock()

	catcher := grip.NewCatcher()

	for _, op := range txn.ops {
		if op.action == opAdd {
			// delete any pending deletes in a group before adding any ops.
			err = txn.removeDeleteGroup()
			catcher.Add(err)
			if err != nil && !txn.ContinueOnError {
				return catcher.Resolve()
			}

			value, err := op.convertData()
			catcher.Add(err)
			if err != nil && !txn.ContinueOnError {
				return catcher.Resolve()
			}

			id, err := txn.coll.db.repo.CreateBlobFromBuffer(value)
			catcher.Add(err)
			if err == nil {
				newTree, err := treeAdd(txn.coll.db.repo, txn.coll.tree, op.key, id)
				catcher.Add(err)
				if err != nil && !txn.ContinueOnError {
					catcher.Add(txn.coll.resetUnsafe())
					return catcher.Resolve()
				}
				txn.coll.tree = newTree
			}
		} else if op.action == opDel {
			// it's easy and safe to group deletes. Therefore, we just add to the delete group during processing.
			txn.deleteGroup = append(txn.deleteGroup, op.key)
		}
	}

	// attempt to run the last delete group incase there are items when the loop ends.
	catcher.Add(txn.removeDeleteGroup())

	if catcher.HasErrors() {
		txn.deleteGroup = []string{}
		return catcher.Resolve()
	}

	if len(txn.ops) > 0 && txn.coll.tree != nil {
		err = txn.coll.commitUnsafe(fmt.Sprintf("added %d ops in 1 commit", len(txn.ops)))
		catcher.Add(err)
	}

	txn.ops = []*operation{}
	if len(txn.deleteGroup) > 0 {
		txn.deleteGroup = []string{}
	}

	return catcher.Resolve()
}