Skip to content

Commit 7f2186c

Browse files
committed
Merge branch 'sv/get-builtin'
* sv/get-builtin: builtin: move builtin retrieval to get_builtin()
2 parents c21df07 + c4f901d commit 7f2186c

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

git.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -487,22 +487,28 @@ static struct cmd_struct commands[] = {
487487
{ "write-tree", cmd_write_tree, RUN_SETUP },
488488
};
489489

490-
int is_builtin(const char *s)
490+
static struct cmd_struct *get_builtin(const char *s)
491491
{
492492
int i;
493493
for (i = 0; i < ARRAY_SIZE(commands); i++) {
494-
struct cmd_struct *p = commands+i;
494+
struct cmd_struct *p = commands + i;
495495
if (!strcmp(s, p->cmd))
496-
return 1;
496+
return p;
497497
}
498-
return 0;
498+
return NULL;
499+
}
500+
501+
int is_builtin(const char *s)
502+
{
503+
return !!get_builtin(s);
499504
}
500505

501506
static void handle_builtin(int argc, const char **argv)
502507
{
503508
const char *cmd = argv[0];
504509
int i;
505510
static const char ext[] = STRIP_EXTENSION;
511+
struct cmd_struct *builtin;
506512

507513
if (sizeof(ext) > 1) {
508514
i = strlen(argv[0]) - strlen(ext);
@@ -519,15 +525,12 @@ static void handle_builtin(int argc, const char **argv)
519525
argv[0] = cmd = "help";
520526
}
521527

522-
for (i = 0; i < ARRAY_SIZE(commands); i++) {
523-
struct cmd_struct *p = commands+i;
524-
if (strcmp(p->cmd, cmd))
525-
continue;
526-
if (saved_environment && (p->option & NO_SETUP)) {
528+
builtin = get_builtin(cmd);
529+
if (builtin) {
530+
if (saved_environment && (builtin->option & NO_SETUP))
527531
restore_env();
528-
break;
529-
}
530-
exit(run_builtin(p, argc, argv));
532+
else
533+
exit(run_builtin(builtin, argc, argv));
531534
}
532535
}
533536

0 commit comments

Comments
 (0)