Files
codebase-memory-mcp/src/git/git_context.h
T
Martin Vogel 7729a8ee9f fix(mcp,cypher): allocate the new query-path memory through the memory core
lint-memory-core failed on #2642: the new search_code scanner, result index, root containment cache and Cypher sort/group/distinct scratch used malloc/calloc/realloc/free directly (mcp.c +22, cypher.c +26, git_context.c +1). They now go through cbm_alloc/cbm_calloc/cbm_realloc/cbm_free/cbm_mem_strdup: file buffers as CBM_MEM_CLASS_EXTRACT, the rest as CBM_MEM_CLASS_OTHER, each block freed with the class it was allocated with. The result index reserves its slot before a result's strings exist, so its insert cannot fail and needs no cleanup; cbm_git_branch_resolve writes into caller buffers instead of returning heap strings. cypher.c ends below its baseline (128 < 132), which is tightened. Output unchanged: 42/42 tool and Cypher responses identical on django; mcp, cypher and git_context suites green under ASan.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-10-14 20:18:55 +02:00

35 lines
1.1 KiB
C

#ifndef CBM_GIT_CONTEXT_H
#define CBM_GIT_CONTEXT_H
#include <stdbool.h>
#include <stddef.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);
/* Only the is_git and branch fields of cbm_git_context_resolve, from the same
* two git commands it uses for them (2 git processes instead of 7). branch
* gets "" when path is not in a git work tree; pass CBM_GIT_BRANCH_MAX bytes
* to read exactly what cbm_git_context_resolve reads. */
#define CBM_GIT_BRANCH_MAX 4096
int cbm_git_branch_resolve(const char *path, bool *is_git, char *branch, size_t branch_size);
void cbm_git_context_free(cbm_git_context_t *ctx);
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