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

Function wt_status_get_detached_from

wt-status.c:1709–1743  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1707}
1708
1709static void wt_status_get_detached_from(struct repository *r,
1710 struct wt_status_state *state)
1711{
1712 struct grab_1st_switch_cbdata cb;
1713 struct commit *commit;
1714 struct object_id oid;
1715 char *ref = NULL;
1716
1717 strbuf_init(&cb.buf, 0);
1718 if (refs_for_each_reflog_ent_reverse(get_main_ref_store(r), "HEAD", grab_1st_switch, &cb) <= 0) {
1719 strbuf_release(&cb.buf);
1720 return;
1721 }
1722
1723 if (repo_dwim_ref(r, cb.buf.buf, cb.buf.len, &oid, &ref,
1724 1) == 1 &&
1725 /* oid is a commit? match without further lookup */
1726 (oideq(&cb.noid, &oid) ||
1727 /* perhaps oid is a tag, try to dereference to a commit */
1728 ((commit = lookup_commit_reference_gently(r, &oid, 1)) != NULL &&
1729 oideq(&cb.noid, &commit->object.oid)))) {
1730 const char *from = ref;
1731 if (!skip_prefix(from, "refs/tags/", &from))
1732 skip_prefix(from, "refs/remotes/", &from);
1733 state->detached_from = xstrdup(from);
1734 } else
1735 state->detached_from =
1736 xstrdup(repo_find_unique_abbrev(r, &cb.noid, DEFAULT_ABBREV));
1737 oidcpy(&state->detached_oid, &cb.noid);
1738 state->detached_at = !repo_get_oid(r, "HEAD", &oid) &&
1739 oideq(&oid, &state->detached_oid);
1740
1741 free(ref);
1742 strbuf_release(&cb.buf);
1743}
1744
1745int wt_status_check_rebase(const struct worktree *wt,
1746 struct wt_status_state *state)

Callers 1

wt_status_get_stateFunction · 0.85

Calls 11

strbuf_initFunction · 0.85
get_main_ref_storeFunction · 0.85
strbuf_releaseFunction · 0.85
repo_dwim_refFunction · 0.85
oideqFunction · 0.85
xstrdupFunction · 0.85
repo_find_unique_abbrevFunction · 0.85
oidcpyFunction · 0.85
repo_get_oidFunction · 0.85

Tested by

no test coverage detected