| 247 | } |
| 248 | |
| 249 | struct commit_graft *read_graft_line(struct strbuf *line) |
| 250 | { |
| 251 | /* The format is just "Commit Parent1 Parent2 ...\n" */ |
| 252 | int i, phase; |
| 253 | const char *tail = NULL; |
| 254 | struct commit_graft *graft = NULL; |
| 255 | struct object_id dummy_oid, *oid; |
| 256 | |
| 257 | strbuf_rtrim(line); |
| 258 | if (!line->len || line->buf[0] == '#') |
| 259 | return NULL; |
| 260 | /* |
| 261 | * phase 0 verifies line, counts hashes in line and allocates graft |
| 262 | * phase 1 fills graft |
| 263 | */ |
| 264 | for (phase = 0; phase < 2; phase++) { |
| 265 | oid = graft ? &graft->oid : &dummy_oid; |
| 266 | if (parse_oid_hex(line->buf, oid, &tail)) |
| 267 | goto bad_graft_data; |
| 268 | for (i = 0; *tail != '\0'; i++) { |
| 269 | oid = graft ? &graft->parent[i] : &dummy_oid; |
| 270 | if (!isspace(*tail++) || parse_oid_hex(tail, oid, &tail)) |
| 271 | goto bad_graft_data; |
| 272 | } |
| 273 | if (!graft) { |
| 274 | graft = xmalloc(st_add(sizeof(*graft), |
| 275 | st_mult(sizeof(struct object_id), i))); |
| 276 | graft->nr_parent = i; |
| 277 | } |
| 278 | } |
| 279 | return graft; |
| 280 | |
| 281 | bad_graft_data: |
| 282 | error("bad graft data: %s", line->buf); |
| 283 | assert(!graft); |
| 284 | return NULL; |
| 285 | } |
| 286 | |
| 287 | static int read_graft_file(struct repository *r, const char *graft_file) |
| 288 | { |
no test coverage detected