MCPcopy
hub / github.com/redspread/spread / DocFromIndex

Method DocFromIndex

pkg/project/index.go:65–87  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

63}
64
65func (p *Project) DocFromIndex(path string) (*pb.Document, error) {
66 index, err := p.repo.Index()
67 if err != nil {
68 return nil, fmt.Errorf("could not retrieve index: %v", err)
69 }
70
71 indexSize := int(index.EntryCount())
72 for i := 0; i < indexSize; i++ {
73 entry, err := index.EntryByIndex(uint(i))
74 if err != nil {
75 return nil, fmt.Errorf("failed to retrieve index entry: %v", err)
76 }
77
78 if entry.Path == path {
79 doc, err := p.getDocument(entry.Id)
80 if err != nil {
81 return nil, fmt.Errorf("failed to read object from Git repository: %v", err)
82 }
83 return doc, nil
84 }
85 }
86 return nil, fmt.Errorf("could not find document with path '%s'", path)
87}
88
89var (
90 ErrNilObjectInfo = errors.New("an object's Info field cannot be nil")

Callers 1

ParamMethod · 0.80

Calls 2

getDocumentMethod · 0.95
IndexMethod · 0.80

Tested by

no test coverage detected