MCPcopy Create free account
hub / github.com/git/git / guess_remote_head

Function guess_remote_head

remote.c:2492–2544  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2490}
2491
2492struct 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
2546struct stale_heads_info {
2547 struct string_list *ref_names;

Callers 4

set_headFunction · 0.85
wanted_peer_refsFunction · 0.85
cmd_cloneFunction · 0.85
get_head_namesFunction · 0.85

Calls 6

copy_refFunction · 0.85
find_ref_by_nameFunction · 0.85
repo_default_branch_nameFunction · 0.85
xstrfmtFunction · 0.85
oideqFunction · 0.85
starts_withFunction · 0.85

Tested by

no test coverage detected