MCPcopy Create free account
hub / github.com/brimdata/super / LookupBranchByName

Function LookupBranchByName

db/api/api.go:128–151  ·  view source on GitHub ↗
(ctx context.Context, api Interface, poolName, branchName string)

Source from the content-addressed store, hash-verified

126}
127
128func LookupBranchByName(ctx context.Context, api Interface, poolName, branchName string) (*db.BranchMeta, error) {
129 b := newBuffer(db.BranchMeta{})
130 query := fmt.Sprintf("from :branches | pool.name == '%s' branch.name == '%s'", poolName, branchName)
131 q, err := api.Query(ctx, srcfiles.Plain(query))
132 if err != nil {
133 return nil, err
134 }
135 defer q.Pull(true)
136 if err := vio.Copy(b, q); err != nil {
137 return nil, err
138 }
139 switch len(b.results) {
140 case 0:
141 return nil, fmt.Errorf("%q: branch not found", poolName+"/"+branchName)
142 case 1:
143 branch, ok := b.results[0].(*db.BranchMeta)
144 if !ok {
145 return nil, fmt.Errorf("internal error: branch record has wrong type: %T", b.results[0])
146 }
147 return branch, nil
148 default:
149 return nil, fmt.Errorf("internal error: multiple branches found with same name: %s", poolName+"/"+branchName)
150 }
151}
152
153func LookupBranchByID(ctx context.Context, api Interface, id ksuid.KSUID) (*db.BranchMeta, error) {
154 b := newBuffer(db.BranchMeta{})

Callers

nothing calls this directly

Calls 5

PlainFunction · 0.92
CopyFunction · 0.92
newBufferFunction · 0.70
QueryMethod · 0.65
PullMethod · 0.65

Tested by

no test coverage detected