Skip to content

Commit 94c734a

Browse files
committed
Merge branch 'nd/daemonize-gc' into maint
"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
2 parents cb4575f + 62aad18 commit 94c734a

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

builtin/gc.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static const char * const builtin_gc_usage[] = {
2626
};
2727

2828
static int pack_refs = 1;
29+
static int prune_reflogs = 1;
2930
static int aggressive_depth = 250;
3031
static int aggressive_window = 250;
3132
static int gc_auto_threshold = 6700;
@@ -258,6 +259,19 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
258259
return NULL;
259260
}
260261

262+
static int gc_before_repack(void)
263+
{
264+
if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
265+
return error(FAILED_RUN, pack_refs_cmd.argv[0]);
266+
267+
if (prune_reflogs && run_command_v_opt(reflog.argv, RUN_GIT_CMD))
268+
return error(FAILED_RUN, reflog.argv[0]);
269+
270+
pack_refs = 0;
271+
prune_reflogs = 0;
272+
return 0;
273+
}
274+
261275
int cmd_gc(int argc, const char **argv, const char *prefix)
262276
{
263277
int aggressive = 0;
@@ -320,12 +334,15 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
320334
fprintf(stderr, _("Auto packing the repository for optimum performance.\n"));
321335
fprintf(stderr, _("See \"git help gc\" for manual housekeeping.\n"));
322336
}
323-
if (detach_auto)
337+
if (detach_auto) {
338+
if (gc_before_repack())
339+
return -1;
324340
/*
325341
* failure to daemonize is ok, we'll continue
326342
* in foreground
327343
*/
328344
daemonize();
345+
}
329346
} else
330347
add_repack_all_option();
331348

@@ -337,11 +354,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
337354
name, (uintmax_t)pid);
338355
}
339356

340-
if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD))
341-
return error(FAILED_RUN, pack_refs_cmd.argv[0]);
342-
343-
if (run_command_v_opt(reflog.argv, RUN_GIT_CMD))
344-
return error(FAILED_RUN, reflog.argv[0]);
357+
if (gc_before_repack())
358+
return -1;
345359

346360
if (run_command_v_opt(repack.argv, RUN_GIT_CMD))
347361
return error(FAILED_RUN, repack.argv[0]);

0 commit comments

Comments
 (0)