commit: don't rewrite shared index unnecessarily
[gitweb.git] / builtin / gc.c
index 5c634afc0022c0ea7a8cd8c81727935ad79a6333..4957c3903293c2d4262f49c01188973bd3e53aa2 100644 (file)
@@ -33,11 +33,13 @@ static int gc_auto_threshold = 6700;
 static int gc_auto_pack_limit = 50;
 static int detach_auto = 1;
 static const char *prune_expire = "2.weeks.ago";
+static const char *prune_worktrees_expire = "3.months.ago";
 
 static struct argv_array pack_refs_cmd = ARGV_ARRAY_INIT;
 static struct argv_array reflog = ARGV_ARRAY_INIT;
 static struct argv_array repack = ARGV_ARRAY_INIT;
 static struct argv_array prune = ARGV_ARRAY_INIT;
+static struct argv_array prune_worktrees = ARGV_ARRAY_INIT;
 static struct argv_array rerere = ARGV_ARRAY_INIT;
 
 static char *pidfile;
@@ -55,6 +57,17 @@ static void remove_pidfile_on_signal(int signo)
        raise(signo);
 }
 
+static void git_config_date_string(const char *key, const char **output)
+{
+       if (git_config_get_string_const(key, output))
+               return;
+       if (strcmp(*output, "now")) {
+               unsigned long now = approxidate("now");
+               if (approxidate(*output) >= now)
+                       git_die_config(key, _("Invalid %s: '%s'"), key, *output);
+       }
+}
+
 static void gc_config(void)
 {
        const char *value;
@@ -71,16 +84,8 @@ static void gc_config(void)
        git_config_get_int("gc.auto", &gc_auto_threshold);
        git_config_get_int("gc.autopacklimit", &gc_auto_pack_limit);
        git_config_get_bool("gc.autodetach", &detach_auto);
-
-       if (!git_config_get_string_const("gc.pruneexpire", &prune_expire)) {
-               if (strcmp(prune_expire, "now")) {
-                       unsigned long now = approxidate("now");
-                       if (approxidate(prune_expire) >= now) {
-                               git_die_config("gc.pruneexpire", _("Invalid gc.pruneexpire: '%s'"),
-                                               prune_expire);
-                       }
-               }
-       }
+       git_config_date_string("gc.pruneexpire", &prune_expire);
+       git_config_date_string("gc.pruneworktreesexpire", &prune_worktrees_expire);
        git_config(git_default_config, NULL);
 }
 
@@ -287,7 +292,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
        argv_array_pushl(&pack_refs_cmd, "pack-refs", "--all", "--prune", NULL);
        argv_array_pushl(&reflog, "reflog", "expire", "--all", NULL);
        argv_array_pushl(&repack, "repack", "-d", "-l", NULL);
-       argv_array_pushl(&prune, "prune", "--expire", NULL );
+       argv_array_pushl(&prune, "prune", "--expire", NULL);
+       argv_array_pushl(&prune_worktrees, "worktree", "prune", "--expire", NULL);
        argv_array_pushl(&rerere, "rerere", "gc", NULL);
 
        gc_config();
@@ -357,6 +363,12 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
                        return error(FAILED_RUN, prune.argv[0]);
        }
 
+       if (prune_worktrees_expire) {
+               argv_array_push(&prune_worktrees, prune_worktrees_expire);
+               if (run_command_v_opt(prune_worktrees.argv, RUN_GIT_CMD))
+                       return error(FAILED_RUN, prune_worktrees.argv[0]);
+       }
+
        if (run_command_v_opt(rerere.argv, RUN_GIT_CMD))
                return error(FAILED_RUN, rerere.argv[0]);