summaryrefslogtreecommitdiff
path: root/builtin/gc.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-06-16 19:18:12 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-06-16 19:18:12 (GMT)
commit1a81f6ceea7795e2b78cebd356d276afe79e7626 (patch)
treeddfea01623a2666de91d4175b5025d18a58cbf3b /builtin/gc.c
parent8dbd3133942fb8a91c6309f1ec73d1c41a44a7be (diff)
parent62aad1849f3009d1e6c7126a321e5515c1543dc3 (diff)
downloadgit-1a81f6ceea7795e2b78cebd356d276afe79e7626.zip
git-1a81f6ceea7795e2b78cebd356d276afe79e7626.tar.gz
git-1a81f6ceea7795e2b78cebd356d276afe79e7626.tar.bz2
Merge branch 'nd/daemonize-gc'
"git gc --auto" was recently changed to run in the background to give control back early to the end-user sitting in front of the terminal, but it forgot that housekeeping involving reflogs should be done without other processes competing for accesses to the refs. * nd/daemonize-gc: gc --auto: do not lock refs in the background
Diffstat (limited to 'builtin/gc.c')
-rw-r--r--builtin/gc.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index 85f5c2b..8d219d8 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -26,6 +26,7 @@ static const char * const builtin_gc_usage[] = {
};
static int pack_refs = 1;
+static int prune_reflogs = 1;
static int aggressive_depth = 250;
static int aggressive_window = 250;
static int gc_auto_threshold = 6700;
@@ -258,6 +259,19 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
return NULL;
}
+static int gc_before_repack(void)
+{
+ if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
+ return error(FAILED_RUN, pack_refs_cmd.argv[0]);
+
+ if (prune_reflogs && run_command_v_opt(reflog.argv, RUN_GIT_CMD))
+ return error(FAILED_RUN, reflog.argv[0]);
+
+ pack_refs = 0;
+ prune_reflogs = 0;
+ return 0;
+}
+
int cmd_gc(int argc, const char **argv, const char *prefix)
{
int aggressive = 0;
@@ -320,12 +334,15 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
fprintf(stderr, _("Auto packing the repository for optimum performance.\n"));
fprintf(stderr, _("See \"git help gc\" for manual housekeeping.\n"));
}
- if (detach_auto)
+ if (detach_auto) {
+ if (gc_before_repack())
+ return -1;
/*
* failure to daemonize is ok, we'll continue
* in foreground
*/
daemonize();
+ }
} else
add_repack_all_option();
@@ -337,11 +354,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
name, (uintmax_t)pid);
}
- if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
- return error(FAILED_RUN, pack_refs_cmd.argv[0]);
-
- if (run_command_v_opt(reflog.argv, RUN_GIT_CMD))
- return error(FAILED_RUN, reflog.argv[0]);
+ if (gc_before_repack())
+ return -1;
if (run_command_v_opt(repack.argv, RUN_GIT_CMD))
return error(FAILED_RUN, repack.argv[0]);