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

Function cbm_gitignore_merge

src/discover/gitignore.c:419–457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

417char *(*cbm_gitignore_merge_dup_hook_for_test)(const char *) = NULL;
418
419bool cbm_gitignore_merge(cbm_gitignore_t *dst, const cbm_gitignore_t *src) {
420 if (!dst) {
421 return false;
422 }
423 if (!src || src->count == 0) {
424 return true; /* nothing to merge */
425 }
426 int needed = dst->count + src->count;
427 if (needed > dst->capacity) {
428 gi_pattern_t *grown = realloc(dst->patterns, (size_t)needed * sizeof(gi_pattern_t));
429 if (!grown) {
430 return false; /* dst left unchanged */
431 }
432 dst->patterns = grown;
433 dst->capacity = needed;
434 }
435 int start_count = dst->count;
436 for (int i = 0; i < src->count; i++) {
437 char *pat = cbm_gitignore_merge_dup_hook_for_test
438 ? cbm_gitignore_merge_dup_hook_for_test(src->patterns[i].pattern)
439 : strdup(src->patterns[i].pattern);
440 if (!pat) {
441 /* Roll back partial copies so dst is unchanged on failure (atomic
442 * merge). A silent partial merge could drop the very exclude
443 * pattern the caller relied on while keeping others. */
444 for (int j = start_count; j < dst->count; j++) {
445 free(dst->patterns[j].pattern);
446 }
447 dst->count = start_count;
448 return false;
449 }
450 dst->patterns[dst->count].pattern = pat;
451 dst->patterns[dst->count].negated = src->patterns[i].negated;
452 dst->patterns[dst->count].dir_only = src->patterns[i].dir_only;
453 dst->patterns[dst->count].rooted = src->patterns[i].rooted;
454 dst->count++;
455 }
456 return true;
457}

Callers 2

discover_implFunction · 0.85
test_gitignore.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected