mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-11-11 09:25:35 +08:00
Previous behavior: src/mcp/mcp.c:3895 called cbm_git_context_resolve for the single branch field. Attached repositories could execute seven Git commands per project, and a rejected status-based replacement took 3,380.410 ms for the isolated 50-project page. Add src/git/git_context.c:115 resolve_current_branch as the single attached/detached/unborn implementation shared by cbm_git_context_resolve and cbm_git_current_branch. cbm_git_run_first_line_buf drains stdout and reaps symbolic-ref once; cbm_pclose_exit_code normalizes POSIX wait status and Windows GetExitCodeProcess results. Exit 0 returns attached/unborn names, exit 1 returns DETACHED, and non-Git errors remain absent. Route CBM_ONLY_SUITE=git_context in tests/test_main.c:386 so focused runs execute four tests instead of traversing high-memory fixtures. tests/test_git_context.c:252 covers attached, detached, unborn, non-Git, full-context parity, heap cleanup, and portable command setup; tests/test_security.c:621 covers normalized exit 7. Verification: Git context ASAN/UBSan 4/4; normalized-exit canary 1/1; MCP ASAN/UBSan 224/224; scripts/check-source-safety.sh passed; staged diff check passed. The -O2 binary returned the isolated default page in 773.848 ms and explicit full inventory in 5,023.220 ms, preserved 41/53 branch fields including the unborn main branch, and reaped both server processes and all reader threads. Signed-off-by: Andrew Hundt <ATHundt@gmail.com>
31 lines
909 B
C
31 lines
909 B
C
#ifndef CBM_GIT_CONTEXT_H
|
|
#define CBM_GIT_CONTEXT_H
|
|
|
|
#include <stdbool.h>
|
|
|
|
typedef struct {
|
|
bool is_git;
|
|
bool is_worktree;
|
|
bool is_detached;
|
|
bool root_exists;
|
|
char *input_path;
|
|
char *worktree_root;
|
|
char *git_dir;
|
|
char *git_common_dir;
|
|
char *canonical_root;
|
|
char *branch;
|
|
char *branch_slug;
|
|
char *head_sha;
|
|
char *base_sha;
|
|
} cbm_git_context_t;
|
|
|
|
int cbm_git_context_resolve(const char *path, cbm_git_context_t *out);
|
|
void cbm_git_context_free(cbm_git_context_t *ctx);
|
|
/* Resolve only the current branch for branch-only callers. Returns a heap
|
|
* string (including "DETACHED") through out_branch on success. */
|
|
int cbm_git_current_branch(const char *path, char **out_branch);
|
|
char *cbm_git_context_branch_qn(const char *project_name, const cbm_git_context_t *ctx);
|
|
int cbm_git_context_props_json(const cbm_git_context_t *ctx, char *buf, int buf_size);
|
|
|
|
#endif
|