summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-03-05 17:10:27 -0500
committerJunio C Hamano <gitster@pobox.com>2016-03-06 17:17:37 -0800
commit46c3cd44d7a1e8a33ad66c017ac9e3575cc88c00 (patch)
tree09bc57d17220e4c424bbd1492b203b06f134cd1f /git.c
parentab5d01a29eb7380ceab070f0807c2939849c44bc (diff)
downloadgit-46c3cd44d7a1e8a33ad66c017ac9e3575cc88c00.tar.gz
setup: make startup_info available everywhere
Commit a60645f (setup: remember whether repository was found, 2010-08-05) introduced the startup_info structure, which records some parts of the setup_git_directory() process (notably, whether we actually found a repository or not). One of the uses of this data is for functions to behave appropriately based on whether we are in a repo. But the startup_info struct is just a pointer to storage provided by the main program, and the only program that sets it up is the git.c wrapper. Thus builtins have access to startup_info, but externally linked programs do not. Worse, library code which is accessible from both has to be careful about accessing startup_info. This can be used to trigger a die("BUG") via get_sha1(): $ git fast-import <<-\EOF tag foo from HEAD:./whatever EOF fatal: BUG: startup_info struct is not initialized. Obviously that's fairly nonsensical input to feed to fast-import, but we should never hit a die("BUG"). And there may be other ways to trigger it if other non-builtins resolve sha1s. So let's point the storage for startup_info to a static variable in setup.c, making it available to all users of the library code. We _could_ turn startup_info into a regular extern struct, but doing so would mean tweaking all of the existing use sites. So let's leave the pointer indirection in place. We can, however, drop any checks for NULL, as they will always be false (and likewise, we can drop the test covering this case, which was a rather artificial situation using one of the test-* programs). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git.c')
-rw-r--r--git.c3
1 files changed, 0 insertions, 3 deletions
diff --git a/git.c b/git.c
index 6cc0c077f9..968a8a4645 100644
--- a/git.c
+++ b/git.c
@@ -15,7 +15,6 @@ const char git_more_info_string[] =
"concept guides. See 'git help <command>' or 'git help <concept>'\n"
"to read about a specific subcommand or concept.");
-static struct startup_info git_startup_info;
static int use_pager = -1;
static char *orig_cwd;
static const char *env_names[] = {
@@ -637,8 +636,6 @@ int main(int argc, char **av)
const char *cmd;
int done_help = 0;
- startup_info = &git_startup_info;
-
cmd = git_extract_argv0_path(argv[0]);
if (!cmd)
cmd = "git-help";