threads / patch / 28850

patchIntroduce gc.autowarnonly config option

Subject: [PATCH] Introduce gc.autowarnonly config option

## tl;dr

9 messages between Nov 5, 2011 and Mar 9, 2012. Diffs are folded; open one to read it.

replies: 8people: 5as markdown or json

Fernando Vezzosi· Nov 5, 2011, 13:39 UTC · lore

When `git gc --auto` would detect need for garbage collection to run, it would just run. With this patch, enabling gc.autowarnonly will instead make it just emit a warning.

Reviewed-by: Sverre Rabbelier <srabbelier@gmail.com>
Signed-off-by: Fernando Vezzosi <buccia@repnz.net>
---
 builtin/gc.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
Show changes to builtin/gc.c +14 −0
diff --git a/builtin/gc.c b/builtin/gc.c
index 0498094..65b6616 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -26,6 +26,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 gc_auto_warn_only = 0;
 static const char *prune_expire = "2.weeks.ago";
 
 #define MAX_ADD 10
@@ -64,6 +65,10 @@ static int gc_config(const char *var, const char *value, void *cb)
 		}
 		return git_config_string(&prune_expire, var, value);
 	}
+	if (!strcmp(var, "gc.autowarnonly")) {
+		gc_auto_warn_only = git_config_bool(var, value);
+		return 0;
+	}
 	return git_default_config(var, value, cb);
 }
 
@@ -219,6 +224,15 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 		 */
 		if (!need_to_gc())
 			return 0;
+
+		if (gc_auto_warn_only){
+			fprintf(stderr,
+					_("Pack the repository for optimum performance by running\n"
+					"\"git gc\" manually. See "
+					"\"git help gc\" for more information.\n"));
+			return 0;
+		}
+
 		if (quiet)
 			fprintf(stderr, _("Auto packing the repository for optimum performance.\n"));
 		else
-- 
1.7.5.3
Fernando Vezzosi· Nov 5, 2011, 10:33 UTC · re: Fernando Vezzosi · lore

[PATCH 2/1] gc --auto: warn gc will soon run, give users a chance to run manually

Signed-off-by: Fernando Vezzosi <buccia@repnz.net>
---
Rebased Nguyễn's patch on top of mine.
 builtin/gc.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)
Show changes to builtin/gc.c +17 −2
diff --git a/builtin/gc.c b/builtin/gc.c
index 65b6616..ca620e3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -25,8 +25,10 @@ static const char * const builtin_gc_usage[] = {
 static int pack_refs = 1;
 static int aggressive_window = 250;
 static int gc_auto_threshold = 6700;
+static int gc_warn_auto_threshold = 6600;
 static int gc_auto_pack_limit = 50;
 static int gc_auto_warn_only = 0;
+static int gc_warn_auto_pack_limit = 45;
 static const char *prune_expire = "2.weeks.ago";
 
 #define MAX_ADD 10
@@ -51,10 +53,12 @@ static int gc_config(const char *var, const char *value, void *cb)
 	}
 	if (!strcmp(var, "gc.auto")) {
 		gc_auto_threshold = git_config_int(var, value);
+		gc_warn_auto_threshold = gc_auto_threshold - 100;
 		return 0;
 	}
 	if (!strcmp(var, "gc.autopacklimit")) {
 		gc_auto_pack_limit = git_config_int(var, value);
+		gc_warn_auto_pack_limit = gc_auto_pack_limit - 5;
 		return 0;
 	}
 	if (!strcmp(var, "gc.pruneexpire")) {
@@ -123,7 +127,13 @@ static int too_many_loose_objects(void)
 		}
 	}
 	closedir(dir);
-	return needed;
+	if (needed)
+		return 1;
+
+	auto_threshold = (gc_warn_auto_threshold + 255) / 256;
+	if (num_loose > auto_threshold)
+		warning(_("Too many loose objects. \"git gc\" will soon run automatically"));
+	return 0;
 }
 
 static int too_many_packs(void)
@@ -146,7 +156,12 @@ static int too_many_packs(void)
 		 */
 		cnt++;
 	}
-	return gc_auto_pack_limit <= cnt;
+	if (gc_auto_pack_limit <= cnt)
+		return 1;
+
+	if (gc_warn_auto_pack_limit <= cnt)
+		warning(_("Too many packs, \"git gc\" will soon run automatically."));
+	return 0;
 }
 
 static int need_to_gc(void)
-- 
1.7.5.3
Nguyen Thai Ngoc Duy· Nov 6, 2011, 02:47 UTC · re: Fernando Vezzosi · lore

Re: [PATCH 2/1] gc --auto: warn gc will soon run, give users a chance to run manually

On Sat, Nov 5, 2011 at 5:33 PM, Fernando Vezzosi <buccia@repnz.net> wrote:
> Signed-off-by: Fernando Vezzosi <buccia@repnz.net>
> ---
>
> Rebased Nguyễn's patch on top of mine.

I think when gc.autowarnonly is true, my patch should be no-op because you'll get warnings eventually when you hit the thresholds.

-- 
Duy
Fernando Vezzosi· Nov 5, 2011, 10:33 UTC · re: Fernando Vezzosi · lore

[PATCH 2/1] gc --auto: warn gc will soon run, give users a chance to run manually

Signed-off-by: Fernando Vezzosi <buccia@repnz.net>
---
Rebased Nguyễn's patch on top of mine.
 builtin/gc.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)
Show changes to builtin/gc.c +17 −2
diff --git a/builtin/gc.c b/builtin/gc.c
index 65b6616..ca620e3 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -25,8 +25,10 @@ static const char * const builtin_gc_usage[] = {
 static int pack_refs = 1;
 static int aggressive_window = 250;
 static int gc_auto_threshold = 6700;
+static int gc_warn_auto_threshold = 6600;
 static int gc_auto_pack_limit = 50;
 static int gc_auto_warn_only = 0;
+static int gc_warn_auto_pack_limit = 45;
 static const char *prune_expire = "2.weeks.ago";
 
 #define MAX_ADD 10
@@ -51,10 +53,12 @@ static int gc_config(const char *var, const char *value, void *cb)
 	}
 	if (!strcmp(var, "gc.auto")) {
 		gc_auto_threshold = git_config_int(var, value);
+		gc_warn_auto_threshold = gc_auto_threshold - 100;
 		return 0;
 	}
 	if (!strcmp(var, "gc.autopacklimit")) {
 		gc_auto_pack_limit = git_config_int(var, value);
+		gc_warn_auto_pack_limit = gc_auto_pack_limit - 5;
 		return 0;
 	}
 	if (!strcmp(var, "gc.pruneexpire")) {
@@ -123,7 +127,13 @@ static int too_many_loose_objects(void)
 		}
 	}
 	closedir(dir);
-	return needed;
+	if (needed)
+		return 1;
+
+	auto_threshold = (gc_warn_auto_threshold + 255) / 256;
+	if (num_loose > auto_threshold)
+		warning(_("Too many loose objects. \"git gc\" will soon run automatically"));
+	return 0;
 }
 
 static int too_many_packs(void)
@@ -146,7 +156,12 @@ static int too_many_packs(void)
 		 */
 		cnt++;
 	}
-	return gc_auto_pack_limit <= cnt;
+	if (gc_auto_pack_limit <= cnt)
+		return 1;
+
+	if (gc_warn_auto_pack_limit <= cnt)
+		warning(_("Too many packs, \"git gc\" will soon run automatically."));
+	return 0;
 }
 
 static int need_to_gc(void)
-- 
1.7.5.3
Junio C Hamano· Nov 6, 2011, 00:19 UTC · re: Fernando Vezzosi · lore

Re: [PATCH 2/1] gc --auto: warn gc will soon run, give users a chance to run manually

Fernando Vezzosi <buccia@repnz.net> writes:
> Signed-off-by: Fernando Vezzosi <buccia@repnz.net>
> ---
>
> Rebased Nguyễn's patch on top of mine.
You don't have to do this.
Sverre Rabbelier· Nov 5, 2011, 14:22 UTC · re: Fernando Vezzosi · lore

Re: [PATCH] Introduce gc.autowarnonly config option

Heya,
On Sat, Nov 5, 2011 at 14:39, Fernando Vezzosi <buccia@repnz.net> wrote:
Show 6 quoted lines
> When `git gc --auto` would detect need for garbage collection to run, it
> would just run.  With this patch, enabling gc.autowarnonly will instead
> make it just emit a warning.
>
> Reviewed-by: Sverre Rabbelier <srabbelier@gmail.com>
> Signed-off-by: Fernando Vezzosi <buccia@repnz.net>

Highly relevant considering recent (3 hours ago) patch that instead adds a warning that gc will happen soon.

-- 
Cheers,

Sverre Rabbelier
Jay Soffian· Nov 7, 2011, 00:18 UTC · re: Fernando Vezzosi · lore

Re: [PATCH] Introduce gc.autowarnonly config option

On Sat, Nov 5, 2011 at 9:39 AM, Fernando Vezzosi <buccia@repnz.net> wrote:
Show 6 quoted lines
> When `git gc --auto` would detect need for garbage collection to run, it
> would just run.  With this patch, enabling gc.autowarnonly will instead
> make it just emit a warning.
>
> Reviewed-by: Sverre Rabbelier <srabbelier@gmail.com>
> Signed-off-by: Fernando Vezzosi <buccia@repnz.net>

This is much better than the solution I've been living with the last year, which was to put a pre-auto-gc in my templates directory of:

#!/bin/sh echo "time to run git gc" exit 1

So, thank you.
j.
Sverre Rabbelier· Mar 9, 2012, 19:20 UTC · re: Fernando Vezzosi · lore

Re: [PATCH] Introduce gc.autowarnonly config option

On Sat, Nov 5, 2011 at 08:39, Fernando Vezzosi <buccia@repnz.net> wrote:
> When `git gc --auto` would detect need for garbage collection to run, it
> would just run.  With this patch, enabling gc.autowarnonly will instead
> make it just emit a warning.
Does anyone know what happened to this patch?
-- 
Cheers,

Sverre Rabbelier
Junio C Hamano· Mar 9, 2012, 19:35 UTC · re: Sverre Rabbelier · lore

Re: [PATCH] Introduce gc.autowarnonly config option

Sverre Rabbelier <srabbelier@gmail.com> writes:
Show 6 quoted lines
> On Sat, Nov 5, 2011 at 08:39, Fernando Vezzosi <buccia@repnz.net> wrote:
>> When `git gc --auto` would detect need for garbage collection to run, it
>> would just run. With this patch, enabling gc.autowarnonly will instead
>> make it just emit a warning.
>
> Does anyone know what happened to this patch?

If I recall correctly, it was pointed out that people who would get annoyed by unexpected triggering of an auto gc would get annoyed by constant nagging by this warning until they reach the point that they can stop and run gc themselves, and the patch was never updated to take that issue into account.

← back to recent threads