summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-12-05 19:42:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-12-05 19:42:26 (GMT)
commit7f2186cadf4844616065c6175f179f1184c8fa75 (patch)
tree57710b1f4fefd930f13f89ca52ff6d930f2cde93 /git.c
parentc21df07886bb07a893609ff242e29b1493da1fd8 (diff)
parentc4f901d1593f3ef097c3e73daa2847ed9ad9efe0 (diff)
downloadgit-7f2186cadf4844616065c6175f179f1184c8fa75.zip
git-7f2186cadf4844616065c6175f179f1184c8fa75.tar.gz
git-7f2186cadf4844616065c6175f179f1184c8fa75.tar.bz2
Merge branch 'sv/get-builtin'
* sv/get-builtin: builtin: move builtin retrieval to get_builtin()
Diffstat (limited to 'git.c')
-rw-r--r--git.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/git.c b/git.c
index 18fbf79..82d7a1c 100644
--- a/git.c
+++ b/git.c
@@ -487,15 +487,20 @@ static struct cmd_struct commands[] = {
{ "write-tree", cmd_write_tree, RUN_SETUP },
};
-int is_builtin(const char *s)
+static struct cmd_struct *get_builtin(const char *s)
{
int 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))
- 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)
@@ -503,6 +508,7 @@ static void handle_builtin(int argc, const char **argv)
const char *cmd = argv[0];
int i;
static const char ext[] = STRIP_EXTENSION;
+ struct cmd_struct *builtin;
if (sizeof(ext) > 1) {
i = strlen(argv[0]) - strlen(ext);
@@ -519,15 +525,12 @@ static void handle_builtin(int argc, const char **argv)
argv[0] = cmd = "help";
}
- for (i = 0; i < ARRAY_SIZE(commands); i++) {
- struct cmd_struct *p = commands+i;
- if (strcmp(p->cmd, cmd))
- continue;
- if (saved_environment && (p->option & NO_SETUP)) {
+ builtin = get_builtin(cmd);
+ if (builtin) {
+ if (saved_environment && (builtin->option & NO_SETUP))
restore_env();
- break;
- }
- exit(run_builtin(p, argc, argv));
+ else
+ exit(run_builtin(builtin, argc, argv));
}
}