Skip to content

Commit ee38dfb

Browse files
pcloudsgitster
authored andcommitted
git wrapper: allow setup_git_directory_gently() be called earlier
In the spirit of v1.4.2-rc3~34^2^2 (Call setup_git_directory() much earlier, 2006-07-28), let run_builtin() take care of searching for a repository for built-ins that want to make use of one if present. So now you can mark your command with RUN_SETUP_GENTLY and use nongit = !startup_info->have_repository; in place of prefix = setup_git_directory_gently(&nongit); and everything will be the same, except the repository is discovered a little sooner. As v1.7.2~16^2 (2010-07-14) explains, this should allow more commands to robustly use features like "git --paginate" that look at local configuration before the command is actually run. This patch sets up the infrastructure. Later patches will teach particular commands to use it. 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a60645f commit ee38dfb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

git.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,14 @@ static int handle_alias(int *argcp, const char ***argv)
230230

231231
const char git_version_string[] = GIT_VERSION;
232232

233-
#define RUN_SETUP (1<<0)
234-
#define USE_PAGER (1<<1)
233+
#define RUN_SETUP (1<<0)
234+
#define RUN_SETUP_GENTLY (1<<1)
235+
#define USE_PAGER (1<<2)
235236
/*
236237
* require working tree to be present -- anything uses this needs
237238
* RUN_SETUP for reading from the configuration file.
238239
*/
239-
#define NEED_WORK_TREE (1<<2)
240+
#define NEED_WORK_TREE (1<<3)
240241

241242
struct cmd_struct {
242243
const char *cmd;
@@ -255,8 +256,12 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
255256
if (!help) {
256257
if (p->option & RUN_SETUP)
257258
prefix = setup_git_directory();
259+
if (p->option & RUN_SETUP_GENTLY) {
260+
int nongit_ok;
261+
prefix = setup_git_directory_gently(&nongit_ok);
262+
}
258263

259-
if (use_pager == -1 && p->option & RUN_SETUP)
264+
if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY))
260265
use_pager = check_pager_config(p->cmd);
261266
if (use_pager == -1 && p->option & USE_PAGER)
262267
use_pager = 1;

0 commit comments

Comments
 (0)