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

Function resolve_enclosing_git_root

src/discover/discover.c:1585–1604  ·  view source on GitHub ↗

When repo_path itself carries no .git (resolve_git_common_dir already * returned false for it), walk upward looking for an enclosing repository, * exactly as `git` itself would when run from a subfolder. Bounded by the * filesystem/drive root: dir is truncated at each iteration, so the loop * cannot run more times than repo_path is characters long. Returns true and * fills ancestor_root (for

Source from the content-addressed store, hash-verified

1583 * the remaining half of issue #510: only the indexed directory's own
1584 * .gitignore was ever consulted, never an enclosing repo's. */
1585static bool resolve_enclosing_git_root(const char *repo_path, char *ancestor_root, size_t ar_sz,
1586 char *common_dir, size_t cd_sz) {
1587 char dir[CBM_SZ_4K];
1588 snprintf(dir, sizeof(dir), "%s", repo_path);
1589 cbm_normalize_path_sep(dir);
1590
1591 for (;;) {
1592 char *slash = strrchr(dir, '/');
1593 /* No separator left, or only the root separator (POSIX "/") or a
1594 * bare drive prefix (Windows "C:/"): nothing above this to check. */
1595 if (!slash || slash == dir || (slash > dir && *(slash - 1) == ':')) {
1596 return false;
1597 }
1598 *slash = '\0';
1599 if (resolve_git_common_dir(dir, common_dir, cd_sz)) {
1600 snprintf(ancestor_root, ar_sz, "%s", dir);
1601 return true;
1602 }
1603 }
1604}
1605
1606/* The enclosing repository's ignore files, kept OUT of the indexed directory's
1607 * own matcher. Merging them in would re-anchor every rooted pattern onto the

Callers 1

discover_implFunction · 0.85

Calls 2

cbm_normalize_path_sepFunction · 0.85
resolve_git_common_dirFunction · 0.85

Tested by

no test coverage detected