Commit 33f6f8e7 authored by Duy Nguyen's avatar Duy Nguyen

gc: prune backup logs

parent 22d5252e
......@@ -4,6 +4,7 @@
#include "lockfile.h"
#include "object-store.h"
#include "strbuf.h"
#include "worktree.h"
void bkl_append(struct strbuf *output, const char *path,
const struct object_id *from,
......@@ -296,3 +297,35 @@ int bkl_prune(struct repository *r, const char *path, timestamp_t expire)
strbuf_release(&opts.copy);
return ret;
}
void bkl_prune_all_or_die(struct repository *r, timestamp_t expire)
{
struct worktree **worktrees, **p;
char *bkl_path;
bkl_path = repo_git_path(r, "common/gitdir.bkl");
if (bkl_prune(r, bkl_path, expire))
die(_("failed to prune %s"), "gitdir.bkl");
free(bkl_path);
worktrees = get_worktrees(0);
for (p = worktrees; *p; p++) {
struct worktree *wt = *p;
if (bkl_prune(r, worktree_git_path(wt, "index.bkl"), expire)) {
if (wt->id)
die(_("failed to prune %s on working tree '%s'"),
"index.bkl", wt->id);
else
die(_("failed to prune %s"), "index.bkl");
}
if (bkl_prune(r, worktree_git_path(wt, "worktree.bkl"), expire)) {
if (wt->id)
die(_("failed to prune %s on working tree '%s'"),
"worktree.bkl", wt->id);
else
die(_("failed to prune %s"), "worktree.bkl");
}
}
free_worktrees(worktrees);
}
......@@ -31,5 +31,6 @@ int bkl_parse_file(const char *path,
void *data);
int bkl_prune(struct repository *r, const char *id, timestamp_t expire);
void bkl_prune_all_or_die(struct repository *r, timestamp_t expire);
#endif
......@@ -27,6 +27,7 @@
#include "pack-objects.h"
#include "blob.h"
#include "tree.h"
#include "backup-log.h"
#define FAILED_RUN "failed to run %s"
......@@ -657,6 +658,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
if (run_command_v_opt(rerere.argv, RUN_GIT_CMD))
die(FAILED_RUN, rerere.argv[0]);
bkl_prune_all_or_die(the_repository, time(NULL) - 90 * 24 * 3600);
report_garbage = report_pack_garbage;
reprepare_packed_git(the_repository);
if (pack_garbage.nr > 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment