From: Nguyễn Thái Ngọc Duy Date: Sun, 21 Mar 2010 10:30:45 GMT Subject: [PATCH v2 18/19] alias: keep repository found while collecting aliases as long as possible Message-ID: <1269167446-7799-19-git-send-email-pclouds@gmail.com> In-Reply-To: <1269167446-7799-1-git-send-email-pclouds@gmail.com> Given that about 80% builtin commands will need to search for a repository, we should keep the repository found in alias handling code. Until we are clear there's no need for a repository, then we can undo the setup with unset_git_directory(). Signed-off-by: Nguyễn Thái Ngọc Duy --- git.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/git.c b/git.c index db5bd95..88aaf13 100644 --- a/git.c +++ b/git.c @@ -152,7 +152,8 @@ static int handle_alias(int *argcp, const char ***argv) char *alias_string; int unused_nongit; - setup_git_directory_gently(&unused_nongit); + if (!startup_info->have_repository) + setup_git_directory_gently(&unused_nongit); alias_command = (*argv)[0]; alias_string = alias_lookup(alias_command); @@ -209,8 +210,6 @@ static int handle_alias(int *argcp, const char ***argv) ret = 1; } - unset_git_directory(startup_info->prefix); - errno = saved_errno; return ret; @@ -240,12 +239,18 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) startup_info->help = argc == 2 && !strcmp(argv[1], "-h"); if (!startup_info->help) { - if (p->option & RUN_SETUP) + if ((p->option & RUN_SETUP) && !startup_info->have_repository) setup_git_directory(); - if (p->option & RUN_SETUP_GENTLY) { + else if ((p->option & RUN_SETUP_GENTLY) && !startup_info->have_repository) { int nongit_ok; setup_git_directory_gently(&nongit_ok); } + else if (startup_info->have_repository) { + if (p->option & (RUN_SETUP_GENTLY | RUN_SETUP)) + ; /* done already */ + else + unset_git_directory(startup_info->prefix); + } if (use_pager == -1 && p->option & RUN_SETUP) use_pager = check_pager_config(p->cmd); -- 1.7.0.2.425.gb99f1