1
0
mirror of https://github.com/git/git.git synced 2025-03-30 19:10:25 +00:00

Merge branch 'sv/get-builtin'

* sv/get-builtin:
  builtin: move builtin retrieval to get_builtin()
This commit is contained in:
Junio C Hamano 2014-12-05 11:42:26 -08:00
commit 7f2186cadf

27
git.c
View File

@ -487,15 +487,20 @@ static struct cmd_struct commands[] = {
{ "write-tree", cmd_write_tree, RUN_SETUP }, { "write-tree", cmd_write_tree, RUN_SETUP },
}; };
int is_builtin(const char *s) static struct cmd_struct *get_builtin(const char *s)
{ {
int i; int i;
for (i = 0; i < ARRAY_SIZE(commands); i++) { for (i = 0; i < ARRAY_SIZE(commands); i++) {
struct cmd_struct *p = commands+i; struct cmd_struct *p = commands + i;
if (!strcmp(s, p->cmd)) if (!strcmp(s, p->cmd))
return 1; return p;
} }
return 0; return NULL;
}
int is_builtin(const char *s)
{
return !!get_builtin(s);
} }
static void handle_builtin(int argc, const char **argv) static void handle_builtin(int argc, const char **argv)
@ -503,6 +508,7 @@ static void handle_builtin(int argc, const char **argv)
const char *cmd = argv[0]; const char *cmd = argv[0];
int i; int i;
static const char ext[] = STRIP_EXTENSION; static const char ext[] = STRIP_EXTENSION;
struct cmd_struct *builtin;
if (sizeof(ext) > 1) { if (sizeof(ext) > 1) {
i = strlen(argv[0]) - strlen(ext); i = strlen(argv[0]) - strlen(ext);
@ -519,15 +525,12 @@ static void handle_builtin(int argc, const char **argv)
argv[0] = cmd = "help"; argv[0] = cmd = "help";
} }
for (i = 0; i < ARRAY_SIZE(commands); i++) { builtin = get_builtin(cmd);
struct cmd_struct *p = commands+i; if (builtin) {
if (strcmp(p->cmd, cmd)) if (saved_environment && (builtin->option & NO_SETUP))
continue;
if (saved_environment && (p->option & NO_SETUP)) {
restore_env(); restore_env();
break; else
} exit(run_builtin(builtin, argc, argv));
exit(run_builtin(p, argc, argv));
} }
} }