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

Function git_capture

src/git/git_context.c:46–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46static int git_capture(const char *repo_path, const char *git_args, char **out) {
47 if (!out) {
48 return CBM_NOT_FOUND;
49 }
50 *out = NULL;
51 if (!repo_path || !git_args || !git_validate_repo_path(repo_path)) {
52 return CBM_NOT_FOUND;
53 }
54
55 char cmd[GIT_CMD_MAX];
56#ifdef _WIN32
57 const char *null_dev = "NUL";
58#else
59 const char *null_dev = "/dev/null";
60#endif
61 /* Double quotes work for POSIX shells and cmd.exe. cbm_validate_shell_arg()
62 * rejects quote/backslash/substitution metacharacters before interpolation. */
63 int n = snprintf(cmd, sizeof(cmd), "git -C \"%s\" %s 2>%s", repo_path, git_args, null_dev);
64 if (n < 0 || n >= (int)sizeof(cmd)) {
65 return CBM_NOT_FOUND;
66 }
67
68 FILE *fp = cbm_popen(cmd, "r");
69 if (!fp) {
70 return CBM_NOT_FOUND;
71 }
72
73 char buf[GIT_OUTPUT_MAX];
74 if (!fgets(buf, sizeof(buf), fp)) {
75 cbm_pclose(fp);
76 return CBM_NOT_FOUND;
77 }
78 trim_newlines(buf);
79
80 int rc = cbm_pclose(fp);
81 if (rc != 0 || buf[0] == '\0') {
82 return CBM_NOT_FOUND;
83 }
84
85 *out = git_strdup(buf);
86 return *out ? 0 : CBM_NOT_FOUND;
87}
88
89static bool path_is_absolute(const char *path) {
90 if (!path || !path[0]) {

Callers 1

cbm_git_context_resolveFunction · 0.85

Calls 5

git_validate_repo_pathFunction · 0.85
cbm_popenFunction · 0.85
cbm_pcloseFunction · 0.85
trim_newlinesFunction · 0.85
git_strdupFunction · 0.85

Tested by

no test coverage detected