Run `parts` over every chunk of target_files; the targets themselves are * excluded from the result. */
| 6488 | /* Run `parts` over every chunk of target_files; the targets themselves are |
| 6489 | * excluded from the result. */ |
| 6490 | static int file_query(cbm_store_t *s, const char *const *parts, int nparts, const char *what, |
| 6491 | const char *project, const char *const *target_files, int target_count, |
| 6492 | char ***out, int *out_count) { |
| 6493 | *out = NULL; |
| 6494 | *out_count = 0; |
| 6495 | if (!s || !project || target_count <= 0) { |
| 6496 | return target_count == 0 ? CBM_STORE_OK : CBM_STORE_ERR; |
| 6497 | } |
| 6498 | /* Exclude the targets themselves up front: an edge between two files of |
| 6499 | * the closure adds nothing, and the caller wants "who ELSE". */ |
| 6500 | CBMHashTable *seen = cbm_ht_create((size_t)target_count * PAIR_LEN); |
| 6501 | if (!seen) { |
| 6502 | return CBM_STORE_ERR; |
| 6503 | } |
| 6504 | for (int i = 0; i < target_count; i++) { |
| 6505 | cbm_ht_set(seen, target_files[i], (void *)target_files[i]); |
| 6506 | } |
| 6507 | char **files = NULL; |
| 6508 | int count = 0; |
| 6509 | int cap = 0; |
| 6510 | int rc = CBM_STORE_OK; |
| 6511 | for (int off = 0; off < target_count && rc == CBM_STORE_OK; off += DEPFILE_CHUNK) { |
| 6512 | int chunk = target_count - off; |
| 6513 | if (chunk > DEPFILE_CHUNK) { |
| 6514 | chunk = DEPFILE_CHUNK; |
| 6515 | } |
| 6516 | rc = file_query_chunk(s, parts, nparts, what, project, target_files + off, chunk, seen, |
| 6517 | &files, &count, &cap); |
| 6518 | } |
| 6519 | cbm_ht_free(seen); |
| 6520 | if (rc != CBM_STORE_OK) { |
| 6521 | cbm_store_free_dependent_files(files, count); |
| 6522 | return rc; |
| 6523 | } |
| 6524 | *out = files; |
| 6525 | *out_count = count; |
| 6526 | return CBM_STORE_OK; |
| 6527 | } |
| 6528 | |
| 6529 | int cbm_store_get_dependent_files(cbm_store_t *s, const char *project, |
| 6530 | const char *const *target_files, int target_count, char ***out, |
no test coverage detected