summaryrefslogtreecommitdiff
path: root/commit-graph.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2019-06-18 18:14:31 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-06-20 03:46:26 (GMT)
commit8d84097f9655a954ea7e94ba08d93e5940ccb2ae (patch)
treea03d339c93622614583625570967a94365add6b7 /commit-graph.c
parentc523035cbd8515d095dc15e9661fd896733bedbc (diff)
downloadgit-8d84097f9655a954ea7e94ba08d93e5940ccb2ae.zip
git-8d84097f9655a954ea7e94ba08d93e5940ccb2ae.tar.gz
git-8d84097f9655a954ea7e94ba08d93e5940ccb2ae.tar.bz2
commit-graph: expire commit-graph files
As we merge commit-graph files in a commit-graph chain, we should clean up the files that are no longer used. This change introduces an 'expiry_window' value to the context, which is always zero (for now). We then check the modified time of each graph-{hash}.graph file in the $OBJDIR/info/commit-graphs folder and unlink the files that are older than the expiry_window. Since this is always zero, this immediately clears all unused graph files. We will update the value to match a config setting in a future change. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/commit-graph.c b/commit-graph.c
index fba705b..0cc2ceb 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1652,6 +1652,70 @@ static void merge_commit_graphs(struct write_commit_graph_context *ctx)
sort_and_scan_merged_commits(ctx);
}
+static void mark_commit_graphs(struct write_commit_graph_context *ctx)
+{
+ uint32_t i;
+ time_t now = time(NULL);
+
+ for (i = ctx->num_commit_graphs_after - 1; i < ctx->num_commit_graphs_before; i++) {
+ struct stat st;
+ struct utimbuf updated_time;
+
+ stat(ctx->commit_graph_filenames_before[i], &st);
+
+ updated_time.actime = st.st_atime;
+ updated_time.modtime = now;
+ utime(ctx->commit_graph_filenames_before[i], &updated_time);
+ }
+}
+
+static void expire_commit_graphs(struct write_commit_graph_context *ctx)
+{
+ struct strbuf path = STRBUF_INIT;
+ DIR *dir;
+ struct dirent *de;
+ size_t dirnamelen;
+ time_t expire_time = time(NULL);
+
+ strbuf_addstr(&path, ctx->obj_dir);
+ strbuf_addstr(&path, "/info/commit-graphs");
+ dir = opendir(path.buf);
+
+ if (!dir) {
+ strbuf_release(&path);
+ return;
+ }
+
+ strbuf_addch(&path, '/');
+ dirnamelen = path.len;
+ while ((de = readdir(dir)) != NULL) {
+ struct stat st;
+ uint32_t i, found = 0;
+
+ strbuf_setlen(&path, dirnamelen);
+ strbuf_addstr(&path, de->d_name);
+
+ stat(path.buf, &st);
+
+ if (st.st_mtime > expire_time)
+ continue;
+ if (path.len < 6 || strcmp(path.buf + path.len - 6, ".graph"))
+ continue;
+
+ for (i = 0; i < ctx->num_commit_graphs_after; i++) {
+ if (!strcmp(ctx->commit_graph_filenames_after[i],
+ path.buf)) {
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found)
+ unlink(path.buf);
+
+ }
+}
+
int write_commit_graph(const char *obj_dir,
struct string_list *pack_indexes,
struct string_list *commit_hex,
@@ -1764,6 +1828,11 @@ int write_commit_graph(const char *obj_dir,
res = write_commit_graph_file(ctx);
+ if (ctx->split) {
+ mark_commit_graphs(ctx);
+ expire_commit_graphs(ctx);
+ }
+
cleanup:
free(ctx->graph_name);
free(ctx->commits.list);