| 358 | } |
| 359 | |
| 360 | static int for_each_root_ref(struct files_ref_store *refs, |
| 361 | int (*cb)(const char *refname, void *cb_data), |
| 362 | void *cb_data) |
| 363 | { |
| 364 | struct strbuf path = STRBUF_INIT, refname = STRBUF_INIT; |
| 365 | struct dirent *de; |
| 366 | int ret; |
| 367 | DIR *d; |
| 368 | |
| 369 | files_ref_path(refs, &path, ""); |
| 370 | |
| 371 | d = opendir(path.buf); |
| 372 | if (!d) { |
| 373 | strbuf_release(&path); |
| 374 | return -1; |
| 375 | } |
| 376 | |
| 377 | while ((de = readdir(d)) != NULL) { |
| 378 | unsigned char dtype; |
| 379 | |
| 380 | if (de->d_name[0] == '.') |
| 381 | continue; |
| 382 | if (ends_with(de->d_name, ".lock")) |
| 383 | continue; |
| 384 | |
| 385 | strbuf_reset(&refname); |
| 386 | strbuf_addstr(&refname, de->d_name); |
| 387 | |
| 388 | dtype = get_dtype(de, &path, 1); |
| 389 | if (dtype == DT_REG && is_root_ref(de->d_name)) { |
| 390 | ret = cb(refname.buf, cb_data); |
| 391 | if (ret) |
| 392 | goto done; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | ret = 0; |
| 397 | |
| 398 | done: |
| 399 | strbuf_release(&refname); |
| 400 | strbuf_release(&path); |
| 401 | closedir(d); |
| 402 | return ret; |
| 403 | } |
| 404 | |
| 405 | struct fill_root_ref_data { |
| 406 | struct files_ref_store *refs; |
no test coverage detected