diff options
Diffstat (limited to 'git.c')
| -rw-r--r-- | git.c | 71 | 
1 files changed, 33 insertions, 38 deletions
@@ -4,52 +4,22 @@  #include "help.h"  #include "quote.h"  #include "run-command.h" +#include "commit.h"  const char git_usage_string[] = -	"git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n" +	"git [--version] [--help] [-c name=value]\n" +	"           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n"  	"           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\n"  	"           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n" -	"           [-c name=value] [--help]\n"  	"           <command> [<args>]";  const char git_more_info_string[] = -	N_("See 'git help <command>' for more information on a specific command."); +	N_("'git help -a' and 'git help -g' lists available subcommands and some\n" +	   "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; -struct pager_config { -	const char *cmd; -	int want; -	char *value; -}; - -static int pager_command_config(const char *var, const char *value, void *data) -{ -	struct pager_config *c = data; -	if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd)) { -		int b = git_config_maybe_bool(var, value); -		if (b >= 0) -			c->want = b; -		else { -			c->want = 1; -			c->value = xstrdup(value); -		} -	} -	return 0; -} - -/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */ -int check_pager_config(const char *cmd) -{ -	struct pager_config c; -	c.cmd = cmd; -	c.want = -1; -	c.value = NULL; -	git_config(pager_command_config, &c); -	if (c.value) -		pager_program = c.value; -	return c.want; -}  static void commit_pager_choice(void) {  	switch (use_pager) { @@ -158,6 +128,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)  			static char git_dir[PATH_MAX+1];  			is_bare_repository_cfg = 1;  			setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0); +			setenv(GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, "0", 1);  			if (envchanged)  				*envchanged = 1;  		} else if (!strcmp(cmd, "-c")) { @@ -168,6 +139,20 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)  			git_config_push_parameter((*argv)[1]);  			(*argv)++;  			(*argc)--; +		} else if (!strcmp(cmd, "--literal-pathspecs")) { +			setenv(GIT_LITERAL_PATHSPECS_ENVIRONMENT, "1", 1); +			if (envchanged) +				*envchanged = 1; +		} else if (!strcmp(cmd, "--no-literal-pathspecs")) { +			setenv(GIT_LITERAL_PATHSPECS_ENVIRONMENT, "0", 1); +			if (envchanged) +				*envchanged = 1; +		} else if (!strcmp(cmd, "--shallow-file")) { +			(*argv)++; +			(*argc)--; +			set_alternate_shallow_file((*argv)[0]); +			if (envchanged) +				*envchanged = 1;  		} else {  			fprintf(stderr, "Unknown option: %s\n", cmd);  			usage(git_usage_string); @@ -338,6 +323,8 @@ static void handle_internal_command(int argc, const char **argv)  		{ "bundle", cmd_bundle, RUN_SETUP_GENTLY },  		{ "cat-file", cmd_cat_file, RUN_SETUP },  		{ "check-attr", cmd_check_attr, RUN_SETUP }, +		{ "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE }, +		{ "check-mailmap", cmd_check_mailmap, RUN_SETUP },  		{ "check-ref-format", cmd_check_ref_format },  		{ "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },  		{ "checkout-index", cmd_checkout_index, @@ -528,8 +515,9 @@ static int run_argv(int *argcp, const char ***argv)  } -int main(int argc, const char **argv) +int main(int argc, char **av)  { +	const char **argv = (const char **) av;  	const char *cmd;  	startup_info = &git_startup_info; @@ -538,6 +526,13 @@ int main(int argc, const char **argv)  	if (!cmd)  		cmd = "git-help"; +	/* +	 * Always open file descriptors 0/1/2 to avoid clobbering files +	 * in die().  It also avoids messing up when the pipes are dup'ed +	 * onto stdin/stdout/stderr in the child processes we spawn. +	 */ +	sanitize_stdfds(); +  	git_setup_gettext();  	/* @@ -569,7 +564,7 @@ int main(int argc, const char **argv)  		commit_pager_choice();  		printf("usage: %s\n\n", git_usage_string);  		list_common_cmds_help(); -		printf("\n%s\n", git_more_info_string); +		printf("\n%s\n", _(git_more_info_string));  		exit(1);  	}  	cmd = argv[0];  | 
