Skip to content

Commit

Permalink
Merge branch 'jn/paginate-fix'
Browse files Browse the repository at this point in the history
* jn/paginate-fix:
  t7006 (pager): add missing TTY prerequisites
  merge-file: run setup_git_directory_gently() sooner
  var: run setup_git_directory_gently() sooner
  ls-remote: run setup_git_directory_gently() sooner
  index-pack: run setup_git_directory_gently() sooner
  config: run setup_git_directory_gently() sooner
  bundle: run setup_git_directory_gently() sooner
  apply: run setup_git_directory_gently() sooner
  grep: run setup_git_directory_gently() sooner
  shortlog: run setup_git_directory_gently() sooner
  git wrapper: allow setup_git_directory_gently() be called earlier
  setup: remember whether repository was found
  git wrapper: introduce startup_info struct

Conflicts:
	builtin/index-pack.c
  • Loading branch information
Junio C Hamano committed Aug 31, 2010
2 parents 693fefe + 41bf3bc commit 633142d
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 47 deletions.
6 changes: 3 additions & 3 deletions builtin/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -3606,11 +3606,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;

Expand Down Expand Up @@ -3683,7 +3683,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)
Expand Down
6 changes: 2 additions & 4 deletions builtin/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions builtin/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,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);

Expand Down
6 changes: 2 additions & 4 deletions builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
struct string_list path_list = STRING_LIST_INIT_NODUP;
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"),
Expand Down Expand Up @@ -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 <pattern>', is a request
* to show usage information and exit.
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 0 additions & 2 deletions builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,12 @@ 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);

read_replace_refs = 0;

prefix = setup_git_directory_gently(&nongit);
git_config(git_index_pack_config, NULL);
if (prefix && chdir(prefix))
die("Cannot come back to cwd");
Expand Down
3 changes: 0 additions & 3 deletions builtin/ls-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];

Expand Down
4 changes: 1 addition & 3 deletions builtin/merge-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions builtin/shortlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
9 changes: 2 additions & 7 deletions builtin/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,12 @@ int split_cmdline(char *cmdline, const char ***argv);
/* Takes a negative value returned by split_cmdline */
const char *split_cmdline_strerror(int cmdline_errno);

/* git.c */
struct startup_info {
int have_repository;
};
extern struct startup_info *startup_info;

/* builtin/merge.c */
int checkout_fast_forward(const unsigned char *from, const unsigned char *to);

Expand Down
1 change: 1 addition & 0 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 23 additions & 15 deletions git.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -230,13 +231,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;
Expand All @@ -255,8 +257,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;
Expand Down Expand Up @@ -296,12 +302,12 @@ 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 },
{ "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,
Expand All @@ -314,7 +320,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 },
Expand All @@ -331,21 +337,21 @@ 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 },
{ "index-pack", cmd_index_pack, RUN_SETUP_GENTLY },
{ "init", cmd_init_db },
{ "init-db", cmd_init_db },
{ "log", cmd_log, RUN_SETUP },
{ "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 },
{ "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 },
Expand All @@ -361,7 +367,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 },
Expand All @@ -371,15 +377,15 @@ 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 },
{ "rev-parse", cmd_rev_parse },
{ "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 },
{ "status", cmd_status, RUN_SETUP | NEED_WORK_TREE },
Expand All @@ -393,7 +399,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 },
Expand Down Expand Up @@ -490,6 +496,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";
Expand Down
12 changes: 11 additions & 1 deletion setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ static dev_t get_device_or_die(const char *path, const char *prefix)
* 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);
Expand Down Expand Up @@ -507,6 +507,16 @@ const char *setup_git_directory_gently(int *nongit_ok)
}
}

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;
Expand Down
Loading

0 comments on commit 633142d

Please sign in to comment.