1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-20 12:16:07 +02:00

builtin/help.c: speed up is_git_command() by checking for builtin commands first

Since 2dce956 is_git_command() is a bit slow as it does file I/O in
the call to list_commands_in_dir(). Avoid the file I/O by adding an
early check for the builtin commands.

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Sebastian Schuberth 2014-01-02 17:17:11 +01:00 committed by Junio C Hamano
parent a3c5263438
commit c6127fa3e2
4 changed files with 134 additions and 117 deletions

View File

@ -14,8 +14,8 @@ Git:
. Add the external declaration for the function to `builtin.h`.
. Add the command to `commands[]` table in `handle_builtin()`,
defined in `git.c`. The entry should look like:
. Add the command to the `commands[]` table defined in `git.c`.
The entry should look like:
{ "foo", cmd_foo, <options> },
+

View File

@ -27,6 +27,8 @@ extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, int sha1_valid, char **buf, unsigned long *buf_size);
extern int is_builtin(const char *s);
extern int cmd_add(int argc, const char **argv, const char *prefix);
extern int cmd_annotate(int argc, const char **argv, const char *prefix);
extern int cmd_apply(int argc, const char **argv, const char *prefix);

View File

@ -288,6 +288,9 @@ static struct cmdnames main_cmds, other_cmds;
static int is_git_command(const char *s)
{
if (is_builtin(s))
return 1;
load_command_list("git-", &main_cmds, &other_cmds);
return is_in_cmdlist(&main_cmds, s) ||
is_in_cmdlist(&other_cmds, s);

18
git.c
View File

@ -332,9 +332,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
return 0;
}
static void handle_builtin(int argc, const char **argv)
{
const char *cmd = argv[0];
static struct cmd_struct commands[] = {
{ "add", cmd_add, RUN_SETUP | NEED_WORK_TREE },
{ "annotate", cmd_annotate, RUN_SETUP },
@ -450,6 +447,21 @@ static void handle_builtin(int argc, const char **argv)
{ "whatchanged", cmd_whatchanged, RUN_SETUP },
{ "write-tree", cmd_write_tree, RUN_SETUP },
};
int is_builtin(const char *s)
{
int i;
for (i = 0; i < ARRAY_SIZE(commands); i++) {
struct cmd_struct *p = commands+i;
if (!strcmp(s, p->cmd))
return 1;
}
return 0;
}
static void handle_builtin(int argc, const char **argv)
{
const char *cmd = argv[0];
int i;
static const char ext[] = STRIP_EXTENSION;