From e37c1329fa86683c828f04b51bad8bae03939ced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 5 Aug 2010 21:40:35 -0500 Subject: [PATCH 01/13] git wrapper: introduce startup_info struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The startup_info struct will collect information managed by the git setup code, such as the prefix for relative paths passed on the command line (i.e., path to the starting cwd from the toplevel of the work tree) and whether a git repository has been found. In other words, startup_info is intended to be a collection of global variables with results that were previously returned from setup functions. This state is global anyway (since the cwd is), even if it is not currently tracked that way. Letting these values persist means there is more flexibility in deciding when to run setup. For now, the struct is empty. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- cache.h | 5 +++++ environment.c | 1 + git.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/cache.h b/cache.h index c9fa3df7f5..0822c3b8be 100644 --- a/cache.h +++ b/cache.h @@ -1097,6 +1097,11 @@ void overlay_tree_on_cache(const char *tree_name, const char *prefix); char *alias_lookup(const char *alias); int split_cmdline(char *cmdline, const char ***argv); +/* git.c */ +struct startup_info { +}; +extern struct startup_info *startup_info; + /* builtin/merge.c */ int checkout_fast_forward(const unsigned char *from, const unsigned char *to); diff --git a/environment.c b/environment.c index 83d38d3c23..eeb26876a1 100644 --- a/environment.c +++ b/environment.c @@ -53,6 +53,7 @@ enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; char *notes_ref_name; int grafts_replace_parents = 1; int core_apply_sparse_checkout; +struct startup_info *startup_info; /* Parallel index stat data preload? */ int core_preload_index = 0; diff --git a/git.c b/git.c index f37028b3b7..c4b6dbea36 100644 --- a/git.c +++ b/git.c @@ -14,6 +14,7 @@ const char git_usage_string[] = const char git_more_info_string[] = "See 'git help COMMAND' for more information on a specific command."; +static struct startup_info git_startup_info; static int use_pager = -1; struct pager_config { const char *cmd; @@ -489,6 +490,8 @@ int main(int argc, const char **argv) { const char *cmd; + startup_info = &git_startup_info; + cmd = git_extract_argv0_path(argv[0]); if (!cmd) cmd = "git-help"; From a60645f9c54c3050cbe25882feba9d5b3d1ca0d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 5 Aug 2010 21:46:33 -0500 Subject: [PATCH 02/13] setup: remember whether repository was found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As v1.7.2~16^2 (git --paginate: paginate external commands again, 2010-07-14) explains, builtins (like git config) that do not use RUN_SETUP are not finding GIT_DIR set correctly when it is time to launch the pager from run_builtin(). If they were to search for a repository sooner, then the outcome of such early repository accesses would be more predictable and reliable. The cmd_*() functions learn whether a repository was found through the *nongit_ok return value from setup_git_directory_gently(). If run_builtin() is to take care of the repository search itself, that datum needs to be retrievable from somewhere else. Use the startup_info struct for this. As a bonus, this information becomes available to functions such as git_config() which might want to avoid trying to access a repository when none is present. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- cache.h | 1 + setup.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cache.h b/cache.h index 0822c3b8be..f9e82a8ace 100644 --- a/cache.h +++ b/cache.h @@ -1099,6 +1099,7 @@ int split_cmdline(char *cmdline, const char ***argv); /* git.c */ struct startup_info { + int have_repository; }; extern struct startup_info *startup_info; diff --git a/setup.c b/setup.c index 2769160527..28a2b69d05 100644 --- a/setup.c +++ b/setup.c @@ -317,7 +317,7 @@ const char *read_gitfile_gently(const char *path) * We cannot decide in this function whether we are in the work tree or * not, since the config can only be read _after_ this function was called. */ -const char *setup_git_directory_gently(int *nongit_ok) +static const char *setup_git_directory_gently_1(int *nongit_ok) { const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT); const char *env_ceiling_dirs = getenv(CEILING_DIRECTORIES_ENVIRONMENT); @@ -473,6 +473,16 @@ const char *setup_git_directory_gently(int *nongit_ok) return cwd + offset; } +const char *setup_git_directory_gently(int *nongit_ok) +{ + const char *prefix; + + prefix = setup_git_directory_gently_1(nongit_ok); + if (startup_info) + startup_info->have_repository = !nongit_ok || !*nongit_ok; + return prefix; +} + int git_config_perm(const char *var, const char *value) { int i; From ee38dfb89ef88a3e4e6818b7cfe31d122a1c640d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 5 Aug 2010 21:52:16 -0500 Subject: [PATCH 03/13] git wrapper: allow setup_git_directory_gently() be called earlier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- git.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/git.c b/git.c index c4b6dbea36..c1d1ee78fc 100644 --- a/git.c +++ b/git.c @@ -230,13 +230,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 RUN_SETUP_GENTLY (1<<1) +#define USE_PAGER (1<<2) /* * 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<<3) struct cmd_struct { const char *cmd; @@ -255,8 +256,12 @@ 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) + if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY)) use_pager = check_pager_config(p->cmd); if (use_pager == -1 && p->option & USE_PAGER) use_pager = 1; From 773b69bf7189f5babb26b899b4c35f604cd993c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 5 Aug 2010 22:01:37 -0500 Subject: [PATCH 04/13] shortlog: run setup_git_directory_gently() sooner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit shortlog already runs a repository search unconditionally; running such a search earlier is not very risky. Without this change, the “[pager] shortlog” configuration is not respected at all: “git shortlog” unconditionally paginates. The tests are a bit slow. Running the full battery like this for all built-in commands would be counterproductive; the intent is rather to test shortlog as a representative example command using ..._gently(). Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/shortlog.c | 3 +-- git.c | 2 +- t/t7006-pager.sh | 9 +++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 0a9681ba7e..2135b0dde1 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -249,7 +249,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) { static struct shortlog log; static struct rev_info rev; - int nongit; + int nongit = !startup_info->have_repository; static const struct option options[] = { OPT_BOOLEAN('n', "numbered", &log.sort_by_number, @@ -265,7 +265,6 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) struct parse_opt_ctx_t ctx; - prefix = setup_git_directory_gently(&nongit); git_config(git_default_config, NULL); shortlog_init(&log); init_revisions(&rev, prefix); diff --git a/git.c b/git.c index c1d1ee78fc..3d96c2bcd3 100644 --- a/git.c +++ b/git.c @@ -384,7 +384,7 @@ static void handle_internal_command(int argc, const char **argv) { "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE }, { "rm", cmd_rm, RUN_SETUP }, { "send-pack", cmd_send_pack, RUN_SETUP }, - { "shortlog", cmd_shortlog, USE_PAGER }, + { "shortlog", cmd_shortlog, RUN_SETUP_GENTLY | USE_PAGER }, { "show-branch", cmd_show_branch, RUN_SETUP }, { "show", cmd_show, RUN_SETUP | USE_PAGER }, { "status", cmd_status, RUN_SETUP | NEED_WORK_TREE }, diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 71d3ceff8f..43b310218a 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -369,4 +369,13 @@ test_GIT_PAGER_overrides expect_success test_must_fail 'git -p' test_doesnt_paginate expect_failure test_must_fail 'git -p nonsense' +test_pager_choices 'git shortlog' +test_expect_success 'setup: configure shortlog not to paginate' ' + git config pager.shortlog false +' +test_doesnt_paginate expect_success 'git shortlog' +test_no_local_config_subdir expect_success 'git shortlog' +test_default_pager expect_success 'git -p shortlog' +test_core_pager_subdir expect_success 'git -p shortlog' + test_done From ff38d1a9953b3bce7741f8f962c5e067fda2d9ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 5 Aug 2010 22:06:39 -0500 Subject: [PATCH 05/13] grep: run setup_git_directory_gently() sooner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git grep already runs a repository search unconditionally, even when the --no-index option is supplied; running such a search earlier is not very risky. Just like with shortlog, without this change, the “[pager] grep” configuration is not respected at all. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/grep.c | 6 ++---- git.c | 2 +- t/t7006-pager.sh | 13 +++++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 597f76bc42..ca56c5b009 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -839,7 +839,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) struct string_list path_list = { NULL, 0, 0, 0 }; int i; int dummy; - int nongit = 0, use_index = 1; + int use_index = 1; struct option options[] = { OPT_BOOLEAN(0, "cached", &cached, "search in index instead of in the work tree"), @@ -930,8 +930,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_END() }; - prefix = setup_git_directory_gently(&nongit); - /* * 'git grep -h', unlike 'git grep -h ', is a request * to show usage information and exit. @@ -976,7 +974,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_NO_INTERNAL_HELP); - if (use_index && nongit) + if (use_index && !startup_info->have_repository) /* die the same way as if we did it at the beginning */ setup_git_directory(); diff --git a/git.c b/git.c index 3d96c2bcd3..5a47bfbcbd 100644 --- a/git.c +++ b/git.c @@ -336,7 +336,7 @@ static void handle_internal_command(int argc, const char **argv) { "fsck-objects", cmd_fsck, RUN_SETUP }, { "gc", cmd_gc, RUN_SETUP }, { "get-tar-commit-id", cmd_get_tar_commit_id }, - { "grep", cmd_grep }, + { "grep", cmd_grep, RUN_SETUP_GENTLY }, { "hash-object", cmd_hash_object }, { "help", cmd_help }, { "index-pack", cmd_index_pack }, diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 43b310218a..bb9533581e 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -106,6 +106,19 @@ test_expect_success TTY 'no pager with --no-pager' ' ! test -e paginated.out ' +test_expect_success TTY 'configuration can disable pager' ' + rm -f paginated.out && + test_might_fail git config --unset pager.grep && + test_terminal git grep initial && + test -e paginated.out && + + rm -f paginated.out && + git config pager.grep false && + test_when_finished "git config --unset pager.grep" && + test_terminal git grep initial && + ! test -e paginated.out +' + # A colored commit log will begin with an appropriate ANSI escape # for the first color; the text "commit" comes later. colorful() { From d1ea896290629185dc0bf4efa3469b410bd41313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Mon, 16 Aug 2010 10:36:12 +1000 Subject: [PATCH 06/13] apply: run setup_git_directory_gently() sooner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As v1.7.2~16^2 (2010-07-14) explains, without this change, “git --paginate apply” can ignore the repository-local “[core] pager” configuration. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/apply.c | 6 +++--- git.c | 2 +- t/t7006-pager.sh | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 12ef9ea8af..f005ba1e89 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -3607,11 +3607,11 @@ static int option_parse_directory(const struct option *opt, return 0; } -int cmd_apply(int argc, const char **argv, const char *unused_prefix) +int cmd_apply(int argc, const char **argv, const char *prefix_) { int i; int errs = 0; - int is_not_gitdir; + int is_not_gitdir = !startup_info->have_repository; int binary; int force_apply = 0; @@ -3684,7 +3684,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) OPT_END() }; - prefix = setup_git_directory_gently(&is_not_gitdir); + prefix = prefix_; prefix_length = prefix ? strlen(prefix) : 0; git_config(git_apply_config, NULL); if (apply_default_whitespace) diff --git a/git.c b/git.c index 5a47bfbcbd..38dbe7022e 100644 --- a/git.c +++ b/git.c @@ -301,7 +301,7 @@ static void handle_internal_command(int argc, const char **argv) { "add", cmd_add, RUN_SETUP | NEED_WORK_TREE }, { "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE }, { "annotate", cmd_annotate, RUN_SETUP }, - { "apply", cmd_apply }, + { "apply", cmd_apply, RUN_SETUP_GENTLY }, { "archive", cmd_archive }, { "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE }, { "blame", cmd_blame, RUN_SETUP }, diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index bb9533581e..6c86d7035f 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -391,4 +391,7 @@ test_no_local_config_subdir expect_success 'git shortlog' test_default_pager expect_success 'git -p shortlog' test_core_pager_subdir expect_success 'git -p shortlog' +test_core_pager_subdir expect_success test_must_fail \ + 'git -p apply Date: Thu, 5 Aug 2010 22:12:46 -0500 Subject: [PATCH 07/13] bundle: run setup_git_directory_gently() sooner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Without this change, “git -p bundle” does not always respect the repository-local “[core] pager” setting. It is hard to notice because subcommands other than “git bundle unbundle” do not produce much output. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/bundle.c | 6 ++---- git.c | 2 +- t/t7006-pager.sh | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/builtin/bundle.c b/builtin/bundle.c index 2006cc5cd5..80649ba0b2 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -18,7 +18,6 @@ static const char builtin_bundle_usage[] = int cmd_bundle(int argc, const char **argv, const char *prefix) { struct bundle_header header; - int nongit; const char *cmd, *bundle_file; int bundle_fd = -1; char buffer[PATH_MAX]; @@ -31,7 +30,6 @@ int cmd_bundle(int argc, const char **argv, const char *prefix) argc -= 2; argv += 2; - prefix = setup_git_directory_gently(&nongit); if (prefix && bundle_file[0] != '/') { snprintf(buffer, sizeof(buffer), "%s/%s", prefix, bundle_file); bundle_file = buffer; @@ -54,11 +52,11 @@ int cmd_bundle(int argc, const char **argv, const char *prefix) return !!list_bundle_refs(&header, argc, argv); } if (!strcmp(cmd, "create")) { - if (nongit) + if (!startup_info->have_repository) die("Need a repository to create a bundle."); return !!create_bundle(&header, bundle_file, argc, argv); } else if (!strcmp(cmd, "unbundle")) { - if (nongit) + if (!startup_info->have_repository) die("Need a repository to unbundle."); return !!unbundle(&header, bundle_fd) || list_bundle_refs(&header, argc, argv); diff --git a/git.c b/git.c index 38dbe7022e..e76b647b61 100644 --- a/git.c +++ b/git.c @@ -306,7 +306,7 @@ static void handle_internal_command(int argc, const char **argv) { "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE }, { "blame", cmd_blame, RUN_SETUP }, { "branch", cmd_branch, RUN_SETUP }, - { "bundle", cmd_bundle }, + { "bundle", cmd_bundle, RUN_SETUP_GENTLY }, { "cat-file", cmd_cat_file, RUN_SETUP }, { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE }, { "checkout-index", cmd_checkout_index, diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 6c86d7035f..1890c65fa1 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -58,6 +58,21 @@ test_expect_success TTY 'some commands use a pager' ' test -e paginated.out ' +test_expect_failure TTY 'pager runs from subdir' ' + echo subdir/paginated.out >expected && + mkdir -p subdir && + rm -f paginated.out subdir/paginated.out && + ( + cd subdir && + test_terminal git log + ) && + { + ls paginated.out subdir/paginated.out || + : + } >actual && + test_cmp expected actual +' + test_expect_success TTY 'some commands do not use a pager' ' rm -f paginated.out || cleanup_fail && @@ -119,6 +134,24 @@ test_expect_success TTY 'configuration can disable pager' ' ! test -e paginated.out ' +test_expect_success 'configuration can enable pager (from subdir)' ' + rm -f paginated.out && + mkdir -p subdir && + git config pager.bundle true && + test_when_finished "git config --unset pager.bundle" && + + git bundle create test.bundle --all && + rm -f paginated.out subdir/paginated.out && + ( + cd subdir && + test_terminal git bundle unbundle ../test.bundle + ) && + { + test -e paginated.out || + test -e subdir/paginated.out + } +' + # A colored commit log will begin with an appropriate ANSI escape # for the first color; the text "commit" comes later. colorful() { From 3ba7e6e29afd67e69ff5963d8ed76728824959a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 5 Aug 2010 22:15:09 -0500 Subject: [PATCH 08/13] config: run setup_git_directory_gently() sooner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For the pager choice (and the choice to paginate) to reflect the current repository configuration, the repository needs to be located first. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/config.c | 5 ++--- git.c | 4 ++-- t/t7006-pager.sh | 8 ++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index f3d1660d02..3f8ef91dfc 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -330,11 +330,10 @@ static int get_colorbool(int print) return get_colorbool_found ? 0 : 1; } -int cmd_config(int argc, const char **argv, const char *unused_prefix) +int cmd_config(int argc, const char **argv, const char *prefix) { - int nongit; + int nongit = !startup_info->have_repository; char *value; - const char *prefix = setup_git_directory_gently(&nongit); config_exclusive_filename = getenv(CONFIG_ENVIRONMENT); diff --git a/git.c b/git.c index e76b647b61..eaf6e7f87d 100644 --- a/git.c +++ b/git.c @@ -319,7 +319,7 @@ static void handle_internal_command(int argc, const char **argv) { "clean", cmd_clean, RUN_SETUP | NEED_WORK_TREE }, { "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE }, { "commit-tree", cmd_commit_tree, RUN_SETUP }, - { "config", cmd_config }, + { "config", cmd_config, RUN_SETUP_GENTLY }, { "count-objects", cmd_count_objects, RUN_SETUP }, { "describe", cmd_describe, RUN_SETUP }, { "diff", cmd_diff }, @@ -376,7 +376,7 @@ static void handle_internal_command(int argc, const char **argv) { "reflog", cmd_reflog, RUN_SETUP }, { "remote", cmd_remote, RUN_SETUP }, { "replace", cmd_replace, RUN_SETUP }, - { "repo-config", cmd_config }, + { "repo-config", cmd_config, RUN_SETUP_GENTLY }, { "rerere", cmd_rerere, RUN_SETUP }, { "reset", cmd_reset, RUN_SETUP }, { "rev-list", cmd_rev_list, RUN_SETUP }, diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 1890c65fa1..017565f332 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -134,6 +134,14 @@ test_expect_success TTY 'configuration can disable pager' ' ! test -e paginated.out ' +test_expect_success 'git config uses a pager if configured to' ' + rm -f paginated.out && + git config pager.config true && + test_when_finished "git config --unset pager.config" && + test_terminal git config --list && + test -e paginated.out +' + test_expect_success 'configuration can enable pager (from subdir)' ' rm -f paginated.out && mkdir -p subdir && From e0fce074fc4fdf2d2175ff97f1cc3db918ea87e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 5 Aug 2010 22:18:53 -0500 Subject: [PATCH 09/13] index-pack: run setup_git_directory_gently() sooner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit index-pack already runs a repository search unconditionally; running such a search earlier is not risky and ensures GIT_DIR will be set correctly if the configuration needs to be accessed from run_builtin(). Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/index-pack.c | 2 -- git.c | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 89a1f12d61..e852890862 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -880,12 +880,10 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix) char *index_name_buf = NULL, *keep_name_buf = NULL; struct pack_idx_entry **idx_objects; unsigned char pack_sha1[20]; - int nongit; if (argc == 2 && !strcmp(argv[1], "-h")) usage(index_pack_usage); - prefix = setup_git_directory_gently(&nongit); git_config(git_index_pack_config, NULL); if (prefix && chdir(prefix)) die("Cannot come back to cwd"); diff --git a/git.c b/git.c index eaf6e7f87d..982406839c 100644 --- a/git.c +++ b/git.c @@ -339,7 +339,7 @@ static void handle_internal_command(int argc, const char **argv) { "grep", cmd_grep, RUN_SETUP_GENTLY }, { "hash-object", cmd_hash_object }, { "help", cmd_help }, - { "index-pack", cmd_index_pack }, + { "index-pack", cmd_index_pack, RUN_SETUP_GENTLY }, { "init", cmd_init_db }, { "init-db", cmd_init_db }, { "log", cmd_log, RUN_SETUP | USE_PAGER }, From f0ef6a6eff15a3df8dc9ec61d93e3f7e540ed0ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 5 Aug 2010 22:20:08 -0500 Subject: [PATCH 10/13] ls-remote: run setup_git_directory_gently() sooner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ls-remote already runs a repository search unconditionally to learn about remote nicknames and "[url] insteadof" shortcuts. Run that search a little sooner, and now one can try [pager] ls-remote to automatically paginate ls-remote output, or use repository-local [core] pager = whatever with "git --paginate ls-remote ". Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/ls-remote.c | 3 --- git.c | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 34480cfad6..97eed4012b 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -32,7 +32,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) { int i; const char *dest = NULL; - int nongit; unsigned flags = 0; int quiet = 0; const char *uploadpack = NULL; @@ -42,8 +41,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) struct transport *transport; const struct ref *ref; - setup_git_directory_gently(&nongit); - for (i = 1; i < argc; i++) { const char *arg = argv[i]; diff --git a/git.c b/git.c index 982406839c..86b0a88d97 100644 --- a/git.c +++ b/git.c @@ -345,7 +345,7 @@ static void handle_internal_command(int argc, const char **argv) { "log", cmd_log, RUN_SETUP | USE_PAGER }, { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-tree", cmd_ls_tree, RUN_SETUP }, - { "ls-remote", cmd_ls_remote }, + { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY }, { "mailinfo", cmd_mailinfo }, { "mailsplit", cmd_mailsplit }, { "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE }, @@ -366,7 +366,7 @@ static void handle_internal_command(int argc, const char **argv) { "pack-objects", cmd_pack_objects, RUN_SETUP }, { "pack-redundant", cmd_pack_redundant, RUN_SETUP }, { "patch-id", cmd_patch_id }, - { "peek-remote", cmd_ls_remote }, + { "peek-remote", cmd_ls_remote, RUN_SETUP_GENTLY }, { "pickaxe", cmd_blame, RUN_SETUP }, { "prune", cmd_prune, RUN_SETUP }, { "prune-packed", cmd_prune_packed, RUN_SETUP }, From 2bc8c1a8a6b1cdffc19badc7272f552302b79d3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 5 Aug 2010 22:21:40 -0500 Subject: [PATCH 11/13] var: run setup_git_directory_gently() sooner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of a campaign to make repository-local configuration available early (simplifying the startup sequence for built-in commands). Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/var.c | 9 ++------- git.c | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/builtin/var.c b/builtin/var.c index 70fdb4dec7..0744bb8318 100644 --- a/builtin/var.c +++ b/builtin/var.c @@ -74,14 +74,9 @@ static int show_config(const char *var, const char *value, void *cb) int cmd_var(int argc, const char **argv, const char *prefix) { - const char *val; - int nongit; - if (argc != 2) { + const char *val = NULL; + if (argc != 2) usage(var_usage); - } - - setup_git_directory_gently(&nongit); - val = NULL; if (strcmp(argv[1], "-l") == 0) { git_config(show_config, NULL); diff --git a/git.c b/git.c index 86b0a88d97..89bce65917 100644 --- a/git.c +++ b/git.c @@ -398,7 +398,7 @@ static void handle_internal_command(int argc, const char **argv) { "update-ref", cmd_update_ref, RUN_SETUP }, { "update-server-info", cmd_update_server_info, RUN_SETUP }, { "upload-archive", cmd_upload_archive }, - { "var", cmd_var }, + { "var", cmd_var, RUN_SETUP_GENTLY }, { "verify-tag", cmd_verify_tag, RUN_SETUP }, { "version", cmd_version }, { "whatchanged", cmd_whatchanged, RUN_SETUP | USE_PAGER }, From 3668d4238314dc5db98de3034058f68ff57a6b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 5 Aug 2010 22:27:43 -0500 Subject: [PATCH 12/13] merge-file: run setup_git_directory_gently() sooner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of a campaign to make repository-local configuration available early (simplifying the startup sequence for built-in commands). Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- builtin/merge-file.c | 4 +--- git.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/builtin/merge-file.c b/builtin/merge-file.c index b8e9e5ba01..b6664d49be 100644 --- a/builtin/merge-file.c +++ b/builtin/merge-file.c @@ -28,7 +28,6 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) xmparam_t xmp = {{0}}; int ret = 0, i = 0, to_stdout = 0; int quiet = 0; - int nongit; struct option options[] = { OPT_BOOLEAN('p', "stdout", &to_stdout, "send results to standard output"), OPT_SET_INT(0, "diff3", &xmp.style, "use a diff3 based merge", XDL_MERGE_DIFF3), @@ -50,8 +49,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) xmp.style = 0; xmp.favor = 0; - prefix = setup_git_directory_gently(&nongit); - if (!nongit) { + if (startup_info->have_repository) { /* Read the configuration file */ git_config(git_xmerge_config, NULL); if (0 <= git_xmerge_style) diff --git a/git.c b/git.c index 89bce65917..286a3595a8 100644 --- a/git.c +++ b/git.c @@ -350,7 +350,7 @@ static void handle_internal_command(int argc, const char **argv) { "mailsplit", cmd_mailsplit }, { "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE }, { "merge-base", cmd_merge_base, RUN_SETUP }, - { "merge-file", cmd_merge_file }, + { "merge-file", cmd_merge_file, RUN_SETUP_GENTLY }, { "merge-index", cmd_merge_index, RUN_SETUP }, { "merge-ours", cmd_merge_ours, RUN_SETUP }, { "merge-recursive", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE }, From 41bf3bc232cf5f99fdc6d3d729536a4c4821d3bd Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Mon, 16 Aug 2010 03:08:34 -0500 Subject: [PATCH 13/13] t7006 (pager): add missing TTY prerequisites The "git bundle unbundle" and "git config" pagination tests are not supposed to run when stdout is not a terminal and IO::Pty not available to make one on the fly. Reported-by: Thomas Rast Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- t/t7006-pager.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 017565f332..fb744e3c4a 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -134,7 +134,7 @@ test_expect_success TTY 'configuration can disable pager' ' ! test -e paginated.out ' -test_expect_success 'git config uses a pager if configured to' ' +test_expect_success TTY 'git config uses a pager if configured to' ' rm -f paginated.out && git config pager.config true && test_when_finished "git config --unset pager.config" && @@ -142,7 +142,7 @@ test_expect_success 'git config uses a pager if configured to' ' test -e paginated.out ' -test_expect_success 'configuration can enable pager (from subdir)' ' +test_expect_success TTY 'configuration can enable pager (from subdir)' ' rm -f paginated.out && mkdir -p subdir && git config pager.bundle true &&