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

Function GetCommit

db/api/api.go:178–212  ·  view source on GitHub ↗
(ctx context.Context, api Interface, pool, revision string)

Source from the content-addressed store, hash-verified

176}
177
178func GetCommit(ctx context.Context, api Interface, pool, revision string) (*commits.Commit, error) {
179 poolID, err := api.PoolID(ctx, pool)
180 if err != nil {
181 return nil, err
182 }
183 commit, err := dbid.ParseID(revision)
184 if err != nil {
185 // LookupBranchByName(ctx
186 if commit, err = api.CommitObject(ctx, poolID, revision); err != nil {
187 return nil, err
188 }
189 }
190 b := newBuffer(commits.Commit{})
191 query := fmt.Sprintf("from %q:log | where id == 0x%s", poolID, idToHex(commit))
192 q, err := api.Query(ctx, srcfiles.Plain(query))
193 if err != nil {
194 return nil, err
195 }
196 defer q.Pull(true)
197 if err := vio.Copy(b, q); err != nil {
198 return nil, err
199 }
200 switch len(b.results) {
201 case 0:
202 return nil, fmt.Errorf("%s: commit not found", commit)
203 case 1:
204 commit, ok := b.results[0].(*commits.Commit)
205 if !ok {
206 return nil, fmt.Errorf("internal error: branch record has wrong type: %T", b.results[0])
207 }
208 return commit, nil
209 default:
210 return nil, fmt.Errorf("internal error: multiple commits found with same id: %s", commit)
211 }
212}
213
214func idToHex(id ksuid.KSUID) string {
215 return hex.EncodeToString(id.Bytes())

Callers 1

getTsFromCommitishMethod · 0.92

Calls 9

ParseIDFunction · 0.92
PlainFunction · 0.92
CopyFunction · 0.92
idToHexFunction · 0.85
newBufferFunction · 0.70
PoolIDMethod · 0.65
CommitObjectMethod · 0.65
QueryMethod · 0.65
PullMethod · 0.65

Tested by

no test coverage detected