MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / gf_open_identity

Function gf_open_identity

src/mcp/test_impact_git.c:839–930  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

837}
838
839static bool gf_open_identity(cbm_git_facts_t *facts, cbm_git_facts_error_t *error) {
840 const char *prefix;
841 if (!gf_rev_metadata(facts, "--show-prefix", false, &prefix, error))
842 return false;
843 if (prefix[0])
844 return gf_error(error, CBM_GIT_FACTS_INVALID, "Git root must be a worktree top-level");
845 if (!gf_rev_metadata(facts, "--show-toplevel", true, &facts->identity.root, error))
846 return false;
847 facts->options.root = facts->identity.root;
848 if (!gf_rev_metadata(facts, "--absolute-git-dir", true, &facts->identity.git_dir, error))
849 return false;
850 /* HEAD and worktree-local refs must be resolved in this worktree's Git
851 * directory, even if its root gitfile is repointed after discovery. */
852 facts->command_git_dir = facts->identity.git_dir;
853 if (!gf_rev_metadata(facts, "--git-common-dir", true, &facts->identity.common_dir, error))
854 return false;
855 facts->graft_paths[0] =
856 cbm_arena_sprintf(&facts->arena, "%s/info/grafts", facts->identity.git_dir);
857 facts->graft_paths[1] =
858 cbm_arena_sprintf(&facts->arena, "%s/info/grafts", facts->identity.common_dir);
859 facts->shallow_paths[0] =
860 cbm_arena_sprintf(&facts->arena, "%s/shallow", facts->identity.git_dir);
861 facts->shallow_paths[1] =
862 cbm_arena_sprintf(&facts->arena, "%s/shallow", facts->identity.common_dir);
863 if (!facts->graft_paths[0] || !facts->graft_paths[1] || !facts->shallow_paths[0] ||
864 !facts->shallow_paths[1])
865 return gf_error(error, CBM_GIT_FACTS_OOM, "Cannot retain Git history guard paths");
866 if (!gf_history_guard(facts, error))
867 return false;
868 const char *format, *shallow;
869 if (!gf_rev_metadata(facts, "--show-object-format=storage", false, &format, error))
870 return false;
871 if (strcmp(format, "sha1") == 0)
872 facts->identity.oid_hex_length = 40;
873 else if (strcmp(format, "sha256") == 0)
874 facts->identity.oid_hex_length = 64;
875 else
876 return gf_error(error, CBM_GIT_FACTS_UNSUPPORTED, "Unsupported Git object format");
877 if (!gf_rev_metadata(facts, "--is-shallow-repository", false, &shallow, error))
878 return false;
879 if (strcmp(shallow, "false") != 0)
880 return gf_error(error, CBM_GIT_FACTS_UNSUPPORTED, "Complete local Git history is required");
881 if (!gf_resolve(facts, "HEAD", facts->identity.head, error) ||
882 !gf_resolve(facts, facts->options.base_ref, facts->identity.base, error))
883 return false;
884 /* Reject a persistent commondir redirect during ref resolution before
885 * switching to OID-only access through the captured common directory. */
886 if (!gf_history_guard(facts, error))
887 return false;
888 if (facts->options.expected_head) {
889 char expected[65];
890 if (!gf_oid(expected, (const unsigned char *)facts->options.expected_head,
891 strlen(facts->options.expected_head), facts->identity.oid_hex_length))
892 return gf_error(error, CBM_GIT_FACTS_INVALID, "Expected HEAD must be a full object ID");
893 if (strcmp(expected, facts->identity.head) != 0)
894 return gf_error(error, CBM_GIT_FACTS_IDENTITY_MISMATCH,
895 "HEAD does not match expected identity");
896 }

Callers 1

cbm_git_facts_openFunction · 0.85

Calls 9

gf_rev_metadataFunction · 0.85
gf_errorFunction · 0.85
gf_history_guardFunction · 0.85
gf_resolveFunction · 0.85
gf_runFunction · 0.85
gf_oid_lineFunction · 0.85
gf_gateFunction · 0.85
gf_oidFunction · 0.70
cbm_arena_sprintfFunction · 0.50

Tested by

no test coverage detected