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

Function git_capture

src/git/git_context.c:56–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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