Merge branch 'nd/daemonize-gc'
Allow running "gc --auto" in the background. * nd/daemonize-gc: gc: config option for running --auto in background daemon: move daemonize() to libgit.a
This commit is contained in:
commit
4c4ac4db2c
@ -1175,6 +1175,10 @@ gc.autopacklimit::
|
|||||||
--auto` consolidates them into one larger pack. The
|
--auto` consolidates them into one larger pack. The
|
||||||
default value is 50. Setting this to 0 disables it.
|
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::
|
gc.packrefs::
|
||||||
Running `git pack-refs` in a repository renders it
|
Running `git pack-refs` in a repository renders it
|
||||||
unclonable by Git versions prior to 1.5.1.2 over dumb
|
unclonable by Git versions prior to 1.5.1.2 over dumb
|
||||||
|
23
builtin/gc.c
23
builtin/gc.c
@ -29,6 +29,7 @@ static int pack_refs = 1;
|
|||||||
static int aggressive_window = 250;
|
static int aggressive_window = 250;
|
||||||
static int gc_auto_threshold = 6700;
|
static int gc_auto_threshold = 6700;
|
||||||
static int gc_auto_pack_limit = 50;
|
static int gc_auto_pack_limit = 50;
|
||||||
|
static int detach_auto = 1;
|
||||||
static const char *prune_expire = "2.weeks.ago";
|
static const char *prune_expire = "2.weeks.ago";
|
||||||
|
|
||||||
static struct argv_array pack_refs_cmd = ARGV_ARRAY_INIT;
|
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);
|
gc_auto_pack_limit = git_config_int(var, value);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (!strcmp(var, "gc.autodetach")) {
|
||||||
|
detach_auto = git_config_bool(var, value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (!strcmp(var, "gc.pruneexpire")) {
|
if (!strcmp(var, "gc.pruneexpire")) {
|
||||||
if (value && strcmp(value, "now")) {
|
if (value && strcmp(value, "now")) {
|
||||||
unsigned long now = approxidate("now");
|
unsigned long now = approxidate("now");
|
||||||
@ -302,11 +307,19 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
|
|||||||
*/
|
*/
|
||||||
if (!need_to_gc())
|
if (!need_to_gc())
|
||||||
return 0;
|
return 0;
|
||||||
if (!quiet)
|
if (!quiet) {
|
||||||
fprintf(stderr,
|
if (detach_auto)
|
||||||
_("Auto packing the repository for optimum performance. You may also\n"
|
fprintf(stderr, _("Auto packing the repository in background for optimum performance.\n"));
|
||||||
"run \"git gc\" manually. See "
|
else
|
||||||
"\"git help gc\" for more information.\n"));
|
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
|
} else
|
||||||
add_repack_all_option();
|
add_repack_all_option();
|
||||||
|
|
||||||
|
1
cache.h
1
cache.h
@ -433,6 +433,7 @@ extern int set_git_dir_init(const char *git_dir, const char *real_git_dir, int);
|
|||||||
extern int init_db(const char *template_dir, unsigned int flags);
|
extern int init_db(const char *template_dir, unsigned int flags);
|
||||||
|
|
||||||
extern void sanitize_stdfds(void);
|
extern void sanitize_stdfds(void);
|
||||||
|
extern int daemonize(void);
|
||||||
|
|
||||||
#define alloc_nr(x) (((x)+16)*3/2)
|
#define alloc_nr(x) (((x)+16)*3/2)
|
||||||
|
|
||||||
|
30
daemon.c
30
daemon.c
@ -1056,11 +1056,6 @@ static void drop_privileges(struct credentials *cred)
|
|||||||
/* nothing */
|
/* nothing */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void daemonize(void)
|
|
||||||
{
|
|
||||||
die("--detach not supported on this platform");
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct credentials *prepare_credentials(const char *user_name,
|
static struct credentials *prepare_credentials(const char *user_name,
|
||||||
const char *group_name)
|
const char *group_name)
|
||||||
{
|
{
|
||||||
@ -1102,24 +1097,6 @@ static struct credentials *prepare_credentials(const char *user_name,
|
|||||||
|
|
||||||
return &c;
|
return &c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void daemonize(void)
|
|
||||||
{
|
|
||||||
switch (fork()) {
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
die_errno("fork failed");
|
|
||||||
default:
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
if (setsid() == -1)
|
|
||||||
die_errno("setsid failed");
|
|
||||||
close(0);
|
|
||||||
close(1);
|
|
||||||
close(2);
|
|
||||||
sanitize_stdfds();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void store_pid(const char *path)
|
static void store_pid(const char *path)
|
||||||
@ -1333,9 +1310,10 @@ int main(int argc, char **argv)
|
|||||||
if (inetd_mode || serve_mode)
|
if (inetd_mode || serve_mode)
|
||||||
return execute();
|
return execute();
|
||||||
|
|
||||||
if (detach)
|
if (detach) {
|
||||||
daemonize();
|
if (daemonize())
|
||||||
else
|
die("--detach not supported on this platform");
|
||||||
|
} else
|
||||||
sanitize_stdfds();
|
sanitize_stdfds();
|
||||||
|
|
||||||
if (pid_file)
|
if (pid_file)
|
||||||
|
24
setup.c
24
setup.c
@ -841,3 +841,27 @@ void sanitize_stdfds(void)
|
|||||||
if (fd > 2)
|
if (fd > 2)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int daemonize(void)
|
||||||
|
{
|
||||||
|
#ifdef NO_POSIX_GOODIES
|
||||||
|
errno = ENOSYS;
|
||||||
|
return -1;
|
||||||
|
#else
|
||||||
|
switch (fork()) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
die_errno("fork failed");
|
||||||
|
default:
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (setsid() == -1)
|
||||||
|
die_errno("setsid failed");
|
||||||
|
close(0);
|
||||||
|
close(1);
|
||||||
|
close(2);
|
||||||
|
sanitize_stdfds();
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -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
|
# Set the child to auto-pack if more than one pack exists
|
||||||
cd child &&
|
cd child &&
|
||||||
git config gc.autopacklimit 1 &&
|
git config gc.autopacklimit 1 &&
|
||||||
|
git config gc.autodetach false &&
|
||||||
git branch test_auto_gc &&
|
git branch test_auto_gc &&
|
||||||
# And create a file that follows the temporary object naming
|
# And create a file that follows the temporary object naming
|
||||||
# convention for the auto-gc to remove
|
# convention for the auto-gc to remove
|
||||||
|
Loading…
Reference in New Issue
Block a user