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 5/5] Update "gc" behavior in commit, merge, am and rebase
Date: Wed, 16 May 2012 19:29:37 +0700	[thread overview]
Message-ID: <1337171377-26960-6-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1337171377-26960-1-git-send-email-pclouds@gmail.com>

Commit d4bb43e (Invoke "git gc --auto" from commit, merge, am and
rebase. - 2007-09-05) used the rule to put "gc --auto" is "where
update-ref occurs". I would argue that this is not a good condition to
run gc, because (at least current) gc is slow. We encourage commit
often and rebase to make all patches in good shape and this workflow
should not be slowed down by random "gc".

Instead, we could just inform users that "gc" should be run soon in
commonly used commands (commit, merge, am and rebase). The warning is
shown once every hour to avoid constantly annoy users, or flooding the
output with warnings if a command is run repeatedly (e.g. in scripts).

Commands that are not expected to return immediately, like
receive-pack or index-pack, are more suitable for "gc --auto". These
keep "gc --auto" as before.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/commit.c           |    2 +-
 builtin/gc.c               |    4 +++-
 builtin/gc.h               |    1 +
 builtin/merge.c            |    2 +-
 git-am.sh                  |    2 +-
 git-rebase--interactive.sh |    2 +-
 6 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index bf7d0aa..bfc4b4e 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1590,7 +1590,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		     "new_index file. Check that disk is not full or quota is\n"
 		     "not exceeded, and then \"git reset HEAD\" to recover."));
 
-	gc("commit.autogc", 0);
+	gc("commit.autogc", GC_DRYRUN);
 	rerere(0);
 	run_hook(get_index_file(), "post-commit", NULL);
 	if (amend && !no_post_rewrite) {
diff --git a/builtin/gc.c b/builtin/gc.c
index f82b9ef..bff3d9c 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -182,7 +182,7 @@ static int need_to_gc(void)
 
 int gc(const char *cmd, int flags)
 {
-	const char *av[] = { "gc", "--auto", NULL, NULL };
+	const char *av[] = { "gc", "--auto", NULL, NULL, NULL };
 	int ac = 2;
 
 	git_config(gc_config, (void*)cmd);
@@ -190,6 +190,8 @@ int gc(const char *cmd, int flags)
 	if (!auto_gc || !need_to_gc())
 		return 0;
 
+	if (flags & GC_DRYRUN)
+		av[ac++] = "--dry-run";
 	if (flags & GC_QUIET)
 		av[ac++] = "--quiet";
 	return run_command_v_opt(av, RUN_GIT_CMD);
diff --git a/builtin/gc.h b/builtin/gc.h
index 3482e92..d022944 100644
--- a/builtin/gc.h
+++ b/builtin/gc.h
@@ -2,6 +2,7 @@
 #define GC_H
 
 #define GC_QUIET  1
+#define GC_DRYRUN 2
 
 extern int gc(const char *cmd, int flags);
 
diff --git a/builtin/merge.c b/builtin/merge.c
index 940259d..a0680b0 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -389,7 +389,7 @@ static void finish(struct commit *head_commit,
 			update_ref(reflog_message.buf, "HEAD",
 				new_head, head, 0,
 				DIE_ON_ERR);
-			gc(NULL, 0);
+			gc(NULL, GC_DRYRUN);
 		}
 	}
 	if (new_head && show_diffstat) {
diff --git a/git-am.sh b/git-am.sh
index f8b7a0c..71cd2fd 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -902,4 +902,4 @@ if test -s "$dotest"/rewritten; then
 fi
 
 rm -fr "$dotest"
-git gc --auto
+git gc --auto --dry-run
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 0c19b7c..6c1c054 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -573,7 +573,7 @@ do_next () {
 		true # we don't care if this hook failed
 	fi &&
 	rm -rf "$state_dir" &&
-	git gc --auto &&
+	git gc --auto --dry-run &&
 	warn "Successfully rebased and updated $head_name."
 
 	exit
-- 
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   ` [PATCH v2 4/5] gc: add --dry-run Nguyễn Thái Ngọc Duy
2012-05-16 12:29   ` Nguyễn Thái Ngọc Duy [this message]

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