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

Function dm_scratch_work

tests/test_doc_mentions.c:9918–9960  ·  view source on GitHub ↗

What the resolver looks at to build its index over one file of * DM_BIG_MEMBERS fields followed (in path order) by DM_SMALL_FILES files of * one type and one field each. 0 when the repository cannot be indexed or the * large file did not reach the index whole. */

Source from the content-addressed store, hash-verified

9916 * one type and one field each. 0 when the repository cannot be indexed or the
9917 * large file did not reach the index whole. */
9918static uint64_t dm_scratch_work(void) {
9919 char tmp[256];
9920 snprintf(tmp, sizeof(tmp), "/tmp/cbm_dm_scratch_XXXXXX");
9921 if (!cbm_mkdtemp(tmp)) {
9922 return 0;
9923 }
9924 size_t cap = (size_t)DM_BIG_MEMBERS * 32 + 64;
9925 char *src = malloc(cap);
9926 if (!src) {
9927 th_rmtree(tmp);
9928 return 0;
9929 }
9930 size_t w = (size_t)snprintf(src, cap, "namespace Big\n{\n public class Wide\n {\n");
9931 for (int i = 0; i < DM_BIG_MEMBERS; i++) {
9932 w += (size_t)snprintf(src + w, cap - w, " public int f%d;\n", i);
9933 }
9934 snprintf(src + w, cap - w, " }\n}\n");
9935 th_write_file(TH_PATH(tmp, "a/Big.cs"), src);
9936 free(src);
9937 for (int i = 0; i < DM_SMALL_FILES; i++) {
9938 char rel[64];
9939 char text[256];
9940 snprintf(rel, sizeof(rel), "b/S%03d.cs", i);
9941 snprintf(text, sizeof(text),
9942 "namespace Small\n{\n%s public class C%03d { public int x; }\n}\n",
9943 i == 0 ? " /// <summary><see cref=\"Nowhere\"/></summary>\n" : "", i);
9944 th_write_file(TH_PATH(tmp, rel), text);
9945 }
9946 char db[512];
9947 snprintf(db, sizeof(db), "%s/scratch.db", tmp);
9948 cbm_doclink_cs_test_work_reset();
9949 uint64_t work = dm_index(tmp, db, NULL) == 0 ? cbm_doclink_cs_test_scratch_work() : 0;
9950 int rows = dm_count(db, "SELECT COUNT(*) FROM doc_link_unresolved");
9951 int fields = dm_count(db, "SELECT COUNT(*) FROM nodes WHERE label = 'Field' AND "
9952 "file_path = 'a/Big.cs'");
9953 if (fields != DM_BIG_MEMBERS) {
9954 printf(" scratch table: a/Big.cs reached the index with %d of %d fields\n", fields,
9955 (int)DM_BIG_MEMBERS);
9956 }
9957 dm_unlink_db(db);
9958 th_rmtree(tmp);
9959 return rows == 1 && fields == DM_BIG_MEMBERS ? work : 0;
9960}
9961
9962/* The per-file scratch table of the index build is not emptied at the size
9963 * one large file grew it to: after a file of DM_BIG_MEMBERS names, every one

Callers 1

Calls 8

cbm_mkdtempFunction · 0.85
th_rmtreeFunction · 0.85
th_write_fileFunction · 0.85
dm_indexFunction · 0.85
dm_countFunction · 0.85
dm_unlink_dbFunction · 0.85

Tested by

no test coverage detected