| 10 | ) |
| 11 | |
| 12 | func (p *Project) AddDocumentToIndex(doc *pb.Document) error { |
| 13 | oid, size, err := p.createDocument(doc) |
| 14 | if err != nil { |
| 15 | return fmt.Errorf("object couldn't be created: %v", err) |
| 16 | } |
| 17 | |
| 18 | info := doc.GetInfo() |
| 19 | if info == nil { |
| 20 | return ErrNilObjectInfo |
| 21 | } |
| 22 | |
| 23 | entry := &git.IndexEntry{ |
| 24 | Mode: git.FilemodeBlob, |
| 25 | Size: uint32(size), |
| 26 | Id: oid, |
| 27 | Path: info.Path, |
| 28 | } |
| 29 | |
| 30 | index, err := p.repo.Index() |
| 31 | if err != nil { |
| 32 | return fmt.Errorf("could not retreive index: %v", err) |
| 33 | } |
| 34 | |
| 35 | err = index.Add(entry) |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | |
| 40 | return index.Write() |
| 41 | } |
| 42 | |
| 43 | func (p *Project) Index() (docs map[string]*pb.Document, err error) { |
| 44 | index, err := p.repo.Index() |