| 151 | } |
| 152 | |
| 153 | func LookupBranchByID(ctx context.Context, api Interface, id ksuid.KSUID) (*db.BranchMeta, error) { |
| 154 | b := newBuffer(db.BranchMeta{}) |
| 155 | query := fmt.Sprintf("from :branches | branch.id == 'hex(%s)'", idToHex(id)) |
| 156 | q, err := api.Query(ctx, srcfiles.Plain(query)) |
| 157 | if err != nil { |
| 158 | return nil, err |
| 159 | } |
| 160 | defer q.Pull(true) |
| 161 | if err := vio.Copy(b, q); err != nil { |
| 162 | return nil, err |
| 163 | } |
| 164 | switch len(b.results) { |
| 165 | case 0: |
| 166 | return nil, fmt.Errorf("%s: branch not found", id) |
| 167 | case 1: |
| 168 | branch, ok := b.results[0].(*db.BranchMeta) |
| 169 | if !ok { |
| 170 | return nil, fmt.Errorf("internal error: branch record has wrong type: %T", b.results[0]) |
| 171 | } |
| 172 | return branch, nil |
| 173 | default: |
| 174 | return nil, fmt.Errorf("internal error: multiple branches found with same id: %s", id) |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | func GetCommit(ctx context.Context, api Interface, pool, revision string) (*commits.Commit, error) { |
| 179 | poolID, err := api.PoolID(ctx, pool) |