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

Function sh_join

src/pipeline/pass_shell.c:277–321  ·  view source on GitHub ↗

`rel` (a relative path: ./ and ../ allowed) inside repository directory * `base` ("" = the root), normalized; NULL when it leaves the repository. */

Source from the content-addressed store, hash-verified

275/* `rel` (a relative path: ./ and ../ allowed) inside repository directory
276 * `base` ("" = the root), normalized; NULL when it leaves the repository. */
277static char *sh_join(CBMArena *a, const char *base, const char *rel) {
278 size_t bl = strlen(base);
279 char *out = cbm_arena_alloc(a, bl + strlen(rel) + PAIR_LEN);
280 if (!out) {
281 return NULL;
282 }
283 memcpy(out, base, bl);
284 size_t n = bl;
285 out[n] = '\0';
286 for (const char *p = rel; *p;) {
287 while (*p == '/') {
288 p++;
289 }
290 size_t sl = strcspn(p, "/");
291 if (sl == 0) {
292 break;
293 }
294 if (sl == SKIP_ONE && p[0] == '.') {
295 p += sl;
296 continue;
297 }
298 if (sl == PAIR_LEN && p[0] == '.' && p[SKIP_ONE] == '.') {
299 if (n == 0) {
300 return NULL;
301 }
302 while (n > 0 && out[n - SKIP_ONE] != '/') {
303 n--;
304 }
305 if (n > 0) {
306 n--;
307 }
308 out[n] = '\0';
309 p += sl;
310 continue;
311 }
312 if (n) {
313 out[n++] = '/';
314 }
315 memcpy(out + n, p, sl);
316 n += sl;
317 out[n] = '\0';
318 p += sl;
319 }
320 return out;
321}
322
323static const char *sh_anchor(CBMArena *a, const char *repo_path) {
324 return repo_path ? cbm_arena_sprintf(a, "%c%s", SH_ANCHOR, repo_path) : NULL;

Callers 6

sh_absoluteFunction · 0.85
sh_candidatesFunction · 0.85
sh_make_defaultFunction · 0.85
sh_buildFunction · 0.85
mk_closure_includeFunction · 0.85
sh_ci_cmdFunction · 0.85

Calls 1

cbm_arena_allocFunction · 0.50

Tested by

no test coverage detected