@matheusbsbs / matheus-bagliano / commits / edb0e04e81
Fork 0

git-gc: by default use safer "-A" option to repack when not --prune'ing

This makes use of repack's new "-A" option which does not drop packed unreachable objects. This makes git-gc safe to call at any time, particularly when a repository is referenced as an alternate by another repository. git-gc --prune will use the "-a" option to repack instead of "-A", so that packed unreachable objects will be removed. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Brandon Casey committed Oct 10, 2007 at 19:59 UTC edb0e04e819c7cde709d10e03f398d12692259f7
1 file changed +11 -1
builtin-gc.c
+11 -1
@@ -26,7 +26,7 @@ static int gc_auto_pack_limit = 20;
26 #define MAX_ADD 10
27 static const char *argv_pack_refs[] = {"pack-refs", "--all", "--prune", NULL};
28 static const char *argv_reflog[] = {"reflog", "expire", "--all", NULL};
29 -static const char *argv_repack[MAX_ADD] = {"repack", "-a", "-d", "-l", NULL};
29 +static const char *argv_repack[MAX_ADD] = {"repack", "-d", "-l", NULL};
30 static const char *argv_prune[] = {"prune", NULL};
31 static const char *argv_rerere[] = {"rerere", "gc", NULL};
32
@@ -211,6 +211,16 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
211 prune = 0;
212 if (!need_to_gc())
213 return 0;
214 + } else {
215 + /*
216 + * Use safer (for shared repos) "-A" option to
217 + * repack when not pruning. Auto-gc makes its
218 + * own decision.
219 + */
220 + if (prune)
221 + append_option(argv_repack, "-a", MAX_ADD);
222 + else
223 + append_option(argv_repack, "-A", MAX_ADD);
224 }
225
226 if (pack_refs && run_command_v_opt(argv_pack_refs, RUN_GIT_CMD))