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

Function get_oid_with_context_1

object-name.c:1730–1871  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1728}
1729
1730static enum get_oid_result get_oid_with_context_1(struct repository *repo,
1731 const char *name,
1732 unsigned flags,
1733 const char *prefix,
1734 struct object_id *oid,
1735 struct object_context *oc)
1736{
1737 int ret, bracket_depth;
1738 int namelen = strlen(name);
1739 const char *cp;
1740 int only_to_die = flags & GET_OID_ONLY_TO_DIE;
1741
1742 memset(oc, 0, sizeof(*oc));
1743 oc->mode = S_IFINVALID;
1744 strbuf_init(&oc->symlink_path, 0);
1745 ret = get_oid_1(repo, name, namelen, oid, flags);
1746 if (!ret && flags & GET_OID_REQUIRE_PATH)
1747 die(_("<object>:<path> required, only <object> '%s' given"),
1748 name);
1749 if (!ret)
1750 return ret;
1751 /*
1752 * tree:path --> object name of path in tree
1753 * :path -> object name of absolute path in index
1754 * :./path -> object name of path relative to cwd in index
1755 * :[0-3]:path -> object name of path in index at stage
1756 * :/foo -> recent commit matching foo
1757 */
1758 if (name[0] == ':') {
1759 int stage = 0;
1760 const struct cache_entry *ce;
1761 char *new_path = NULL;
1762 int pos;
1763 if (!only_to_die && namelen > 2 && name[1] == '/') {
1764 struct handle_one_ref_cb cb;
1765 struct commit_list *list = NULL;
1766
1767 cb.repo = repo;
1768 cb.list = &list;
1769 refs_for_each_ref(get_main_ref_store(repo), handle_one_ref, &cb);
1770 refs_head_ref(get_main_ref_store(repo), handle_one_ref, &cb);
1771 ret = get_oid_oneline(repo, name + 2, oid, list);
1772
1773 commit_list_free(list);
1774 return ret;
1775 }
1776 if (namelen < 3 ||
1777 name[2] != ':' ||
1778 name[1] < '0' || '3' < name[1])
1779 cp = name + 1;
1780 else {
1781 stage = name[1] - '0';
1782 cp = name + 3;
1783 }
1784 new_path = resolve_relative_path(repo, cp);
1785 if (!new_path) {
1786 namelen = namelen - (cp - name);
1787 } else {

Callers 2

get_oid_with_contextFunction · 0.85

Calls 15

strbuf_initFunction · 0.85
get_oid_1Function · 0.85
refs_for_each_refFunction · 0.85
get_main_ref_storeFunction · 0.85
refs_head_refFunction · 0.85
get_oid_onelineFunction · 0.85
commit_list_freeFunction · 0.85
resolve_relative_pathFunction · 0.85
xstrdupFunction · 0.85
repo_read_indexFunction · 0.85
index_name_posFunction · 0.85
reject_tree_in_indexFunction · 0.85

Tested by

no test coverage detected