|
|
@ -9,6 +9,43 @@ const char git_usage_string[] = |
|
|
|
const char git_more_info_string[] = |
|
|
|
const char git_more_info_string[] = |
|
|
|
"See 'git help COMMAND' for more information on a specific command."; |
|
|
|
"See 'git help COMMAND' for more information on a specific command."; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int use_pager = -1; |
|
|
|
|
|
|
|
struct pager_config { |
|
|
|
|
|
|
|
const char *cmd; |
|
|
|
|
|
|
|
int val; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)) |
|
|
|
|
|
|
|
c->val = git_config_bool(var, 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.val = -1; |
|
|
|
|
|
|
|
git_config(pager_command_config, &c); |
|
|
|
|
|
|
|
return c.val; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void commit_pager_choice(void) { |
|
|
|
|
|
|
|
switch (use_pager) { |
|
|
|
|
|
|
|
case 0: |
|
|
|
|
|
|
|
setenv("GIT_PAGER", "cat", 1); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 1: |
|
|
|
|
|
|
|
setup_pager(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int handle_options(const char*** argv, int* argc, int* envchanged) |
|
|
|
static int handle_options(const char*** argv, int* argc, int* envchanged) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int handled = 0; |
|
|
|
int handled = 0; |
|
|
@ -38,9 +75,9 @@ static int handle_options(const char*** argv, int* argc, int* envchanged) |
|
|
|
exit(0); |
|
|
|
exit(0); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { |
|
|
|
} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) { |
|
|
|
setup_pager(); |
|
|
|
use_pager = 1; |
|
|
|
} else if (!strcmp(cmd, "--no-pager")) { |
|
|
|
} else if (!strcmp(cmd, "--no-pager")) { |
|
|
|
setenv("GIT_PAGER", "cat", 1); |
|
|
|
use_pager = 0; |
|
|
|
if (envchanged) |
|
|
|
if (envchanged) |
|
|
|
*envchanged = 1; |
|
|
|
*envchanged = 1; |
|
|
|
} else if (!strcmp(cmd, "--git-dir")) { |
|
|
|
} else if (!strcmp(cmd, "--git-dir")) { |
|
|
@ -242,8 +279,13 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv) |
|
|
|
prefix = NULL; |
|
|
|
prefix = NULL; |
|
|
|
if (p->option & RUN_SETUP) |
|
|
|
if (p->option & RUN_SETUP) |
|
|
|
prefix = setup_git_directory(); |
|
|
|
prefix = setup_git_directory(); |
|
|
|
if (p->option & USE_PAGER) |
|
|
|
|
|
|
|
setup_pager(); |
|
|
|
if (use_pager == -1 && p->option & RUN_SETUP) |
|
|
|
|
|
|
|
use_pager = check_pager_config(p->cmd); |
|
|
|
|
|
|
|
if (use_pager == -1 && p->option & USE_PAGER) |
|
|
|
|
|
|
|
use_pager = 1; |
|
|
|
|
|
|
|
commit_pager_choice(); |
|
|
|
|
|
|
|
|
|
|
|
if (p->option & NEED_WORK_TREE) |
|
|
|
if (p->option & NEED_WORK_TREE) |
|
|
|
setup_work_tree(); |
|
|
|
setup_work_tree(); |
|
|
|
|
|
|
|
|
|
|
@ -466,6 +508,7 @@ int main(int argc, const char **argv) |
|
|
|
argv++; |
|
|
|
argv++; |
|
|
|
argc--; |
|
|
|
argc--; |
|
|
|
handle_options(&argv, &argc, NULL); |
|
|
|
handle_options(&argv, &argc, NULL); |
|
|
|
|
|
|
|
commit_pager_choice(); |
|
|
|
if (argc > 0) { |
|
|
|
if (argc > 0) { |
|
|
|
if (!prefixcmp(argv[0], "--")) |
|
|
|
if (!prefixcmp(argv[0], "--")) |
|
|
|
argv[0] += 2; |
|
|
|
argv[0] += 2; |
|
|
|