# [PATCH] Introduce gc.autowarnonly config option

9 messages from 2011-11-05 to 2012-03-09. Participants: Fernando Vezzosi, Sverre Rabbelier, Junio C Hamano, Nguyen Thai Ngoc Duy, Jay Soffian.
Thread: https://gitlist.dev/t/28850

## Fernando Vezzosi, 2011-11-05 10:33

Subject: [PATCH 2/1] gc --auto: warn gc will soon run, give users a chance to run manually
Message-ID: <20111105151225.EE3869004A@inscatolati.net>
URL: https://gitlist.dev/e/20111105151225.EE3869004A%40inscatolati.net
In-Reply-To: <20111105140529.3A6CE9004A@inscatolati.net>

```
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(-)

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

```

## Fernando Vezzosi, 2011-11-05 10:33

Subject: [PATCH 2/1] gc --auto: warn gc will soon run, give users a chance to run manually
Message-ID: <20111105154411.079F69004A@inscatolati.net>
URL: https://gitlist.dev/e/20111105154411.079F69004A%40inscatolati.net
In-Reply-To: <20111105140529.3A6CE9004A@inscatolati.net>

```
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(-)

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

```

## Fernando Vezzosi, 2011-11-05 13:39

Subject: [PATCH] Introduce gc.autowarnonly config option
Message-ID: <20111105140529.3A6CE9004A@inscatolati.net>
URL: https://gitlist.dev/e/20111105140529.3A6CE9004A%40inscatolati.net

```
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(-)

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

```

## Sverre Rabbelier, 2011-11-05 14:22

Subject: Re: [PATCH] Introduce gc.autowarnonly config option
Message-ID: <CAGdFq_jQ_2NueWD5YqXb-nuT6boOw66TJ0+m5mFPqenND2RBsQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAGdFq_jQ_2NueWD5YqXb-nuT6boOw66TJ0%2Bm5mFPqenND2RBsQ%40mail.gmail.com
In-Reply-To: <20111105140529.3A6CE9004A@inscatolati.net>

```
Heya,

On Sat, Nov 5, 2011 at 14: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.
>
> 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

```

## Junio C Hamano, 2011-11-06 00:19

Subject: Re: [PATCH 2/1] gc --auto: warn gc will soon run, give users a chance to run manually
Message-ID: <7vaa8a85ma.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vaa8a85ma.fsf%40alter.siamese.dyndns.org
In-Reply-To: <20111105154411.079F69004A@inscatolati.net>

```
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.

```

## Nguyen Thai Ngoc Duy, 2011-11-06 02:47

Subject: Re: [PATCH 2/1] gc --auto: warn gc will soon run, give users a chance to run manually
Message-ID: <CACsJy8DusGtKYWANPFkn9eAp42oe-2uS5b7Rp2oAaNzfUZAB1A@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8DusGtKYWANPFkn9eAp42oe-2uS5b7Rp2oAaNzfUZAB1A%40mail.gmail.com
In-Reply-To: <20111105151225.EE3869004A@inscatolati.net>

```
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

```

## Jay Soffian, 2011-11-07 00:18

Subject: Re: [PATCH] Introduce gc.autowarnonly config option
Message-ID: <CAG+J_DzNsAP1xAswkNxTAN6ze8ZV5pFqDMeQXKkjCoQgPUgEQQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAG%2BJ_DzNsAP1xAswkNxTAN6ze8ZV5pFqDMeQXKkjCoQgPUgEQQ%40mail.gmail.com
In-Reply-To: <20111105140529.3A6CE9004A@inscatolati.net>

```
On Sat, Nov 5, 2011 at 9:39 AM, 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.
>
> 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, 2012-03-09 19:20

Subject: Re: [PATCH] Introduce gc.autowarnonly config option
Message-ID: <CAGdFq_g=+A7q7_ZkUYG6LZ+ehLBtMY+s+nJxhp4FVhUQ4Zo_rA@mail.gmail.com>
URL: https://gitlist.dev/e/CAGdFq_g%3D%2BA7q7_ZkUYG6LZ%2BehLBtMY%2Bs%2BnJxhp4FVhUQ4Zo_rA%40mail.gmail.com
In-Reply-To: <20111105140529.3A6CE9004A@inscatolati.net>

```
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, 2012-03-09 19:35

Subject: Re: [PATCH] Introduce gc.autowarnonly config option
Message-ID: <7veht15zz8.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7veht15zz8.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CAGdFq_g=+A7q7_ZkUYG6LZ+ehLBtMY+s+nJxhp4FVhUQ4Zo_rA@mail.gmail.com>

```
Sverre Rabbelier <srabbelier@gmail.com> writes:

> 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.

```
