Git setup cleanup series
cover Git setup cleanup series
This is the result of my "Remove .git auto detection from setup_git_env()" patch [1]. Basically I make git behave differently (and correctly) when GIT_HARDENED_SETUP=1 to smooth out the migration from the current messy setup to a less messy setup. Eventually GIT_HARDENED_SETUP should be enabled by default and the obsolete code removed, but we're far away from that.
Summary of changes:
- startup_info struct is added to help move up setup_git_directory_gently() to run_builtin(), which reduces lots of headache.
- GIT_HARDENED_SETUP=1 will make git die() whenever setup_git_env() is called from anywhere but setup_git_dir*. It also creates lots of segfault because get_git_dir() and friends now can return NULL.
- gitattr, gitexcludes will not access repository if there is no repository
- enter_repo() will use setup_git_dir* to do the setup
- because non-builtin commands do not have startup_info, they will behave just like before. I'll need to look at them.
Tests are lacking. But you can just try "GIT_HARDENED_SETUP=1 make test" after 04/26, then again at the end of the series to see the difference. It'd be great if people see new failing tests. I'm not sure I have caught them all.
[1] http://mid.gmane.org/[email protected]
Nguyễn Thái Ngọc Duy (26):
rev-parse --git-dir: print relative gitdir correctly setup_git_directory*: Explicitly set git dir
Save setup_git_dir* info globally for later use
Add GIT_HARDENED_SETUP to detect gitdir/worktree related mis-setup errors enter_repo(): use setup_git_directory_gently internally
Tweak init/clone to work properly with GIT_HARDENED_SETUP=1 Support running setup_git_dir_gently() from the beginning for builtin commands
config: move up gitdir setup to run_builtin()
hash-object: move gitdir setup to run_builtin()
shortlog: move up gitdir setup to run_builtin()
Do not look for .git/info/exclude when gitdir is not set up
grep: move up gitdir setup to run_builtin()
USE_PAGER should not be used without RUN_SETUP*
Do not try to read $GIT_DIR/info/attributes if there is no repository
archive: move up gitdir setup to run_builtin()
mailinfo: move up gitdir setup to run_builtin()
check-ref-format: setup gitdir gently
verify-pack: set up gitdir gently
apply: move up gitdir setup to run_builtin()
bundle: move up gitdir setup to run_builtin()
diff: move up gitdir setup to run_builtin()
help: move up gitdir setup to run_builtin()
ls-remote: move up gitdir setup to run_builtin()
var: move up gitdir setup to run_builtin()
merge-file: move up gitdir setup to run_builtin()
Turn on GIT_HARDENED_SETUP for the whole test suite
attr.c | 5 ++- builtin-apply.c | 13 +++---- builtin-archive.c | 2 +- builtin-bundle.c | 6 +-- builtin-config.c | 12 +++--- builtin-diff.c | 6 +-- builtin-grep.c | 9 ++--- builtin-hash-object.c | 9 +++-- builtin-help.c | 2 - builtin-init-db.c | 4 ++ builtin-ls-remote.c | 3 -- builtin-mailinfo.c | 3 -- builtin-merge-file.c | 4 +-- builtin-rev-parse.c | 8 ++++ builtin-shortlog.c | 4 +-- builtin-var.c | 2 - cache.h | 8 ++++ config.c | 17 ++++++--- dir.c | 8 +++-- environment.c | 43 +++++++++++++++++----- git.c | 88 +++++++++++++++++++++++++++++++---------------- path.c | 8 ++--- setup.c | 48 ++++++++++++++++++++------ t/t0024-crlf-archive.sh | 1 + t/t1302-repo-version.sh | 2 +- t/test-lib.sh | 3 ++ 26 files changed, 204 insertions(+), 114 deletions(-)
PATCH 1/26 rev-parse --git-dir: print relative gitdir correctly
When git_dir is relative, it is relative to Git's current working directory, which is worktree top directory. "git rev-parse --git-dir" is expected to output relative to user's current working directory.
Catch this case and make gitdir absolute (the easy way).
---
This one is probably not needed for now. In my later patches, set_git_dir() is used more, and this becomes necessary.
builtin-rev-parse.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
builtin-rev-parse.c +8 -0
@@ -638,6 +638,14 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)const char *gitdir =getenv (GIT_DIR_ENVIRONMENT );static char cwd[PATH_MAX ];if (gitdir) { +if (prefix && !is_absolute_path (gitdir)) { +int len; +if (!getcwd (cwd,PATH_MAX )) +die_errno ("unable to get current working directory" ); + len =strlen (cwd); +printf ("%s%s%s\n" , cwd, len && cwd[len-1 ] !='/' ?"/" :"" , gitdir); +continue ; + }puts (gitdir);continue ; }
Signature · 1 line
1.7.0.195.g637a2
PATCH 2/26 setup_git_directory*: Explicitly set git dir
In reply to Nguyễn Thái Ngọc DuyIf setup_git_directory_gently() and its callers do not set gitdir now, it will be eventually set by setup_git_env(), through obscure call chain. One of the indirect call site is git_config().
My goal is to remove gitdir auto detection in setup_git_env(). So the first step is not depend on that behavior.
--- setup.c | 34 +++++++++++++++++++++++----------- 1 files changed, 23 insertions(+), 11 deletions(-)
setup.c +23 -11
@@ -313,8 +313,12 @@ 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. +* +* After this function is finished, set_git_dir() must be called if a +* a repository is found. Repo format will be checked later by +* setup_git_directory_gently() */ -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 );
@@ -345,18 +349,17 @@ const char *setup_git_directory_gently(int *nongit_ok)const char *retval;if (!work_tree_env) { +/* core.worktree may override worktree */ retval =set_work_tree (gitdirenv); -/* config may override worktree */ -if (check_repository_format_gently (nongit_ok)) -return NULL ; +set_git_dir (gitdirenv);return retval; } -if (check_repository_format_gently (nongit_ok)) -return NULL ; retval =get_relative_cwd (buffer,sizeof (buffer) -1 ,get_git_work_tree ()); -if (!retval || !*retval) +if (!retval || !*retval) { +set_git_dir (gitdirenv);return NULL ; + }set_git_dir (make_absolute_path (gitdirenv));if (chdir (work_tree_env) <0 )die_errno ("Could not chdir to '%s'" , work_tree_env);
@@ -396,8 +399,10 @@ const char *setup_git_directory_gently(int *nongit_ok)die ("Repository setup failed" );break ; } -if (is_git_directory (DEFAULT_GIT_DIR_ENVIRONMENT )) +if (is_git_directory (DEFAULT_GIT_DIR_ENVIRONMENT )) { +set_git_dir (DEFAULT_GIT_DIR_ENVIRONMENT );break ; + }if (is_git_directory ("." )) { inside_git_dir =1 ;if (!work_tree_env)
@@ -407,7 +412,6 @@ const char *setup_git_directory_gently(int *nongit_ok)set_git_dir (cwd); }else set_git_dir ("." ); -check_repository_format_gently (nongit_ok);return NULL ; }while (--offset > ceil_offset && cwd[offset] !='/' );
@@ -428,8 +432,6 @@ const char *setup_git_directory_gently(int *nongit_ok)if (!work_tree_env) inside_work_tree =1 ; git_work_tree_cfg =xstrndup (cwd, offset); -if (check_repository_format_gently (nongit_ok)) -return NULL ;if (offset == len)return NULL ;
@@ -440,6 +442,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 (!nongit_ok || (!*nongit_ok &&check_repository_format_gently (nongit_ok))) + prefix =NULL ; +return prefix; +} +int git_config_perm (const char *var,const char *value) {int i;
Signature · 1 line
1.7.0.195.g637a2
PATCH 3/26 Save setup_git_dir* info globally for later use
In reply to Nguyễn Thái Ngọc DuyFor one thing, this could help catching setup_git_dir being run twice, which is usually wrong.
This also helps moving up setup_git_dir* from inside builtin commands to handle_internal_command(). Without this, run_builtin() needs to find another way to pass "nongit_ok" to builtin commands.
The main program has to intialize startup_info pointer properly. For builtin commands, git.c will take care of that. If startup_info is NULL, the prior behavior should apply.
---
Could have save the command name in startup_info too, so error messages are clearer..
cache.h | 8 ++++++++ environment.c | 1 + git.c | 31 +++++++++++++++++++++++-------- setup.c | 14 +++++++++++++- 4 files changed, 45 insertions(+), 9 deletions(-)
cache.h +8 -0
@@ -1040,4 +1040,12 @@ 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; +int have_set_gitdir; +int have_repository; +}; +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 +23 -8
@@ -13,6 +13,8 @@ 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 opts; +struct startup_info *startup_info;static int use_pager =-1 ;struct pager_config {const char *cmd;
@@ -206,9 +208,6 @@ static int handle_alias(int *argcp, const char ***argv) ret =1 ; } -if (subdir &&chdir (subdir)) -die_errno ("Cannot change to '%s'" , subdir); - errno = saved_errno;return ret;
@@ -234,13 +233,26 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) {int status, help;struct stat st; -const char *prefix; - prefix =NULL ; help = argc ==2 && !strcmp (argv[1 ],"-h" );if (!help) { -if (p->option &RUN_SETUP ) - prefix =setup_git_directory (); +/* handle_alias() may have set up gitdir for alias lookup */ +if (startup_info->have_set_gitdir) { +if (p->option &RUN_SETUP ) { +if (!startup_info->have_repository) +die ("No repository found" ); + } +else { +/* This is WRONG, but we can't get rid of it now */ + startup_info->have_set_gitdir =0 ; +if (startup_info->prefix &&chdir (startup_info->prefix)) +die ("Cannot change to '%s'" , startup_info->prefix); + } + } +else { +if (p->option &RUN_SETUP ) +setup_git_directory (); + }if (use_pager ==-1 && p->option &RUN_SETUP ) use_pager =check_pager_config (p->cmd);
@@ -254,7 +266,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;
@@ -473,6 +485,9 @@ int main(int argc, const char **argv) {const char *cmd; + startup_info = &opts; +memset (startup_info,0 ,sizeof (*startup_info)); + cmd =git_extract_argv0_path (argv[0 ]);if (!cmd) cmd ="git-help" ;
setup.c +13 -1
@@ -236,7 +236,13 @@ void setup_work_tree(void) git_dir =make_absolute_path (git_dir);if (!work_tree ||chdir (work_tree))die ("This operation must be run in a work tree" ); + +/* we know gitdir is already set, we only adjust it to relative path */ +if (startup_info) + startup_info->have_set_gitdir =0 ;set_git_dir (make_relative_path (git_dir, work_tree)); +if (startup_info) + startup_info->have_set_gitdir =1 ; initialized =1 ; }
@@ -447,8 +453,14 @@ const char *setup_git_directory_gently(int *nongit_ok)const char *prefix; prefix =setup_git_directory_gently_1 (nongit_ok); -if (!nongit_ok || (!*nongit_ok &&check_repository_format_gently (nongit_ok))) +if (startup_info) + startup_info->have_set_gitdir =1 ; +if ((!nongit_ok || !*nongit_ok) &&check_repository_format_gently (nongit_ok)) prefix =NULL ; +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 4/26 Add GIT_HARDENED_SETUP to detect gitdir/worktree related mis-setup errors
In reply to Nguyễn Thái Ngọc DuyWhen GIT_DIR environment variable is not specified, .git will be searched if a repository is needed. Currently this can be done in two
places: setup_git_directory_gently() and setup_git_env().
The one in setup_git_env() is no longer correct and should IMHO have been removed since the introduction of setup_git_directory_gently() in d288a70. Having two ways of auto detection may lead to obscure errors because .git may be misdetected by setup_git_env(), automatically called via git_path(), which is all over the place.
This patch makes setup_git_env() die if GIT_DIR is not explictly set. That's setup_git_directory_gently()'s job. If you ever want to touch things inside $GIT_DIR, you should have already called setup_git_directory_gently().
However, doing that will break Git the hard way. So the die()ing behavior will be only triggered if environment variable GIT_HARDENED_SETUP is set. Otherwise old behavior remains. Once all Git commands have been adapted to stay away from the old behavior, the old code can be removed.
--- config.c | 17 ++++++++++++----- environment.c | 42 ++++++++++++++++++++++++++++++++---------- setup.c | 4 +++- 3 files changed, 47 insertions(+), 16 deletions(-)
config.c +12 -5
@@ -704,6 +704,7 @@ int git_config(config_fn_t fn, void *data)int ret =0 , found =0 ;char *repo_config =NULL ;const char *home =NULL ; +const char *hardened_setup =getenv ("GIT_HARDENED_SETUP" );/* Setting $GIT_CONFIG makes git read _only_ the given config file. */ if (config_exclusive_filename)
@@ -724,12 +725,18 @@ int git_config(config_fn_t fn, void *data)free (user_config); } - repo_config =git_pathdup ("config" ); -if (!access (repo_config,R_OK )) { - ret +=git_config_from_file (fn, repo_config, data); - found +=1 ; +if (hardened_setup && !*hardened_setup) + hardened_setup =NULL ; +if (hardened_setup && startup_info && !startup_info->have_set_gitdir) +die ("Try to access a repository before properly setting it up" ); +if (!hardened_setup || !startup_info || startup_info->have_repository) { + repo_config =git_pathdup ("config" ); +if (!access (repo_config,R_OK )) { + ret +=git_config_from_file (fn, repo_config, data); + found +=1 ; + } +free (repo_config); } -free (repo_config);if (found ==0 )return -1 ;return ret;
environment.c +32 -10
71 lines not on this page · raw message
setup.c +3 -1
@@ -453,8 +453,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->have_set_gitdir =1 ; + startup_info->have_repository =get_git_dir () !=NULL ; + }if ((!nongit_ok || !*nongit_ok) &&check_repository_format_gently (nongit_ok)) prefix =NULL ;if (startup_info) {
Signature · 1 line
1.7.0.195.g637a2
PATCH 5/26 enter_repo(): use setup_git_directory_gently internally
In reply to Nguyễn Thái Ngọc Duy--- path.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
path.c +3 -5
@@ -281,6 +281,7 @@ char *enter_repo(char *path, int strict) {static char used_path[PATH_MAX ];static char validated_path[PATH_MAX ]; +int nongit_ok;if (!path)return NULL ;
@@ -334,12 +335,9 @@ char *enter_repo(char *path, int strict)else if (chdir (path))return NULL ; -if (access ("objects" ,X_OK ) ==0 &&access ("refs" ,X_OK ) ==0 && -validate_headref ("HEAD" ) ==0 ) { -set_git_dir ("." ); -check_repository_format (); +setup_git_directory_gently (&nongit_ok); +if (!nongit_ok)return path; - }return NULL ; }
Signature · 1 line
1.7.0.195.g637a2
PATCH 6/26 Tweak init/clone to work properly with GIT_HARDENED_SETUP=1
In reply to Nguyễn Thái Ngọc Duy--- builtin-init-db.c | 4 ++++ t/t0000-basic.sh | 2 ++ t/t0001-init.sh | 2 ++ t/t0003-attributes.sh | 2 ++ t/t5600-clone-fail-cleanup.sh | 2 ++ t/t5601-clone.sh | 2 ++ t/t5602-clone-remote-exec.sh | 2 ++ t/t5700-clone-reference.sh | 2 ++ t/t5701-clone-local.sh | 2 ++ t/t5702-clone-options.sh | 2 ++ t/t5704-bundle.sh | 2 ++ t/t5705-clone-2gb.sh | 2 ++ t/t5706-clone-branch.sh | 2 ++ 13 files changed, 28 insertions(+), 0 deletions(-)
builtin-init-db.c +4 -0
@@ -195,6 +195,7 @@ static int create_default_files(const char *template_path)* from it after installing. */ copy_templates (template_path); + startup_info->have_repository =1 ;git_config (git_default_config,NULL ); is_bare_repository_cfg = init_is_bare_repository;
@@ -286,6 +287,9 @@ int init_db(const char *template_dir, unsigned int flags)char *path;int len, reinit; +/* init_db's caller mush have called set_git_dir() */ + startup_info->have_set_gitdir =1 ; +safe_create_dir (get_git_dir (),0 ); init_is_bare_repository =is_bare_repository ();
t/t0000-basic.sh +2 -0
@@ -28,6 +28,8 @@ then exit 1 fi +export GIT_HARDENED_SETUP=1 + . ./test-lib.sh ################################################################
t/t0001-init.sh +2 -0
@@ -4,6 +4,8 @@ test_description='git init' . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + check_config () { if test -d "$1" && test -f "$1/config" && test -d "$1/refs" then
t/t0003-attributes.sh +2 -0
@@ -4,6 +4,8 @@ test_description=gitattributes . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + attr_check () { path="$1"
t/t5600-clone-fail-cleanup.sh +2 -0
@@ -11,6 +11,8 @@ remove the directory before attempting a clone again.' . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + test_expect_success \ 'clone of non-existent source should fail' \ 'test_must_fail git clone foo bar'
t/t5601-clone.sh +2 -0
@@ -4,6 +4,8 @@ test_description=clone . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + test_expect_success setup ' rm -fr .git &&
t/t5602-clone-remote-exec.sh +2 -0
@@ -4,6 +4,8 @@ test_description=clone . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + test_expect_success setup ' echo "#!/bin/sh" > not_ssh echo "echo \"\$*\" > not_ssh_output" >> not_ssh
t/t5700-clone-reference.sh +2 -0
@@ -6,6 +6,8 @@ test_description='test clone --reference' . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + base_dir=`pwd` U=$base_dir/UPLOAD_LOG
t/t5701-clone-local.sh +2 -0
@@ -3,6 +3,8 @@ test_description='test local clone' . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + D=`pwd` test_expect_success 'preparing origin repository' '
t/t5702-clone-options.sh +2 -0
@@ -3,6 +3,8 @@ test_description='basic clone options' . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + test_expect_success 'setup' ' mkdir parent &&
t/t5704-bundle.sh +2 -0
@@ -3,6 +3,8 @@ test_description='some bundle related tests' . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + test_expect_success 'setup' ' : > file &&
t/t5705-clone-2gb.sh +2 -0
@@ -3,6 +3,8 @@ test_description='Test cloning a repository larger than 2 gigabyte' . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + test -z "$GIT_TEST_CLONE_2GB" && say "Skipping expensive 2GB clone test; enable it with GIT_TEST_CLONE_2GB=t" && test_done &&
t/t5706-clone-branch.sh +2 -0
@@ -3,6 +3,8 @@ test_description='clone --branch option' . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + check_HEAD() { echo refs/heads/"$1" >expect && git symbolic-ref HEAD >actual &&
Signature · 1 line
1.7.0.195.g637a2
PATCH 7/26 Support running setup_git_dir_gently() from the beginning for builtin commands
In reply to Nguyễn Thái Ngọc DuyAttempt to access gitdir is everywhere, even before cmd_*() is called. The sooner we setup gitdir, the less trouble we may have to deal with.
--- git.c | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-)
git.c +13 -3
@@ -215,13 +215,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;
@@ -236,12 +237,17 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) help = argc ==2 && !strcmp (argv[1 ],"-h" );if (!help) { +if ((p->option & (RUN_SETUP |RUN_SETUP_GENTLY )) == (RUN_SETUP |RUN_SETUP_GENTLY )) +die ("Internal error: RUN_SETUP and RUN_SETUP_GENTLY are mutually exclusive" ); +/* handle_alias() may have set up gitdir for alias lookup */ if (startup_info->have_set_gitdir) {if (p->option &RUN_SETUP ) {if (!startup_info->have_repository)die ("No repository found" ); } +if (p->option &RUN_SETUP_GENTLY ) + ;/* all done */ else {/* This is WRONG, but we can't get rid of it now */ startup_info->have_set_gitdir =0 ;
@@ -252,6 +258,10 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)else {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 )
Signature · 1 line
1.7.0.195.g637a2
PATCH 8/26 config: move up gitdir setup to run_builtin()
In reply to Nguyễn Thái Ngọc Duy--- builtin-config.c | 12 ++++++------ git.c | 4 ++-- t/t1302-repo-version.sh | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-)
builtin-config.c +6 -6
@@ -159,7 +159,8 @@ static int get_value(const char *key_, const char *regex_) local = config_exclusive_filename;if (!local) {const char *home =getenv ("HOME" ); - local = repo_config =git_pathdup ("config" ); +if (startup_info->have_repository) + local = repo_config =git_pathdup ("config" );if (git_config_global () && home) global =xstrdup (mkpath ("%s/.gitconfig" , home));if (git_config_system ())
@@ -197,7 +198,8 @@ static int get_value(const char *key_, const char *regex_)git_config_from_file (show_config, system_wide,NULL );if (do_all && global)git_config_from_file (show_config, global,NULL ); -git_config_from_file (show_config, local,NULL ); +if (local) +git_config_from_file (show_config, local,NULL );if (!do_all && !seen && global)git_config_from_file (show_config, global,NULL );if (!do_all && !seen && system_wide)
@@ -326,11 +328,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 +409,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
@@ -322,7 +322,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 },
@@ -378,7 +378,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 },
t/t1302-repo-version.sh +1 -1
@@ -29,7 +29,7 @@ test_expect_success 'gitdir selection on normal repos' ' # Make sure it would stop at test2, not trash test_expect_success 'gitdir selection on unsupported repo' ' (cd test2 && - test "$(git config core.repositoryformatversion)" = 99)' + test "$(git config --file=.git/config core.repositoryformatversion)" = 99)' test_expect_success 'gitdir not required mode' ' (git apply --stat test.patch &&
Signature · 1 line
1.7.0.195.g637a2
PATCH 9/26 hash-object: move gitdir setup to run_builtin()
In reply to Nguyễn Thái Ngọc Duy--- 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
@@ -340,7 +340,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 10/26 shortlog: move up gitdir setup to run_builtin()
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. When the config path is required, setup_git_env() plays hero and set gitdir to ".git". Shortly after, setup_git_dir* is run inside cmd_shortlog() and may move gitdir to somewhere else.
--- builtin-shortlog.c | 4 +--- git.c | 2 +- t/t4201-shortlog.sh | 2 ++ 3 files changed, 4 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 ) {read_from_stdin (&log);
git.c +1 -1
@@ -386,7 +386,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 },
t/t4201-shortlog.sh +2 -0
@@ -8,6 +8,8 @@ test_description='git shortlog . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + echo 1 > a1 git add a1 tree=$(git write-tree)
Signature · 1 line
1.7.0.195.g637a2
PATCH 11/26 Do not look for .git/info/exclude when gitdir is not set up
In reply to Nguyễn Thái Ngọc Duy--- dir.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
dir.c +5 -3
@@ -1024,9 +1024,11 @@ void setup_standard_excludes(struct dir_struct *dir)const char *path; dir->exclude_per_dir =".gitignore" ; - path =git_path ("info/exclude" ); -if (!access (path,R_OK )) -add_excludes_from_file (dir, path); +if (!startup_info || startup_info->have_repository) { + path =git_path ("info/exclude" ); +if (!access (path,R_OK )) +add_excludes_from_file (dir, path); + }if (excludes_file && !access (excludes_file,R_OK ))add_excludes_from_file (dir, excludes_file); }
Signature · 1 line
1.7.0.195.g637a2
PATCH 12/26 grep: move up gitdir setup to run_builtin()
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. When the config path is required, setup_git_env() plays hero and set gitdir to ".git". Shortly after, setup_git_dir* is run inside cmd_shortlog() and may move gitdir to somewhere else.
--- builtin-grep.c | 9 +++------ git.c | 2 +- t/t7002-grep.sh | 2 ++ 3 files changed, 6 insertions(+), 7 deletions(-)
builtin-grep.c +3 -6
@@ -758,7 +758,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" ),
@@ -846,8 +846,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.
@@ -885,9 +883,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
@@ -339,7 +339,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 },
t/t7002-grep.sh +2 -0
@@ -8,6 +8,8 @@ test_description='git grep various. . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + cat >hello.c <<EOF #include <stdio.h> int main(int argc, const char **argv)
Signature · 1 line
1.7.0.195.g637a2
PATCH 13/26 USE_PAGER should not be used without RUN_SETUP*
In reply to Nguyễn Thái Ngọc Duy--- git.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
git.c +4 -1
@@ -266,8 +266,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 14/26 Do not try to read $GIT_DIR/info/attributes if there is no repository
In reply to Nguyễn Thái Ngọc Duy--- attr.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
attr.c +4 -1
@@ -480,7 +480,10 @@ static void bootstrap_attr_stack(void)debug_push (elem); } - elem =read_attr_from_file (git_path (INFOATTRIBUTES_FILE ),1 ); +if (!startup_info || startup_info->have_repository) + elem =read_attr_from_file (git_path (INFOATTRIBUTES_FILE ),1 ); +else + elem =NULL ;if (!elem) elem =xcalloc (1 ,sizeof (*elem)); elem->origin =NULL ;
Signature · 1 line
1.7.0.195.g637a2
PATCH 15/26 archive: move up gitdir setup to run_builtin()
In reply to Nguyễn Thái Ngọc Duy--- builtin-archive.c | 2 +- git.c | 4 ++-- t/t0024-crlf-archive.sh | 3 +++ t/t5000-tar-tree.sh | 2 ++ t/t5001-archive-attr.sh | 2 ++ 5 files changed, 10 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
@@ -308,7 +308,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 },
@@ -396,7 +396,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 },
t/t0024-crlf-archive.sh +3 -0
@@ -3,6 +3,9 @@ test_description='respect crlf in git archive' . ./test-lib.sh + +export GIT_HARDENED_SETUP=1 + UNZIP=${UNZIP:-unzip} test_expect_success setup '
t/t5000-tar-tree.sh +2 -0
@@ -29,6 +29,8 @@ UNZIP=${UNZIP:-unzip} SUBSTFORMAT=%H%n +export GIT_HARDENED_SETUP=1 + test_expect_success \ 'populate workdir' \ 'mkdir a b c &&
t/t5001-archive-attr.sh +2 -0
@@ -4,6 +4,8 @@ test_description='git archive attribute tests' . ./test-lib.sh +export GIT_HARDENED_SETUP=1 + SUBSTFORMAT=%H%n test_expect_exists() {
Signature · 1 line
1.7.0.195.g637a2
PATCH 16/26 mailinfo: move up gitdir setup to run_builtin()
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
@@ -1027,9 +1027,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
@@ -352,7 +352,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 17/26 check-ref-format: setup gitdir 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
@@ -317,7 +317,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 18/26 verify-pack: set up gitdir 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
@@ -408,7 +408,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 19/26 apply: move up gitdir setup to run_builtin()
In reply to Nguyễn Thái Ngọc Duy--- builtin-apply.c | 13 ++++++------- git.c | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-)
builtin-apply.c +6 -7
@@ -26,7 +26,7 @@* --cached updates only the cache without ever touching the working tree. */ static const char *prefix; -static int prefix_length =-1 ; +static int prefix_length;static int newfd =-1 ;static int unidiff_zero;
@@ -2441,7 +2441,7 @@ static int apply_binary(struct image *img, struct patch *patch)return 0 ;/* deletion patch */ } -if (has_sha1_file (sha1)) { +if (startup_info->have_repository &&has_sha1_file (sha1)) {/* We already have the postimage */ enum object_type type;unsigned long size;
@@ -3512,11 +3512,10 @@ 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 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 = 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
@@ -307,7 +307,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 20/26 bundle: move up gitdir setup to run_builtin()
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
@@ -312,7 +312,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 21/26 diff: move up gitdir setup to run_builtin()
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
@@ -328,7 +328,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 22/26 help: move up gitdir setup to run_builtin()
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
@@ -344,7 +344,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 23/26 ls-remote: move up gitdir setup to run_builtin()
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
@@ -351,7 +351,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 },
@@ -371,7 +371,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 24/26 var: move up gitdir setup to run_builtin()
In reply to Nguyễn Thái Ngọc Duy--- 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
@@ -403,7 +403,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 25/26 merge-file: move up gitdir setup to run_builtin()
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
@@ -356,7 +356,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
PATCH 26/26 Turn on GIT_HARDENED_SETUP for the whole test suite
In reply to Nguyễn Thái Ngọc Duy--- t/t0000-basic.sh | 2 -- t/t0001-init.sh | 2 -- t/t0003-attributes.sh | 2 -- t/t0024-crlf-archive.sh | 2 -- t/t4201-shortlog.sh | 2 -- t/t5000-tar-tree.sh | 2 -- t/t5001-archive-attr.sh | 2 -- t/t5600-clone-fail-cleanup.sh | 2 -- t/t5601-clone.sh | 2 -- t/t5602-clone-remote-exec.sh | 2 -- t/t5700-clone-reference.sh | 2 -- t/t5701-clone-local.sh | 2 -- t/t5702-clone-options.sh | 2 -- t/t5704-bundle.sh | 2 -- t/t5705-clone-2gb.sh | 2 -- t/t5706-clone-branch.sh | 2 -- t/t7002-grep.sh | 2 -- t/test-lib.sh | 3 +++ 18 files changed, 3 insertions(+), 34 deletions(-)
t/t0000-basic.sh +0 -2
@@ -28,8 +28,6 @@ then exit 1 fi -export GIT_HARDENED_SETUP=1 - . ./test-lib.sh ################################################################
t/t0001-init.sh +0 -2
@@ -4,8 +4,6 @@ test_description='git init' . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - check_config () { if test -d "$1" && test -f "$1/config" && test -d "$1/refs" then
t/t0003-attributes.sh +0 -2
@@ -4,8 +4,6 @@ test_description=gitattributes . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - attr_check () { path="$1"
t/t0024-crlf-archive.sh +0 -2
@@ -4,8 +4,6 @@ test_description='respect crlf in git archive' . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - UNZIP=${UNZIP:-unzip} test_expect_success setup '
t/t4201-shortlog.sh +0 -2
@@ -8,8 +8,6 @@ test_description='git shortlog . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - echo 1 > a1 git add a1 tree=$(git write-tree)
t/t5000-tar-tree.sh +0 -2
@@ -29,8 +29,6 @@ UNZIP=${UNZIP:-unzip} SUBSTFORMAT=%H%n -export GIT_HARDENED_SETUP=1 - test_expect_success \ 'populate workdir' \ 'mkdir a b c &&
t/t5001-archive-attr.sh +0 -2
@@ -4,8 +4,6 @@ test_description='git archive attribute tests' . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - SUBSTFORMAT=%H%n test_expect_exists() {
t/t5600-clone-fail-cleanup.sh +0 -2
@@ -11,8 +11,6 @@ remove the directory before attempting a clone again.' . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - test_expect_success \ 'clone of non-existent source should fail' \ 'test_must_fail git clone foo bar'
t/t5601-clone.sh +0 -2
@@ -4,8 +4,6 @@ test_description=clone . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - test_expect_success setup ' rm -fr .git &&
t/t5602-clone-remote-exec.sh +0 -2
@@ -4,8 +4,6 @@ test_description=clone . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - test_expect_success setup ' echo "#!/bin/sh" > not_ssh echo "echo \"\$*\" > not_ssh_output" >> not_ssh
t/t5700-clone-reference.sh +0 -2
@@ -6,8 +6,6 @@ test_description='test clone --reference' . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - base_dir=`pwd` U=$base_dir/UPLOAD_LOG
t/t5701-clone-local.sh +0 -2
@@ -3,8 +3,6 @@ test_description='test local clone' . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - D=`pwd` test_expect_success 'preparing origin repository' '
t/t5702-clone-options.sh +0 -2
@@ -3,8 +3,6 @@ test_description='basic clone options' . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - test_expect_success 'setup' ' mkdir parent &&
t/t5704-bundle.sh +0 -2
@@ -3,8 +3,6 @@ test_description='some bundle related tests' . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - test_expect_success 'setup' ' : > file &&
t/t5705-clone-2gb.sh +0 -2
@@ -3,8 +3,6 @@ test_description='Test cloning a repository larger than 2 gigabyte' . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - test -z "$GIT_TEST_CLONE_2GB" && say "Skipping expensive 2GB clone test; enable it with GIT_TEST_CLONE_2GB=t" && test_done &&
t/t5706-clone-branch.sh +0 -2
@@ -3,8 +3,6 @@ test_description='clone --branch option' . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - check_HEAD() { echo refs/heads/"$1" >expect && git symbolic-ref HEAD >actual &&
t/t7002-grep.sh +0 -2
@@ -8,8 +8,6 @@ test_description='git grep various. . ./test-lib.sh -export GIT_HARDENED_SETUP=1 - cat >hello.c <<EOF #include <stdio.h> int main(int argc, const char **argv)
t/test-lib.sh +3 -0
@@ -61,6 +61,9 @@ export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export EDITOR GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u} +GIT_HARDENED_SETUP=1 +export GIT_HARDENED_SETUP + # Protect ourselves from common misconfiguration to export # CDPATH into the environment unset CDPATH
Signature · 1 line
1.7.0.195.g637a2