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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 I hate it every single time git hangs because gc is activated.
 Opening another terminal is an option but I would lose all terminal
 settings I have on the current one (e.g. access to suspended vim
 sessions).

 I don't think gc_warn_* need their own config vars. Hopefully
 hardcoded offset is good enough.

 builtin/gc.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index 0498094..1f4555e 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -25,7 +25,9 @@ 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_warn_auto_pack_limit = 45;
 static const char *prune_expire = "2.weeks.ago";
 
 #define MAX_ADD 10
@@ -50,10 +52,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")) {
@@ -118,7 +122,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)
@@ -141,7 +151,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.4.74.g639db

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]