[PATCH 7/9] builtin: Support RUN_SETUP_GENTLY to set up repository early if found

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jonathan Nieder
Date: Monday, April 12, 2010 - 7:29 pm

From: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>

Attempts to access gitdir are everywhere, even before cmd_*() is
called (examples: alias handling, pager configuration, work tree).
Because the repository has not been found, repository-specific
information (i.e., $GIT_DIR/config) can not be read.  This leads to
obscure bugs.

So the sooner we setup gitdir, the less trouble we may have to deal with.

This patch sets up the infrastructure.  Later patches will teach
particular commands to use it where applicable.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 git.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/git.c b/git.c
index b1d51c9..20e9bfc 100644
--- a/git.c
+++ b/git.c
@@ -220,13 +220,14 @@ static int handle_alias(int *argcp, const char ***argv)
 
 const char git_version_string[] = GIT_VERSION;
 
-#define RUN_SETUP	(1<<0)
-#define USE_PAGER	(1<<1)
+#define RUN_SETUP		(1<<0)
+#define USE_PAGER		(1<<1)
 /*
  * require working tree to be present -- anything uses this needs
  * RUN_SETUP for reading from the configuration file.
  */
-#define NEED_WORK_TREE	(1<<2)
+#define NEED_WORK_TREE		(1<<2)
+#define RUN_SETUP_GENTLY	(1<<3)
 
 struct cmd_struct {
 	const char *cmd;
@@ -245,6 +246,10 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
 	if (!help) {
 		if (p->option & RUN_SETUP)
 			prefix = setup_git_directory();
+		if (p->option & RUN_SETUP_GENTLY) {
+			int nongit_ok;
+			prefix = setup_git_directory_gently(&nongit_ok);
+		}
 
 		if (use_pager == -1 && p->option & RUN_SETUP)
 			use_pager = check_pager_config(p->cmd);
-- 
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH/RFC 0/9] Setup cleanup, chapter one, Jonathan Nieder, (Mon Apr 12, 7:11 pm)
[PATCH 3/9] builtins: do not commit pager choice early, Jonathan Nieder, (Mon Apr 12, 7:24 pm)
[PATCH 4/9] t7006: test pager.&lt;cmd&gt; configuration, Jonathan Nieder, (Mon Apr 12, 7:25 pm)
[PATCH 5/9] builtin: introduce startup_info struct, Jonathan Nieder, (Mon Apr 12, 7:27 pm)
[PATCH 6/9] builtin: remember whether repository was found, Jonathan Nieder, (Mon Apr 12, 7:28 pm)
[PATCH 7/9] builtin: Support RUN_SETUP_GENTLY to set up re ..., Jonathan Nieder, (Mon Apr 12, 7:29 pm)
[PATCH 9/9] config: run setup before commiting pager choice, Jonathan Nieder, (Mon Apr 12, 7:31 pm)
Re: [PATCH 8/9] builtin: check pager.&lt;cmd&gt; configuration i ..., Nguyen Thai Ngoc Duy, (Mon Apr 12, 10:29 pm)
[PATCH 3/9 v2] builtins: do not commit pager choice early, Jonathan Nieder, (Tue Apr 13, 7:17 pm)
[PATCH 4/9 v2] t7006: test pager.&lt;cmd&gt; configuration, Jonathan Nieder, (Tue Apr 13, 7:19 pm)
Re: [RFC/PATCH 00/46] nd/setup remainder for convenient re ..., Nguyen Thai Ngoc Duy, (Wed Apr 14, 12:59 am)
Re: [PATCH/RFC 0/9] Setup cleanup, chapter one, Junio C Hamano, (Wed Apr 14, 1:54 pm)
Re: [PATCH/RFC 0/9] Setup cleanup, chapter one, Jonathan Nieder, (Wed Apr 14, 5:05 pm)
[PATCH] t7006: guard cleanup with test_expect_success, Jonathan Nieder, (Wed Apr 14, 5:38 pm)
Re: [PATCH] t7006: guard cleanup with test_expect_success, Junio C Hamano, (Wed Apr 14, 5:56 pm)
Re: [PATCH] t7006: guard cleanup with test_expect_success, Jonathan Nieder, (Wed Apr 14, 6:27 pm)
Re: [PATCH 8/9] builtin: check pager.&lt;cmd&gt; configuration i ..., Nguyen Thai Ngoc Duy, (Thu Apr 15, 10:43 am)