Search and set up repository early for builtin commands
cover Search and set up repository early for builtin commands
This is a simpler part of my Git setup cleanup WIP [1], to introduce RUN_SETUP_GENTLY and make most of commands use it.
The commands that do not have RUN_SETUP* are:
- Init/Clone commands
- Server commands
- Helpers that have nothing to do with repositories
- git-rev-parse
[1] http://mid.gmane.org/[email protected]
Nguyễn Thái Ngọc Duy (18):
builtin: introduce startup_info struct
builtin: Support RUN_SETUP_GENTLY to set up repository early if found
config: use RUN_SETUP_GENTLY
hash-object: use RUN_SETUP_GENTLY
shortlog: use RUN_SETUP_GENTLY
grep: use RUN_SETUP_GENTLY
builtin: USE_PAGER should not be used without RUN_SETUP*
archive: use RUN_SETUP_GENTLY
mailinfo: use RUN_SETUP_GENTLY
check-ref-format: use RUN_SETUP_GENTLY
verify-pack: use RUN_SETUP_GENTLY
apply: use RUN_SETUP_GENTLY
bundle: use RUN_SETUP_GENTLY
diff: use RUN_SETUP_GENTLY
help: use RUN_SETUP_GENTLY
ls-remote: use RUN_SETUP_GENTLY
var: use RUN_SETUP_GENTLY
merge-file: use RUN_SETUP_GENTLY
builtin/apply.c | 7 ++--- builtin/archive.c | 2 +- builtin/bundle.c | 6 +--- builtin/config.c | 6 +--- builtin/diff.c | 6 +--- builtin/grep.c | 9 ++----- builtin/hash-object.c | 9 ++++--- builtin/help.c | 2 - builtin/ls-remote.c | 3 -- builtin/mailinfo.c | 3 -- builtin/merge-file.c | 4 +-- builtin/shortlog.c | 4 +-- builtin/var.c | 2 - cache.h | 7 +++++ environment.c | 1 + git.c | 61 ++++++++++++++++++++++++++++--------------------- setup.c | 14 ++++++++++- 17 files changed, 76 insertions(+), 70 deletions(-)
PATCH 1/18 builtin: introduce startup_info struct
The purpose of this struct is to make it easier to extend parameters passed to builtin commands from run_builtin(), and let libgit aware of some global states in future.
--- cache.h | 6 ++++++ environment.c | 1 + git.c | 9 +++++---- setup.c | 12 +++++++++++- 4 files changed, 23 insertions(+), 5 deletions(-)
cache.h +6 -0
@@ -1054,4 +1054,10 @@ 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 { +const char *prefix; +}; +extern struct startup_info *startup_info; +#endif /* CACHE_H */
environment.c +1 -0
@@ -52,6 +52,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 ;
git.c +5 -4
@@ -13,6 +13,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;
@@ -237,13 +238,13 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) {int status, help;struct stat st; -const char *prefix; - prefix =NULL ; +memset (&git_startup_info,0 ,sizeof (git_startup_info)); + startup_info = &git_startup_info; help = argc ==2 && !strcmp (argv[1 ],"-h" );if (!help) {if (p->option &RUN_SETUP ) - prefix =setup_git_directory (); +setup_git_directory ();if (use_pager ==-1 && p->option &RUN_SETUP ) use_pager =check_pager_config (p->cmd);
@@ -257,7 +258,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)trace_argv_printf (argv,"trace: built-in: git" ); - status = p->fn (argc, argv, prefix); + status = p->fn (argc, argv, startup_info->prefix);if (status)return status;
setup.c +11 -1
@@ -315,7 +315,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 );
@@ -443,6 +443,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->prefix = prefix; +return prefix; +} +int git_config_perm (const char *var,const char *value) {int i;
Signature · 1 line
1.7.0.195.g637a2
PATCH 2/18 builtin: Support RUN_SETUP_GENTLY to set up repository early if found
In reply to Nguyễn Thái Ngọc DuyAttempts to access gitdir are everywhere, even before cmd_*() is called. Because repository has not been found, repository-specific information (i.e. $GIT_DIR/config) may not be read. This leads to obscure bugs.
So the sooner we setup gitdir, the less trouble we may have to deal with.
--- cache.h | 1 + git.c | 11 ++++++++--- setup.c | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-)
cache.h +1 -0
@@ -1057,6 +1057,7 @@ int split_cmdline(char *cmdline, const char ***argv);/* git.c */ struct startup_info {const char *prefix; +int have_repository; };extern struct startup_info *startup_info;
git.c +8 -3
@@ -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 )setup_git_directory (); +if (p->option &RUN_SETUP_GENTLY ) { +int nongit_ok; +setup_git_directory_gently (&nongit_ok); + }if (use_pager ==-1 && p->option &RUN_SETUP ) use_pager =check_pager_config (p->cmd);
setup.c +3 -1
@@ -448,8 +448,10 @@ const char *setup_git_directory_gently(int *nongit_ok)const char *prefix; prefix =setup_git_directory_gently_1 (nongit_ok); -if (startup_info) +if (startup_info) { startup_info->prefix = prefix; + startup_info->have_repository = !nongit_ok || !*nongit_ok; + }return prefix; }
Signature · 1 line
1.7.0.195.g637a2
PATCH 3/18 config: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duy--- builtin/config.c | 6 ++---- git.c | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-)
builtin/config.c +2 -4
@@ -326,11 +326,9 @@ 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;char *value; -const char *prefix =setup_git_directory_gently (&nongit); config_exclusive_filename =getenv (CONFIG_ENVIRONMENT );
@@ -409,7 +407,7 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix) }else if (actions ==ACTION_EDIT ) {check_argc (argc,0 ,0 ); -if (!config_exclusive_filename && nongit) +if (!config_exclusive_filename && !startup_info->have_repository)die ("not in a git directory" );git_config (git_default_config,NULL ); launch_editor(config_exclusive_filename ?
git.c +2 -2
@@ -309,7 +309,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 },
@@ -366,7 +366,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 },
Signature · 1 line
1.7.0.195.g637a2
PATCH 4/18 hash-object: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duyhash-object needs to inspect repository's config, so it must try to find a repository regardless the object will be written in object store.
--- builtin/hash-object.c | 9 +++++---- git.c | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-)
builtin/hash-object.c +5 -4
@@ -76,7 +76,7 @@ static const struct option hash_object_options[] = {int cmd_hash_object (int argc,const char **argv,const char *prefix) {int i; -int prefix_length =-1 ; +int prefix_length;const char *errstr =NULL ; type = blob_type;
@@ -84,9 +84,10 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) argc =parse_options (argc, argv,NULL , hash_object_options, hash_object_usage,0 ); + prefix_length = prefix ?strlen (prefix) :0 ;if (write_object) { - prefix =setup_git_directory (); - prefix_length = prefix ?strlen (prefix) :0 ; +if (!startup_info->have_repository) +die ("No repository found" );if (vpath && prefix) vpath =prefix_filename (prefix, prefix_length, vpath); }
@@ -121,7 +122,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)for (i =0 ; i < argc; i++) {const char *arg = argv[i]; -if (0 <= prefix_length) +if (prefix_length) arg =prefix_filename (prefix, prefix_length, arg);hash_object (arg, type, write_object, no_filters ?NULL : vpath ? vpath : arg);
git.c +1 -1
@@ -327,7 +327,7 @@ static void handle_internal_command(int argc, const char **argv) { "gc", cmd_gc, RUN_SETUP }, { "get-tar-commit-id", cmd_get_tar_commit_id }, { "grep", cmd_grep, USE_PAGER }, - { "hash-object", cmd_hash_object }, + { "hash-object", cmd_hash_object, RUN_SETUP_GENTLY }, { "help", cmd_help }, { "index-pack", cmd_index_pack }, { "init", cmd_init_db },
Signature · 1 line
1.7.0.195.g637a2
PATCH 5/18 shortlog: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duyshortlog has USE_PAGER set. setup_pager() may read config even setup_git_dir* is not run yet. This tries to find a repository before the config is read.
--- builtin/shortlog.c | 4 +--- git.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-)
builtin/shortlog.c +1 -3
@@ -249,7 +249,6 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) { static struct shortlog log; static struct rev_info rev; - int nongit; static const struct option options[] = { OPT_BOOLEAN('n', "numbered", &log.sort_by_number,
@@ -265,7 +264,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);
@@ -292,7 +290,7 @@ parse_done: log.user_format = rev.commit_format ==CMIT_FMT_USERFORMAT ;/* assume HEAD if from a tty */ -if (!nongit && !rev.pending.nr &&isatty (0 )) +if (startup_info->have_repository && !rev.pending.nr &&isatty (0 ))add_head_to_pending (&rev);if (rev.pending.nr ==0 ) {if (isatty (0 ))
git.c +1 -1
@@ -374,7 +374,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 },
Signature · 1 line
1.7.0.195.g637a2
PATCH 6/18 grep: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duygrep has USE_PAGER set. setup_pager() may read config even setup_git_dir* is not run yet. This tries to find a repository before config is read.
--- builtin/grep.c | 9 +++------ git.c | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-)
builtin/grep.c +3 -6
@@ -765,7 +765,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)const char **paths =NULL ;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" ),
@@ -853,8 +853,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.
@@ -893,9 +891,8 @@ 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) -/* die the same way as if we did it at the beginning */ -setup_git_directory (); +if (use_index && !startup_info->have_repository) +die ("No git repository found" );/* * skip a -- separator; we know it cannot be
git.c +1 -1
@@ -326,7 +326,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, USE_PAGER }, + { "grep", cmd_grep, RUN_SETUP_GENTLY | USE_PAGER }, { "hash-object", cmd_hash_object, RUN_SETUP_GENTLY }, { "help", cmd_help }, { "index-pack", cmd_index_pack },
Signature · 1 line
1.7.0.195.g637a2
PATCH 7/18 builtin: USE_PAGER should not be used without RUN_SETUP*
In reply to Nguyễn Thái Ngọc DuyUSE_PAGER may need core.pager from repository. So a repository search should be done before core.pager is read.
--- git.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
git.c +4 -1
@@ -253,8 +253,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)if (use_pager ==-1 && p->option &RUN_SETUP ) use_pager =check_pager_config (p->cmd); -if (use_pager ==-1 && p->option &USE_PAGER ) +if (use_pager ==-1 && p->option &USE_PAGER ) { +if ((p->option & (RUN_SETUP |RUN_SETUP_GENTLY )) ==0 ) +die ("Internal error: USE_PAGER must be together with RUN_SETUP*" ); use_pager =1 ; + } }commit_pager_choice ();
Signature · 1 line
1.7.0.195.g637a2
PATCH 8/18 archive: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duy--- builtin/archive.c | 2 +- git.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
builtin/archive.c +1 -1
@@ -125,5 +125,5 @@ int cmd_archive(int argc, const char **argv, const char *prefix)setvbuf (stderr,NULL , _IOLBF,BUFSIZ ); -return write_archive (argc, argv, prefix,1 ); +return write_archive (argc, argv, prefix,0 ); }
git.c +2 -2
@@ -295,7 +295,7 @@ static void handle_internal_command(int argc, const char **argv) { "stage", cmd_add, RUN_SETUP | NEED_WORK_TREE }, { "annotate", cmd_annotate, RUN_SETUP }, { "apply", cmd_apply }, - { "archive", cmd_archive }, + { "archive", cmd_archive, RUN_SETUP_GENTLY }, { "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE }, { "blame", cmd_blame, RUN_SETUP }, { "branch", cmd_branch, RUN_SETUP },
@@ -384,7 +384,7 @@ static void handle_internal_command(int argc, const char **argv) { "stripspace", cmd_stripspace }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP }, { "tag", cmd_tag, RUN_SETUP }, - { "tar-tree", cmd_tar_tree }, + { "tar-tree", cmd_tar_tree, RUN_SETUP_GENTLY }, { "unpack-file", cmd_unpack_file, RUN_SETUP }, { "unpack-objects", cmd_unpack_objects, RUN_SETUP }, { "update-index", cmd_update_index, RUN_SETUP },
Signature · 1 line
1.7.0.195.g637a2
PATCH 9/18 mailinfo: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duymailinfo may use repo config, so setup gitdir first.
--- builtin/mailinfo.c | 3 --- git.c | 2 +- 2 files changed, 1 insertions(+), 4 deletions(-)
builtin/mailinfo.c +0 -3
@@ -1026,9 +1026,6 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) {const char *def_charset; -/* NEEDSWORK: might want to do the optional .git/ directory -* discovery -*/ git_config (git_mailinfo_config,NULL ); def_charset = (git_commit_encoding ? git_commit_encoding :"UTF-8" );
git.c +1 -1
@@ -339,7 +339,7 @@ static void handle_internal_command(int argc, const char **argv) { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-tree", cmd_ls_tree, RUN_SETUP }, { "ls-remote", cmd_ls_remote }, - { "mailinfo", cmd_mailinfo }, + { "mailinfo", cmd_mailinfo, RUN_SETUP_GENTLY }, { "mailsplit", cmd_mailsplit }, { "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE }, { "merge-base", cmd_merge_base, RUN_SETUP },
Signature · 1 line
1.7.0.195.g637a2
PATCH 10/18 check-ref-format: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc DuyWhen --branch is used, check-ref-format will look into repository for branch name. Therefore repository search is needed.
The call flow is:
- cmd_check_ref_format
- strbuf_check_branch_ref
- strbuf_branchname
- interpret_branch_name
- branch_get
- read_config
- resolve_ref
--- git.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
git.c +1 -1
@@ -304,7 +304,7 @@ static void handle_internal_command(int argc, const char **argv) { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE }, { "checkout-index", cmd_checkout_index, RUN_SETUP | NEED_WORK_TREE}, - { "check-ref-format", cmd_check_ref_format }, + { "check-ref-format", cmd_check_ref_format, RUN_SETUP_GENTLY }, { "check-attr", cmd_check_attr, RUN_SETUP }, { "cherry", cmd_cherry, RUN_SETUP }, { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE },
Signature · 1 line
1.7.0.195.g637a2
PATCH 11/18 verify-pack: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duy--- git.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
git.c +1 -1
@@ -396,7 +396,7 @@ static void handle_internal_command(int argc, const char **argv) { "version", cmd_version }, { "whatchanged", cmd_whatchanged, RUN_SETUP | USE_PAGER }, { "write-tree", cmd_write_tree, RUN_SETUP }, - { "verify-pack", cmd_verify_pack }, + { "verify-pack", cmd_verify_pack, RUN_SETUP_GENTLY }, { "show-ref", cmd_show_ref, RUN_SETUP }, { "pack-refs", cmd_pack_refs, RUN_SETUP }, };
Signature · 1 line
1.7.0.195.g637a2
PATCH 12/18 apply: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duy--- builtin/apply.c | 7 +++---- git.c | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-)
builtin/apply.c +3 -4
@@ -3516,7 +3516,6 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) {int i;int errs =0 ; -int is_not_gitdir;int binary;int force_apply =0 ;
@@ -3589,7 +3588,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) OPT_END() }; - prefix =setup_git_directory_gently (&is_not_gitdir); + prefix = startup_info->prefix; prefix_length = prefix ?strlen (prefix) :0 ;git_config (git_apply_config,NULL );if (apply_default_whitespace)
@@ -3604,10 +3603,10 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) apply = apply_verbosely =1 ;if (!force_apply && (diffstat || numstat || summary || check || fake_ancestor)) apply =0 ; -if (check_index && is_not_gitdir) +if (check_index && !startup_info->have_repository)die ("--index outside a repository" );if (cached) { -if (is_not_gitdir) +if (!startup_info->have_repository)die ("--cached outside a repository" ); check_index =1 ; }
git.c +1 -1
@@ -294,7 +294,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, RUN_SETUP_GENTLY }, { "bisect--helper", cmd_bisect__helper, RUN_SETUP | NEED_WORK_TREE }, { "blame", cmd_blame, RUN_SETUP },
Signature · 1 line
1.7.0.195.g637a2
PATCH 13/18 bundle: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duy--- builtin/bundle.c | 6 ++---- git.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
builtin/bundle.c +2 -4
@@ -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);
git.c +1 -1
@@ -299,7 +299,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,
Signature · 1 line
1.7.0.195.g637a2
PATCH 14/18 diff: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duy--- builtin/diff.c | 6 ++---- git.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
builtin/diff.c +2 -4
@@ -252,7 +252,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)int ents =0 , blobs =0 , paths =0 ;const char *path =NULL ;struct blobinfo blob[2 ]; -int nongit;int result =0 ;/*
@@ -278,7 +277,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)* Other cases are errors. */ - prefix =setup_git_directory_gently (&nongit);git_config (git_diff_ui_config,NULL );if (diff_use_color_default ==-1 )
@@ -287,7 +285,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)init_revisions (&rev, prefix);/* If this is a no-index diff, just run it and exit there. */ -diff_no_index (&rev, argc, argv, nongit, prefix); +diff_no_index (&rev, argc, argv, !startup_info->have_repository, prefix);/* Otherwise, we are doing the usual "git" diff */ rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
@@ -296,7 +294,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)DIFF_OPT_SET (&rev.diffopt,ALLOW_EXTERNAL );DIFF_OPT_SET (&rev.diffopt,ALLOW_TEXTCONV ); -if (nongit) +if (!startup_info->have_repository)die ("Not a git repository" ); argc =setup_revisions (argc, argv, &rev,NULL );if (!rev.diffopt.output_format) {
git.c +1 -1
@@ -315,7 +315,7 @@ static void handle_internal_command(int argc, const char **argv) { "config", cmd_config, RUN_SETUP_GENTLY }, { "count-objects", cmd_count_objects, RUN_SETUP }, { "describe", cmd_describe, RUN_SETUP }, - { "diff", cmd_diff }, + { "diff", cmd_diff, RUN_SETUP_GENTLY }, { "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE }, { "diff-index", cmd_diff_index, RUN_SETUP }, { "diff-tree", cmd_diff_tree, RUN_SETUP },
Signature · 1 line
1.7.0.195.g637a2
PATCH 15/18 help: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duy--- builtin/help.c | 2 -- git.c | 2 +- 2 files changed, 1 insertions(+), 3 deletions(-)
builtin/help.c +0 -2
@@ -414,7 +414,6 @@ static void show_html_page(const char *git_cmd)int cmd_help (int argc,const char **argv,const char *prefix) { -int nongit;const char *alias;enum help_format parsed_help_format;load_command_list ("git-" , &main_cmds, &other_cmds);
@@ -437,7 +436,6 @@ int cmd_help(int argc, const char **argv, const char *prefix)return 0 ; } -setup_git_directory_gently (&nongit);git_config (git_help_config,NULL );if (parsed_help_format !=HELP_FORMAT_NONE )
git.c +1 -1
@@ -331,7 +331,7 @@ static void handle_internal_command(int argc, const char **argv) { "get-tar-commit-id", cmd_get_tar_commit_id }, { "grep", cmd_grep, RUN_SETUP_GENTLY | USE_PAGER }, { "hash-object", cmd_hash_object, RUN_SETUP_GENTLY }, - { "help", cmd_help }, + { "help", cmd_help, RUN_SETUP_GENTLY }, { "index-pack", cmd_index_pack }, { "init", cmd_init_db }, { "init-db", cmd_init_db },
Signature · 1 line
1.7.0.195.g637a2
PATCH 16/18 ls-remote: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duy--- builtin/ls-remote.c | 3 --- git.c | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-)
builtin/ls-remote.c +0 -3
@@ -31,7 +31,6 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) {int i;const char *dest =NULL ; -int nongit;unsigned flags =0 ;const char *uploadpack =NULL ;const char **pattern =NULL ;
@@ -40,8 +39,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];
git.c +2 -2
@@ -338,7 +338,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, RUN_SETUP_GENTLY }, { "mailsplit", cmd_mailsplit }, { "merge", cmd_merge, RUN_SETUP | NEED_WORK_TREE },
@@ -359,7 +359,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 },
Signature · 1 line
1.7.0.195.g637a2
PATCH 17/18 var: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duy"git var" needs to read repository config, so setup gitdir first.
--- builtin/var.c | 2 -- git.c | 2 +- 2 files changed, 1 insertions(+), 3 deletions(-)
builtin/var.c +0 -2
@@ -75,12 +75,10 @@ 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 ) {usage (var_usage); } -setup_git_directory_gently (&nongit); val =NULL ;if (strcmp (argv[1 ],"-l" ) ==0 ) {
git.c +1 -1
@@ -391,7 +391,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 },
Signature · 1 line
1.7.0.195.g637a2
PATCH 18/18 merge-file: use RUN_SETUP_GENTLY
In reply to Nguyễn Thái Ngọc Duy--- builtin/merge-file.c | 4 +--- git.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-)
builtin/merge-file.c +1 -3
@@ -30,7 +30,6 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)int level =XDL_MERGE_ZEALOUS_ALNUM ;int style =0 , quiet =0 ;int favor =0 ; -int nongit;struct option options[] = {OPT_BOOLEAN ('p' ,"stdout" , &to_stdout,"send results to standard output" ),
@@ -45,8 +44,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) OPT_END(), }; - 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)
git.c +1 -1
@@ -343,7 +343,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 },
Signature · 1 line
1.7.0.195.g637a2