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

Function get_branch

wt-status.c:1645–1674  ·  view source on GitHub ↗

* Extract branch information from rebase/bisect */

Source from the content-addressed store, hash-verified

1643 * Extract branch information from rebase/bisect
1644 */
1645static char *get_branch(const struct worktree *wt, const char *path)
1646{
1647 struct strbuf sb = STRBUF_INIT;
1648 struct object_id oid;
1649 const char *branch_name;
1650
1651 if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0)
1652 goto got_nothing;
1653
1654 while (sb.len && sb.buf[sb.len - 1] == '\n')
1655 strbuf_setlen(&sb, sb.len - 1);
1656 if (!sb.len)
1657 goto got_nothing;
1658 if (skip_prefix(sb.buf, "refs/heads/", &branch_name))
1659 strbuf_remove(&sb, 0, branch_name - sb.buf);
1660 else if (starts_with(sb.buf, "refs/"))
1661 ;
1662 else if (!get_oid_hex(sb.buf, &oid)) {
1663 strbuf_reset(&sb);
1664 strbuf_add_unique_abbrev(&sb, &oid, DEFAULT_ABBREV);
1665 } else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */
1666 goto got_nothing;
1667 else /* bisect */
1668 ;
1669 return strbuf_detach(&sb, NULL);
1670
1671got_nothing:
1672 strbuf_release(&sb);
1673 return NULL;
1674}
1675
1676struct grab_1st_switch_cbdata {
1677 struct strbuf buf;

Callers 2

wt_status_check_rebaseFunction · 0.85
wt_status_check_bisectFunction · 0.85

Calls 9

strbuf_read_fileFunction · 0.85
worktree_git_pathFunction · 0.85
strbuf_setlenFunction · 0.85
strbuf_removeFunction · 0.85
starts_withFunction · 0.85
get_oid_hexFunction · 0.85
strbuf_add_unique_abbrevFunction · 0.85
strbuf_detachFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected