Returns 1 when a valid ref has been added to `list`, 0 otherwise */
| 393 | |
| 394 | /* Returns 1 when a valid ref has been added to `list`, 0 otherwise */ |
| 395 | static int process_ref_v2(struct packet_reader *reader, struct ref ***list, |
| 396 | const char **unborn_head_target) |
| 397 | { |
| 398 | int ret = 1; |
| 399 | size_t i = 0; |
| 400 | struct object_id old_oid; |
| 401 | struct ref *ref; |
| 402 | struct string_list line_sections = STRING_LIST_INIT_DUP; |
| 403 | const char *end; |
| 404 | const char *line = reader->line; |
| 405 | |
| 406 | /* |
| 407 | * Ref lines have a number of fields which are space deliminated. The |
| 408 | * first field is the OID of the ref. The second field is the ref |
| 409 | * name. Subsequent fields (symref-target and peeled) are optional and |
| 410 | * don't have a particular order. |
| 411 | */ |
| 412 | if (string_list_split(&line_sections, line, " ", -1) < 2) { |
| 413 | ret = 0; |
| 414 | goto out; |
| 415 | } |
| 416 | |
| 417 | if (!strcmp("unborn", line_sections.items[i].string)) { |
| 418 | i++; |
| 419 | if (unborn_head_target && |
| 420 | !strcmp("HEAD", line_sections.items[i++].string)) { |
| 421 | /* |
| 422 | * Look for the symref target (if any). If found, |
| 423 | * return it to the caller. |
| 424 | */ |
| 425 | for (; i < line_sections.nr; i++) { |
| 426 | const char *arg = line_sections.items[i].string; |
| 427 | |
| 428 | if (skip_prefix(arg, "symref-target:", &arg)) { |
| 429 | *unborn_head_target = xstrdup(arg); |
| 430 | break; |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | goto out; |
| 435 | } |
| 436 | if (parse_oid_hex_algop(line_sections.items[i++].string, &old_oid, &end, reader->hash_algo) || |
| 437 | *end) { |
| 438 | ret = 0; |
| 439 | goto out; |
| 440 | } |
| 441 | |
| 442 | ref = alloc_ref(line_sections.items[i++].string); |
| 443 | |
| 444 | memcpy(ref->old_oid.hash, old_oid.hash, reader->hash_algo->rawsz); |
| 445 | **list = ref; |
| 446 | *list = &ref->next; |
| 447 | |
| 448 | for (; i < line_sections.nr; i++) { |
| 449 | const char *arg = line_sections.items[i].string; |
| 450 | if (skip_prefix(arg, "symref-target:", &arg)) |
| 451 | ref->symref = xstrdup(arg); |
| 452 |
no test coverage detected