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

Function build_dedup_files_array

src/mcp/mcp.c:14317–14361  ·  view source on GitHub ↗

Build deduplicated file list from search results + raw matches. */

Source from the content-addressed store, hash-verified

14315
14316/* Build deduplicated file list from search results + raw matches. */
14317static yyjson_mut_val *build_dedup_files_array(yyjson_mut_doc *doc, search_result_t *sr,
14318 int result_start, int output_count,
14319 grep_match_t *raw, int raw_start, int raw_count) {
14320 (void)raw_start;
14321 yyjson_mut_val *files_arr = yyjson_mut_arr(doc);
14322 size_t seen_capacity = (size_t)output_count + (size_t)raw_count;
14323 const char **seen_files = seen_capacity > 0 ? calloc(seen_capacity, sizeof(*seen_files)) : NULL;
14324 if (!files_arr || (seen_capacity > 0 && !seen_files)) {
14325 free(seen_files);
14326 return NULL;
14327 }
14328 int seen_count = 0;
14329 for (int fi = 0; fi < output_count; fi++) {
14330 int result_index = result_start + fi;
14331 bool dup = false;
14332 for (int j = 0; j < seen_count; j++) {
14333 if (strcmp(seen_files[j], sr[result_index].file) == 0) {
14334 dup = true;
14335 break;
14336 }
14337 }
14338 if (!dup) {
14339 seen_files[seen_count++] = sr[result_index].file;
14340 yyjson_mut_arr_add_str(doc, files_arr, sr[result_index].file);
14341 }
14342 }
14343 for (int fi = 0; fi < raw_count; fi++) {
14344 /* `raw` contains only the requested page. raw_start is the global
14345 * offset used for continuation metadata, not an array index. */
14346 int raw_index = fi;
14347 bool dup = false;
14348 for (int j = 0; j < seen_count; j++) {
14349 if (strcmp(seen_files[j], raw[raw_index].file) == 0) {
14350 dup = true;
14351 break;
14352 }
14353 }
14354 if (!dup) {
14355 seen_files[seen_count++] = raw[raw_index].file;
14356 yyjson_mut_arr_add_str(doc, files_arr, raw[raw_index].file);
14357 }
14358 }
14359 free(seen_files);
14360 return files_arr;
14361}
14362
14363/* Attach source or context lines to a search result JSON item. */
14364static void attach_result_source(yyjson_mut_doc *doc, yyjson_mut_val *item, search_result_t *r,

Callers 1

assemble_search_outputFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected