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

Function unit_get

src/pipeline/doc_links_cs.c:1375–1410  ·  view source on GitHub ↗

The unit of directory `dir`, made on first sight: a project when `pd` says * which project files the directory holds, else a shared tree. CS_NONE when * memory ran out. */

Source from the content-addressed store, hash-verified

1373 * which project files the directory holds, else a shared tree. CS_NONE when
1374 * memory ran out. */
1375static int unit_get(cs_index_t *ix, const char *dir, const cs_pdir_t *pd) {
1376 intptr_t v = (intptr_t)cbm_ht_get(ix->unit_by_dir, dir);
1377 if (v > 0) {
1378 return (int)(v - SKIP_ONE);
1379 }
1380 if (ix->nunits >= ix->ucap) {
1381 int ncap = ix->ucap ? ix->ucap * PAIR_LEN : CBM_SZ_64;
1382 cs_unit_t *grown = (cs_unit_t *)ix_alloc(ix, (size_t)ncap * sizeof(cs_unit_t));
1383 if (!grown) {
1384 return CS_NONE;
1385 }
1386 if (ix->nunits > 0) {
1387 memcpy(grown, ix->units, (size_t)ix->nunits * sizeof(cs_unit_t));
1388 }
1389 ix->units = grown;
1390 ix->ucap = ncap;
1391 }
1392 char *key = ix_strdup(ix, dir);
1393 if (!key) {
1394 return CS_NONE;
1395 }
1396 int id = ix->nunits++;
1397 cs_unit_t *u = &ix->units[id];
1398 memset(u, 0, sizeof(*u));
1399 u->dir = key;
1400 u->group = CS_NONE;
1401 if (pd) {
1402 const char *base = strrchr(key, '/');
1403 u->is_ref = strcmp(base ? base + SKIP_ONE : key, CS_REF_DIR) == 0;
1404 u->group = group_of(ix, pd);
1405 } else {
1406 ix->nshared++;
1407 }
1408 cbm_ht_set(ix->unit_by_dir, key, (void *)(intptr_t)(id + SKIP_ONE));
1409 return id;
1410}
1411
1412/* The tree of the project-less directory rel[0, len): the length of its root
1413 * -- the largest directory around it that has no project in or below it; the

Callers 1

unit_ofFunction · 0.85

Calls 5

cbm_ht_getFunction · 0.85
group_ofFunction · 0.85
cbm_ht_setFunction · 0.85
ix_allocFunction · 0.70
ix_strdupFunction · 0.70

Tested by

no test coverage detected