git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Sverre Rabbelier" <srabbelier@gmail.com>,
	"Jeff King" <peff@peff.net>, "Nicolas Pitre" <nico@fluxnic.net>,
	"Fernando Vezzosi" <buccia@repnz.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 4/5] gc: add --dry-run
Date: Wed, 16 May 2012 19:29:36 +0700	[thread overview]
Message-ID: <1337171377-26960-5-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1337171377-26960-1-git-send-email-pclouds@gmail.com>

"git gc --auto --dry-run" will print instead of doing
housekeeping. This option is to be called by other commands rather
than by user and will not print more than one warning every hour. gc()
function also behaves this way.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-gc.txt |    7 ++++++-
 builtin/gc.c             |   19 +++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/Documentation/git-gc.txt b/Documentation/git-gc.txt
index b370b02..f69f5e1 100644
--- a/Documentation/git-gc.txt
+++ b/Documentation/git-gc.txt
@@ -9,7 +9,7 @@ git-gc - Cleanup unnecessary files and optimize the local repository
 SYNOPSIS
 --------
 [verse]
-'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune]
+'git gc' [--aggressive] [--auto [--dry-run]] [--quiet] [--prune=<date> | --no-prune]
 
 DESCRIPTION
 -----------
@@ -60,6 +60,11 @@ are consolidated into a single pack by using the `-A` option of
 'git repack'. Setting `gc.autopacklimit` to 0 disables
 automatic consolidation of packs.
 
+--dry-run::
+	Only show warning if housekeeping is required. The warning
+	is only shown at most once every hour even if
+	"gc --auto --dry-run" is run continuously.
+
 --prune=<date>::
 	Prune loose objects older than date (default is 2 weeks ago,
 	overridable by the config variable `gc.pruneExpire`).  This
diff --git a/builtin/gc.c b/builtin/gc.c
index ce60225..f82b9ef 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -150,6 +150,8 @@ static void add_repack_all_option(void)
 
 static int need_to_gc(void)
 {
+	struct stat st;
+
 	/*
 	 * Setting gc.auto to 0 or negative can disable the
 	 * automatic gc.
@@ -168,6 +170,13 @@ static int need_to_gc(void)
 	else if (!too_many_loose_objects())
 		return 0;
 
+	if (stat(git_path("gc_needed"), &st))
+		open(git_path("gc_needed"), O_CREAT | O_RDWR, 0644);
+	else if (time(NULL) - st.st_mtime < 3600)
+		return 0;
+	else
+		utime(git_path("gc_needed"), NULL);
+
 	return 1;
 }
 
@@ -190,6 +199,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 {
 	int aggressive = 0;
 	int auto_gc = 0;
+	int check_gc = 0;
 	int quiet = 0;
 
 	struct option builtin_gc_options[] = {
@@ -199,12 +209,16 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 			PARSE_OPT_OPTARG, NULL, (intptr_t)prune_expire },
 		OPT_BOOLEAN(0, "aggressive", &aggressive, "be more thorough (increased runtime)"),
 		OPT_BOOLEAN(0, "auto", &auto_gc, "enable auto-gc mode"),
+		OPT_BOOLEAN(0, "dry-run", &check_gc, "warn if auto gc is needed"),
 		OPT_END()
 	};
 
 	if (argc == 2 && !strcmp(argv[1], "-h"))
 		usage_with_options(builtin_gc_usage, builtin_gc_options);
 
+	if (!auto_gc && check_gc)
+		die(_("--dry-run is useless without --auto"));
+
 	argv_array_pushl(&pack_refs_cmd, "pack-refs", "--all", "--prune", NULL);
 	argv_array_pushl(&reflog, "reflog", "expire", "--all", NULL);
 	argv_array_pushl(&repack, "repack", "-d", "-l", NULL);
@@ -240,6 +254,11 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
 		if (run_hook(NULL, "pre-auto-gc", NULL))
 			return 0;
 
+		if (check_gc) {
+			warning(_("This repository needs maintenance. "
+				  "Please run \"git gc\" as soon as possible."));
+			return 0;
+		}
 		if (quiet)
 			fprintf(stderr, _("Auto packing the repository for optimum performance.\n"));
 		else
-- 
1.7.8.36.g69ee2

  parent reply	other threads:[~2012-05-16 12:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-12  8:08 [PATCH] Update "gc" behavior in commit, merge, am, rebase and index-pack Nguyễn Thái Ngọc Duy
2012-05-12  8:18 ` Nguyen Thai Ngoc Duy
2012-05-12 17:36 ` Nicolas Pitre
2012-05-14  9:09   ` Nguyen Thai Ngoc Duy
2012-05-14 15:18     ` Sverre Rabbelier
2012-05-15 11:25       ` Nguyen Thai Ngoc Duy
2012-05-14 20:11   ` Jeff King
2012-05-14 20:50 ` Jeff King
2012-05-14 23:35   ` Junio C Hamano
2012-05-16 12:29 ` [PATCH v2 0/5] "git gc --auto" update Nguyễn Thái Ngọc Duy
2012-05-16 12:29   ` [PATCH v2 1/5] Add convenient function to do automatic garbage collection Nguyễn Thái Ngọc Duy
2012-05-18 22:37     ` Junio C Hamano
2012-05-19  4:56       ` Nguyen Thai Ngoc Duy
2012-05-16 12:29   ` [PATCH v2 2/5] index-pack: perform automatic gc, share receive.gc config with receive-pack Nguyễn Thái Ngọc Duy
2012-05-16 12:29   ` [PATCH v2 3/5] commit: reinstate "gc --auto" Nguyễn Thái Ngọc Duy
2012-05-16 12:29   ` Nguyễn Thái Ngọc Duy [this message]
2012-05-16 12:29   ` [PATCH v2 5/5] Update "gc" behavior in commit, merge, am and rebase Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1337171377-26960-5-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=buccia@repnz.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=nico@fluxnic.net \
    --cc=peff@peff.net \
    --cc=srabbelier@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).