(ctx context.Context, api Interface, pool, revision string)
| 176 | } |
| 177 | |
| 178 | func 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 | |
| 214 | func idToHex(id ksuid.KSUID) string { |
| 215 | return hex.EncodeToString(id.Bytes()) |
no test coverage detected