summaryrefslogtreecommitdiff
path: root/builtin/gc.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2012-04-07 06:30:09 -0400
committerJunio C Hamano <gitster@pobox.com>2012-04-11 11:09:49 -0700
commit7e52f5660e542cf801e8fc6902a30cc572c13736 (patch)
tree203e0339a37a81deb5ff7c65e933ae197e91a0d1 /builtin/gc.c
parente8dde3e5f9ddb7cf95a6ff3cea6cf07c3a2db80d (diff)
downloadgit-7e52f5660e542cf801e8fc6902a30cc572c13736.tar.gz
gc: do not explode objects which will be immediately pruned
When we pack everything into one big pack with "git repack -Ad", any unreferenced objects in to-be-deleted packs are exploded into loose objects, with the intent that they will be examined and possibly cleaned up by the next run of "git prune". Since the exploded objects will receive the mtime of the pack from which they come, if the source pack is old, those loose objects will end up pruned immediately. In that case, it is much more efficient to skip the exploding step entirely for these objects. This patch teaches pack-objects to receive the expiration information and avoid writing these objects out. It also teaches "git gc" to pass the value of gc.pruneexpire to repack (which in turn learns to pass it along to pack-objects) so that this optimization happens automatically during "git gc" and "git gc --auto". Signed-off-by: Jeff King <peff@peff.net> Acked-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/gc.c')
-rw-r--r--builtin/gc.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/builtin/gc.c b/builtin/gc.c
index 271376d82b..1bc2fe336e 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -144,6 +144,19 @@ static int too_many_packs(void)
return gc_auto_pack_limit <= cnt;
}
+static void add_repack_all_option(void)
+{
+ if (prune_expire && !strcmp(prune_expire, "now"))
+ append_option(argv_repack, "-a", MAX_ADD);
+ else {
+ append_option(argv_repack, "-A", MAX_ADD);
+ if (prune_expire) {
+ append_option(argv_repack, "--unpack-unreachable", MAX_ADD);
+ append_option(argv_repack, prune_expire, MAX_ADD);
+ }
+ }
+}
+
static int need_to_gc(void)
{
/*
@@ -160,10 +173,7 @@ static int need_to_gc(void)
* there is no need.
*/
if (too_many_packs())
- append_option(argv_repack,
- prune_expire && !strcmp(prune_expire, "now") ?
- "-a" : "-A",
- MAX_ADD);
+ add_repack_all_option();
else if (!too_many_loose_objects())
return 0;
@@ -227,10 +237,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
"run \"git gc\" manually. See "
"\"git help gc\" for more information.\n"));
} else
- append_option(argv_repack,
- prune_expire && !strcmp(prune_expire, "now")
- ? "-a" : "-A",
- MAX_ADD);
+ add_repack_all_option();
if (pack_refs && run_command_v_opt(argv_pack_refs, RUN_GIT_CMD))
return error(FAILED_RUN, argv_pack_refs[0]);