summaryrefslogtreecommitdiff
path: root/builtin/gc.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2019-03-15 15:59:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-03-18 06:09:40 (GMT)
commitcd8eb3a094c51482c80a97589e4aff53af2c7c63 (patch)
treeed57f97b5a94f24af63ddaadaff914eea9aa105a /builtin/gc.c
parente5cdbd5f7048d5dc9d84a7d1f2c467f0ebf4ac0b (diff)
downloadgit-cd8eb3a094c51482c80a97589e4aff53af2c7c63.zip
git-cd8eb3a094c51482c80a97589e4aff53af2c7c63.tar.gz
git-cd8eb3a094c51482c80a97589e4aff53af2c7c63.tar.bz2
gc: refactor a "call me once" pattern
Change an idiom we're using to ensure that gc_before_repack() only does work once (see 62aad1849f ("gc --auto: do not lock refs in the background", 2014-05-25)) to be more obvious. Nothing except this function cares about the "pack_refs" and "prune_reflogs" variables, so let's not leave the reader wondering if they're being zero'd out for later use somewhere else. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/gc.c')
-rw-r--r--builtin/gc.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index 733bd7b..ae716a0 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -489,14 +489,20 @@ done:
static void gc_before_repack(void)
{
+ /*
+ * We may be called twice, as both the pre- and
+ * post-daemonized phases will call us, but running these
+ * commands more than once is pointless and wasteful.
+ */
+ static int done = 0;
+ if (done++)
+ return;
+
if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
die(FAILED_RUN, pack_refs_cmd.argv[0]);
if (prune_reflogs && run_command_v_opt(reflog.argv, RUN_GIT_CMD))
die(FAILED_RUN, reflog.argv[0]);
-
- pack_refs = 0;
- prune_reflogs = 0;
}
int cmd_gc(int argc, const char **argv, const char *prefix)