gc: config option for running --auto in background
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 8 Feb 2014 07:08:52 +0000 (14:08 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Feb 2014 18:46:37 +0000 (10:46 -0800)
`gc --auto` takes time and can block the user temporarily (but not any
less annoyingly). Make it run in background on systems that support
it. The only thing lost with running in background is printouts. But
gc output is not really interesting. You can keep it in foreground by
changing gc.autodetach.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
builtin/gc.c
t/t5400-send-pack.sh
index 5f4d7939ed1ec267e7f282624e5bb480e72d7a33..4781773e6a80fbbd62a5eb562b959e1a7d296cb2 100644 (file)
@@ -1167,6 +1167,10 @@ gc.autopacklimit::
        --auto` consolidates them into one larger pack.  The
        default value is 50.  Setting this to 0 disables it.
 
+gc.autodetach::
+       Make `git gc --auto` return immediately andrun in background
+       if the system supports it. Default is true.
+
 gc.packrefs::
        Running `git pack-refs` in a repository renders it
        unclonable by Git versions prior to 1.5.1.2 over dumb
index c19545d49e217400ee1736183c870557b9c9d54b..ed5cc3c0318f87abd8674f7b98936a2265fff577 100644 (file)
@@ -29,6 +29,7 @@ static int pack_refs = 1;
 static int aggressive_window = 250;
 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 struct argv_array pack_refs_cmd = ARGV_ARRAY_INIT;
@@ -73,6 +74,10 @@ static int gc_config(const char *var, const char *value, void *cb)
                gc_auto_pack_limit = git_config_int(var, value);
                return 0;
        }
+       if (!strcmp(var, "gc.autodetach")) {
+               detach_auto = git_config_bool(var, value);
+               return 0;
+       }
        if (!strcmp(var, "gc.pruneexpire")) {
                if (value && strcmp(value, "now")) {
                        unsigned long now = approxidate("now");
@@ -301,11 +306,19 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
                 */
                if (!need_to_gc())
                        return 0;
-               if (!quiet)
-                       fprintf(stderr,
-                                       _("Auto packing the repository for optimum performance. You may also\n"
-                                       "run \"git gc\" manually. See "
-                                       "\"git help gc\" for more information.\n"));
+               if (!quiet) {
+                       if (detach_auto)
+                               fprintf(stderr, _("Auto packing the repository in background for optimum performance.\n"));
+                       else
+                               fprintf(stderr, _("Auto packing the repository for optimum performance.\n"));
+                       fprintf(stderr, _("See \"git help gc\" for manual housekeeping.\n"));
+               }
+               if (detach_auto)
+                       /*
+                        * failure to daemonize is ok, we'll continue
+                        * in foreground
+                        */
+                       daemonize();
        } else
                add_repack_all_option();
 
index 129fc88bd28e8ea85e81310aec860df808949447..0736bcbcd52a76ef3400c046e7d3558dd1a866c7 100755 (executable)
@@ -164,6 +164,7 @@ test_expect_success 'receive-pack runs auto-gc in remote repo' '
            # Set the child to auto-pack if more than one pack exists
            cd child &&
            git config gc.autopacklimit 1 &&
+           git config gc.autodetach false &&
            git branch test_auto_gc &&
            # And create a file that follows the temporary object naming
            # convention for the auto-gc to remove