Exemplo n.º 1
0
func (p *Project) AddDocumentToIndex(doc *pb.Document) error {
	oid, size, err := p.createDocument(doc)
	if err != nil {
		return fmt.Errorf("object couldn't be created: %v", err)
	}

	info := doc.GetInfo()
	if info == nil {
		return ErrNilObjectInfo
	}

	entry := &git.IndexEntry{
		Mode: git.FilemodeBlob,
		Size: uint32(size),
		Id:   oid,
		Path: info.Path,
	}

	index, err := p.repo.Index()
	if err != nil {
		return fmt.Errorf("could not retreive index: %v", err)
	}

	err = index.Add(entry)
	if err != nil {
		return err
	}

	return index.Write()
}
Exemplo n.º 2
0
func getObjectFromDoc(doc *pb.Document) (*pb.Object, error) {
	root := doc.GetRoot()
	if root == nil {
		return nil, fmt.Errorf("document '%s' does not have a root", doc.Name)
	}

	obj := root.GetObject()
	if obj == nil {
		return nil, fmt.Errorf("root field of document '%s' does not have an object as it's value", doc.Name)
	}
	return obj, nil
}
Exemplo n.º 3
0
// GetFieldFromDocument returns a pointer to field in doc based on the given field path.
func GetFieldFromDocument(doc *pb.Document, fieldpath string) (*pb.Field, error) {
	root := doc.GetRoot()
	if root == nil {
		return nil, fmt.Errorf("root for document '%s' was nil", doc.Name)
	}

	field, err := ResolveRelativeField(root, fieldpath)
	if err != nil {
		return nil, fmt.Errorf("could not resolve '%s': %v", fieldpath, err)
	}
	return field, err
}