MCPcopy Index your code
hub / github.com/git/git / expire_commit_graphs

Function expire_commit_graphs

commit-graph.c:2495–2552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2493}
2494
2495static void expire_commit_graphs(struct write_commit_graph_context *ctx)
2496{
2497 struct strbuf path = STRBUF_INIT;
2498 DIR *dir;
2499 struct dirent *de;
2500 size_t dirnamelen;
2501 timestamp_t expire_time = time(NULL);
2502
2503 if (ctx->opts && ctx->opts->expire_time)
2504 expire_time = ctx->opts->expire_time;
2505 if (!ctx->split) {
2506 char *chain_file_name = get_commit_graph_chain_filename(ctx->odb_source);
2507 unlink(chain_file_name);
2508 free(chain_file_name);
2509 ctx->num_commit_graphs_after = 0;
2510 }
2511
2512 strbuf_addstr(&path, ctx->odb_source->path);
2513 strbuf_addstr(&path, "/info/commit-graphs");
2514 dir = opendir(path.buf);
2515
2516 if (!dir)
2517 goto out;
2518
2519 strbuf_addch(&path, '/');
2520 dirnamelen = path.len;
2521 while ((de = readdir(dir)) != NULL) {
2522 struct stat st;
2523 uint32_t i, found = 0;
2524
2525 strbuf_setlen(&path, dirnamelen);
2526 strbuf_addstr(&path, de->d_name);
2527
2528 if (stat(path.buf, &st) < 0)
2529 continue;
2530
2531 if (st.st_mtime > expire_time)
2532 continue;
2533 if (path.len < 6 || strcmp(path.buf + path.len - 6, ".graph"))
2534 continue;
2535
2536 for (i = 0; i < ctx->num_commit_graphs_after; i++) {
2537 if (!strcmp(ctx->commit_graph_filenames_after[i],
2538 path.buf)) {
2539 found = 1;
2540 break;
2541 }
2542 }
2543
2544 if (!found)
2545 unlink(path.buf);
2546 }
2547
2548out:
2549 if(dir)
2550 closedir(dir);
2551 strbuf_release(&path);
2552}

Callers 1

write_commit_graphFunction · 0.85

Calls 9

strbuf_addstrFunction · 0.85
opendirFunction · 0.85
strbuf_addchFunction · 0.85
readdirFunction · 0.85
strbuf_setlenFunction · 0.85
closedirFunction · 0.85
strbuf_releaseFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected