| 2490 | } |
| 2491 | |
| 2492 | struct ref *guess_remote_head(const struct ref *head, |
| 2493 | const struct ref *refs, |
| 2494 | unsigned flags) |
| 2495 | { |
| 2496 | const struct ref *r; |
| 2497 | struct ref *list = NULL; |
| 2498 | struct ref **tail = &list; |
| 2499 | |
| 2500 | if (!head) |
| 2501 | return NULL; |
| 2502 | |
| 2503 | /* |
| 2504 | * Some transports support directly peeking at |
| 2505 | * where HEAD points; if that is the case, then |
| 2506 | * we don't have to guess. |
| 2507 | */ |
| 2508 | if (head->symref) |
| 2509 | return copy_ref(find_ref_by_name(refs, head->symref)); |
| 2510 | |
| 2511 | /* If a remote branch exists with the default branch name, let's use it. */ |
| 2512 | if (!(flags & REMOTE_GUESS_HEAD_ALL)) { |
| 2513 | char *default_branch = |
| 2514 | repo_default_branch_name(the_repository, |
| 2515 | flags & REMOTE_GUESS_HEAD_QUIET); |
| 2516 | char *ref = xstrfmt("refs/heads/%s", default_branch); |
| 2517 | |
| 2518 | r = find_ref_by_name(refs, ref); |
| 2519 | free(ref); |
| 2520 | free(default_branch); |
| 2521 | |
| 2522 | if (r && oideq(&r->old_oid, &head->old_oid)) |
| 2523 | return copy_ref(r); |
| 2524 | |
| 2525 | /* Fall back to the hard-coded historical default */ |
| 2526 | r = find_ref_by_name(refs, "refs/heads/master"); |
| 2527 | if (r && oideq(&r->old_oid, &head->old_oid)) |
| 2528 | return copy_ref(r); |
| 2529 | } |
| 2530 | |
| 2531 | /* Look for another ref that points there */ |
| 2532 | for (r = refs; r; r = r->next) { |
| 2533 | if (r != head && |
| 2534 | starts_with(r->name, "refs/heads/") && |
| 2535 | oideq(&r->old_oid, &head->old_oid)) { |
| 2536 | *tail = copy_ref(r); |
| 2537 | tail = &((*tail)->next); |
| 2538 | if (!(flags & REMOTE_GUESS_HEAD_ALL)) |
| 2539 | break; |
| 2540 | } |
| 2541 | } |
| 2542 | |
| 2543 | return list; |
| 2544 | } |
| 2545 | |
| 2546 | struct stale_heads_info { |
| 2547 | struct string_list *ref_names; |
no test coverage detected