{"thread":{"id":"35588","subject":"[PATCH 1/2] Call load_command_list() only when it is needed","startedAt":"2013-12-30T21:05:44Z","lastAt":"2014-01-02T12:46:22Z","messageCount":4,"participants":["Sebastian Schuberth","Christian Couder"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"232531","messageId":"52C1E028.8000004@gmail.com","threadId":"35588","inReplyTo":null,"subject":"[PATCH 1/2] Call load_command_list() only when it is needed","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2013-12-30T21:05:44Z","receivedAt":"2013-12-30T21:05:44Z","isPatch":true,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"This avoids list_commands_in_dir() being called when not needed which is\nquite slow due to file I/O in order to list matching files in a directory.\n\nSigned-off-by: Sebastian Schuberth <sschuberth@gmail.com>\n---\n builtin/help.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/help.c b/builtin/help.c\nindex cc17e67..b6fc15e 100644\n--- a/builtin/help.c\n+++ b/builtin/help.c\n@@ -288,6 +288,7 @@ static struct cmdnames main_cmds, other_cmds;\n \n static int is_git_command(const char *s)\n {\n+\tload_command_list(\"git-\", &main_cmds, &other_cmds);\n \treturn is_in_cmdlist(&main_cmds, s) ||\n \t\tis_in_cmdlist(&other_cmds, s);\n }\n@@ -449,7 +450,6 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \tint nongit;\n \tconst char *alias;\n \tenum help_format parsed_help_format;\n-\tload_command_list(\"git-\", &main_cmds, &other_cmds);\n \n \targc = parse_options(argc, argv, prefix, builtin_help_options,\n \t\t\tbuiltin_help_usage, 0);\n@@ -458,6 +458,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \tif (show_all) {\n \t\tgit_config(git_help_config, NULL);\n \t\tprintf(_(\"usage: %s%s\"), _(git_usage_string), \"\\n\\n\");\n+\t\tload_command_list(\"git-\", &main_cmds, &other_cmds);\n \t\tlist_commands(colopts, &main_cmds, &other_cmds);\n \t}\n \n-- \n1.8.4.msysgit.0\n"},{"id":"232532","messageId":"52C1E09A.8040907@gmail.com","threadId":"35588","inReplyTo":"52C1E028.8000004@gmail.com","subject":"[PATCH 2/2] Speed up is_git_command() by checking early for internal commands","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2013-12-30T21:07:38Z","receivedAt":"2013-12-30T21:07:38Z","isPatch":true,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"Since 2dce956 is_git_command() was a bit slow as it does file I/O in the\ncall to list_commands_in_dir(). Avoid the file I/O by adding an early\ncheck for internal commands.\n\nSigned-off-by: Sebastian Schuberth <sschuberth@gmail.com>\n---\n builtin/help.c |   5 ++\n git.c          | 242 ++++++++++++++++++++++++++++++---------------------------\n 2 files changed, 132 insertions(+), 115 deletions(-)\n\ndiff --git a/builtin/help.c b/builtin/help.c\nindex b6fc15e..1f0261e 100644\n--- a/builtin/help.c\n+++ b/builtin/help.c\n@@ -284,10 +284,15 @@ static int git_help_config(const char *var, const char *value, void *cb)\n \treturn git_default_config(var, value, cb);\n }\n \n+extern int is_internal_command(const char *s);\n+\n static struct cmdnames main_cmds, other_cmds;\n \n static int is_git_command(const char *s)\n {\n+\tif (is_internal_command(s))\n+\t\treturn 1;\n+\n \tload_command_list(\"git-\", &main_cmds, &other_cmds);\n \treturn is_in_cmdlist(&main_cmds, s) ||\n \t\tis_in_cmdlist(&other_cmds, s);\ndiff --git a/git.c b/git.c\nindex 3799514..cc81138 100644\n--- a/git.c\n+++ b/git.c\n@@ -332,124 +332,136 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)\n \treturn 0;\n }\n \n+static struct cmd_struct commands[] = {\n+\t{ \"add\", cmd_add, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"annotate\", cmd_annotate, RUN_SETUP },\n+\t{ \"apply\", cmd_apply, RUN_SETUP_GENTLY },\n+\t{ \"archive\", cmd_archive },\n+\t{ \"bisect--helper\", cmd_bisect__helper, RUN_SETUP },\n+\t{ \"blame\", cmd_blame, RUN_SETUP },\n+\t{ \"branch\", cmd_branch, RUN_SETUP },\n+\t{ \"bundle\", cmd_bundle, RUN_SETUP_GENTLY },\n+\t{ \"cat-file\", cmd_cat_file, RUN_SETUP },\n+\t{ \"check-attr\", cmd_check_attr, RUN_SETUP },\n+\t{ \"check-ignore\", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"check-mailmap\", cmd_check_mailmap, RUN_SETUP },\n+\t{ \"check-ref-format\", cmd_check_ref_format },\n+\t{ \"checkout\", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"checkout-index\", cmd_checkout_index,\n+\t\tRUN_SETUP | NEED_WORK_TREE},\n+\t{ \"cherry\", cmd_cherry, RUN_SETUP },\n+\t{ \"cherry-pick\", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"clean\", cmd_clean, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"clone\", cmd_clone },\n+\t{ \"column\", cmd_column, RUN_SETUP_GENTLY },\n+\t{ \"commit\", cmd_commit, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"commit-tree\", cmd_commit_tree, RUN_SETUP },\n+\t{ \"config\", cmd_config, RUN_SETUP_GENTLY },\n+\t{ \"count-objects\", cmd_count_objects, RUN_SETUP },\n+\t{ \"credential\", cmd_credential, RUN_SETUP_GENTLY },\n+\t{ \"describe\", cmd_describe, RUN_SETUP },\n+\t{ \"diff\", cmd_diff },\n+\t{ \"diff-files\", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"diff-index\", cmd_diff_index, RUN_SETUP },\n+\t{ \"diff-tree\", cmd_diff_tree, RUN_SETUP },\n+\t{ \"fast-export\", cmd_fast_export, RUN_SETUP },\n+\t{ \"fetch\", cmd_fetch, RUN_SETUP },\n+\t{ \"fetch-pack\", cmd_fetch_pack, RUN_SETUP },\n+\t{ \"fmt-merge-msg\", cmd_fmt_merge_msg, RUN_SETUP },\n+\t{ \"for-each-ref\", cmd_for_each_ref, RUN_SETUP },\n+\t{ \"format-patch\", cmd_format_patch, RUN_SETUP },\n+\t{ \"fsck\", cmd_fsck, RUN_SETUP },\n+\t{ \"fsck-objects\", cmd_fsck, RUN_SETUP },\n+\t{ \"gc\", cmd_gc, RUN_SETUP },\n+\t{ \"get-tar-commit-id\", cmd_get_tar_commit_id },\n+\t{ \"grep\", cmd_grep, RUN_SETUP_GENTLY },\n+\t{ \"hash-object\", cmd_hash_object },\n+\t{ \"help\", cmd_help },\n+\t{ \"index-pack\", cmd_index_pack, RUN_SETUP_GENTLY },\n+\t{ \"init\", cmd_init_db },\n+\t{ \"init-db\", cmd_init_db },\n+\t{ \"log\", cmd_log, RUN_SETUP },\n+\t{ \"ls-files\", cmd_ls_files, RUN_SETUP },\n+\t{ \"ls-remote\", cmd_ls_remote, RUN_SETUP_GENTLY },\n+\t{ \"ls-tree\", cmd_ls_tree, RUN_SETUP },\n+\t{ \"mailinfo\", cmd_mailinfo },\n+\t{ \"mailsplit\", cmd_mailsplit },\n+\t{ \"merge\", cmd_merge, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"merge-base\", cmd_merge_base, RUN_SETUP },\n+\t{ \"merge-file\", cmd_merge_file, RUN_SETUP_GENTLY },\n+\t{ \"merge-index\", cmd_merge_index, RUN_SETUP },\n+\t{ \"merge-ours\", cmd_merge_ours, RUN_SETUP },\n+\t{ \"merge-recursive\", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"merge-recursive-ours\", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"merge-recursive-theirs\", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"merge-subtree\", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"merge-tree\", cmd_merge_tree, RUN_SETUP },\n+\t{ \"mktag\", cmd_mktag, RUN_SETUP },\n+\t{ \"mktree\", cmd_mktree, RUN_SETUP },\n+\t{ \"mv\", cmd_mv, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"name-rev\", cmd_name_rev, RUN_SETUP },\n+\t{ \"notes\", cmd_notes, RUN_SETUP },\n+\t{ \"pack-objects\", cmd_pack_objects, RUN_SETUP },\n+\t{ \"pack-redundant\", cmd_pack_redundant, RUN_SETUP },\n+\t{ \"pack-refs\", cmd_pack_refs, RUN_SETUP },\n+\t{ \"patch-id\", cmd_patch_id },\n+\t{ \"pickaxe\", cmd_blame, RUN_SETUP },\n+\t{ \"prune\", cmd_prune, RUN_SETUP },\n+\t{ \"prune-packed\", cmd_prune_packed, RUN_SETUP },\n+\t{ \"push\", cmd_push, RUN_SETUP },\n+\t{ \"read-tree\", cmd_read_tree, RUN_SETUP },\n+\t{ \"receive-pack\", cmd_receive_pack },\n+\t{ \"reflog\", cmd_reflog, RUN_SETUP },\n+\t{ \"remote\", cmd_remote, RUN_SETUP },\n+\t{ \"remote-ext\", cmd_remote_ext },\n+\t{ \"remote-fd\", cmd_remote_fd },\n+\t{ \"repack\", cmd_repack, RUN_SETUP },\n+\t{ \"replace\", cmd_replace, RUN_SETUP },\n+\t{ \"rerere\", cmd_rerere, RUN_SETUP },\n+\t{ \"reset\", cmd_reset, RUN_SETUP },\n+\t{ \"rev-list\", cmd_rev_list, RUN_SETUP },\n+\t{ \"rev-parse\", cmd_rev_parse },\n+\t{ \"revert\", cmd_revert, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"rm\", cmd_rm, RUN_SETUP },\n+\t{ \"send-pack\", cmd_send_pack, RUN_SETUP },\n+\t{ \"shortlog\", cmd_shortlog, RUN_SETUP_GENTLY | USE_PAGER },\n+\t{ \"show\", cmd_show, RUN_SETUP },\n+\t{ \"show-branch\", cmd_show_branch, RUN_SETUP },\n+\t{ \"show-ref\", cmd_show_ref, RUN_SETUP },\n+\t{ \"stage\", cmd_add, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"status\", cmd_status, RUN_SETUP | NEED_WORK_TREE },\n+\t{ \"stripspace\", cmd_stripspace },\n+\t{ \"symbolic-ref\", cmd_symbolic_ref, RUN_SETUP },\n+\t{ \"tag\", cmd_tag, RUN_SETUP },\n+\t{ \"unpack-file\", cmd_unpack_file, RUN_SETUP },\n+\t{ \"unpack-objects\", cmd_unpack_objects, RUN_SETUP },\n+\t{ \"update-index\", cmd_update_index, RUN_SETUP },\n+\t{ \"update-ref\", cmd_update_ref, RUN_SETUP },\n+\t{ \"update-server-info\", cmd_update_server_info, RUN_SETUP },\n+\t{ \"upload-archive\", cmd_upload_archive },\n+\t{ \"upload-archive--writer\", cmd_upload_archive_writer },\n+\t{ \"var\", cmd_var, RUN_SETUP_GENTLY },\n+\t{ \"verify-pack\", cmd_verify_pack },\n+\t{ \"verify-tag\", cmd_verify_tag, RUN_SETUP },\n+\t{ \"version\", cmd_version },\n+\t{ \"whatchanged\", cmd_whatchanged, RUN_SETUP },\n+\t{ \"write-tree\", cmd_write_tree, RUN_SETUP },\n+};\n+\n+int is_internal_command(const char *s)\n+{\n+\tint i;\n+\tfor (i = 0; i < ARRAY_SIZE(commands); i++) {\n+\t\tstruct cmd_struct *p = commands+i;\n+\t\tif (!strcmp(s, p->cmd))\n+\t\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n static void handle_internal_command(int argc, const char **argv)\n {\n \tconst char *cmd = argv[0];\n-\tstatic struct cmd_struct commands[] = {\n-\t\t{ \"add\", cmd_add, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"annotate\", cmd_annotate, RUN_SETUP },\n-\t\t{ \"apply\", cmd_apply, RUN_SETUP_GENTLY },\n-\t\t{ \"archive\", cmd_archive },\n-\t\t{ \"bisect--helper\", cmd_bisect__helper, RUN_SETUP },\n-\t\t{ \"blame\", cmd_blame, RUN_SETUP },\n-\t\t{ \"branch\", cmd_branch, RUN_SETUP },\n-\t\t{ \"bundle\", cmd_bundle, RUN_SETUP_GENTLY },\n-\t\t{ \"cat-file\", cmd_cat_file, RUN_SETUP },\n-\t\t{ \"check-attr\", cmd_check_attr, RUN_SETUP },\n-\t\t{ \"check-ignore\", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"check-mailmap\", cmd_check_mailmap, RUN_SETUP },\n-\t\t{ \"check-ref-format\", cmd_check_ref_format },\n-\t\t{ \"checkout\", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"checkout-index\", cmd_checkout_index,\n-\t\t\tRUN_SETUP | NEED_WORK_TREE},\n-\t\t{ \"cherry\", cmd_cherry, RUN_SETUP },\n-\t\t{ \"cherry-pick\", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"clean\", cmd_clean, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"clone\", cmd_clone },\n-\t\t{ \"column\", cmd_column, RUN_SETUP_GENTLY },\n-\t\t{ \"commit\", cmd_commit, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"commit-tree\", cmd_commit_tree, RUN_SETUP },\n-\t\t{ \"config\", cmd_config, RUN_SETUP_GENTLY },\n-\t\t{ \"count-objects\", cmd_count_objects, RUN_SETUP },\n-\t\t{ \"credential\", cmd_credential, RUN_SETUP_GENTLY },\n-\t\t{ \"describe\", cmd_describe, RUN_SETUP },\n-\t\t{ \"diff\", cmd_diff },\n-\t\t{ \"diff-files\", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"diff-index\", cmd_diff_index, RUN_SETUP },\n-\t\t{ \"diff-tree\", cmd_diff_tree, RUN_SETUP },\n-\t\t{ \"fast-export\", cmd_fast_export, RUN_SETUP },\n-\t\t{ \"fetch\", cmd_fetch, RUN_SETUP },\n-\t\t{ \"fetch-pack\", cmd_fetch_pack, RUN_SETUP },\n-\t\t{ \"fmt-merge-msg\", cmd_fmt_merge_msg, RUN_SETUP },\n-\t\t{ \"for-each-ref\", cmd_for_each_ref, RUN_SETUP },\n-\t\t{ \"format-patch\", cmd_format_patch, RUN_SETUP },\n-\t\t{ \"fsck\", cmd_fsck, RUN_SETUP },\n-\t\t{ \"fsck-objects\", cmd_fsck, RUN_SETUP },\n-\t\t{ \"gc\", cmd_gc, RUN_SETUP },\n-\t\t{ \"get-tar-commit-id\", cmd_get_tar_commit_id },\n-\t\t{ \"grep\", cmd_grep, RUN_SETUP_GENTLY },\n-\t\t{ \"hash-object\", cmd_hash_object },\n-\t\t{ \"help\", cmd_help },\n-\t\t{ \"index-pack\", cmd_index_pack, RUN_SETUP_GENTLY },\n-\t\t{ \"init\", cmd_init_db },\n-\t\t{ \"init-db\", cmd_init_db },\n-\t\t{ \"log\", cmd_log, RUN_SETUP },\n-\t\t{ \"ls-files\", cmd_ls_files, RUN_SETUP },\n-\t\t{ \"ls-remote\", cmd_ls_remote, RUN_SETUP_GENTLY },\n-\t\t{ \"ls-tree\", cmd_ls_tree, RUN_SETUP },\n-\t\t{ \"mailinfo\", cmd_mailinfo },\n-\t\t{ \"mailsplit\", cmd_mailsplit },\n-\t\t{ \"merge\", cmd_merge, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"merge-base\", cmd_merge_base, RUN_SETUP },\n-\t\t{ \"merge-file\", cmd_merge_file, RUN_SETUP_GENTLY },\n-\t\t{ \"merge-index\", cmd_merge_index, RUN_SETUP },\n-\t\t{ \"merge-ours\", cmd_merge_ours, RUN_SETUP },\n-\t\t{ \"merge-recursive\", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"merge-recursive-ours\", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"merge-recursive-theirs\", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"merge-subtree\", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"merge-tree\", cmd_merge_tree, RUN_SETUP },\n-\t\t{ \"mktag\", cmd_mktag, RUN_SETUP },\n-\t\t{ \"mktree\", cmd_mktree, RUN_SETUP },\n-\t\t{ \"mv\", cmd_mv, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"name-rev\", cmd_name_rev, RUN_SETUP },\n-\t\t{ \"notes\", cmd_notes, RUN_SETUP },\n-\t\t{ \"pack-objects\", cmd_pack_objects, RUN_SETUP },\n-\t\t{ \"pack-redundant\", cmd_pack_redundant, RUN_SETUP },\n-\t\t{ \"pack-refs\", cmd_pack_refs, RUN_SETUP },\n-\t\t{ \"patch-id\", cmd_patch_id },\n-\t\t{ \"pickaxe\", cmd_blame, RUN_SETUP },\n-\t\t{ \"prune\", cmd_prune, RUN_SETUP },\n-\t\t{ \"prune-packed\", cmd_prune_packed, RUN_SETUP },\n-\t\t{ \"push\", cmd_push, RUN_SETUP },\n-\t\t{ \"read-tree\", cmd_read_tree, RUN_SETUP },\n-\t\t{ \"receive-pack\", cmd_receive_pack },\n-\t\t{ \"reflog\", cmd_reflog, RUN_SETUP },\n-\t\t{ \"remote\", cmd_remote, RUN_SETUP },\n-\t\t{ \"remote-ext\", cmd_remote_ext },\n-\t\t{ \"remote-fd\", cmd_remote_fd },\n-\t\t{ \"repack\", cmd_repack, RUN_SETUP },\n-\t\t{ \"replace\", cmd_replace, RUN_SETUP },\n-\t\t{ \"rerere\", cmd_rerere, RUN_SETUP },\n-\t\t{ \"reset\", cmd_reset, RUN_SETUP },\n-\t\t{ \"rev-list\", cmd_rev_list, RUN_SETUP },\n-\t\t{ \"rev-parse\", cmd_rev_parse },\n-\t\t{ \"revert\", cmd_revert, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"rm\", cmd_rm, RUN_SETUP },\n-\t\t{ \"send-pack\", cmd_send_pack, RUN_SETUP },\n-\t\t{ \"shortlog\", cmd_shortlog, RUN_SETUP_GENTLY | USE_PAGER },\n-\t\t{ \"show\", cmd_show, RUN_SETUP },\n-\t\t{ \"show-branch\", cmd_show_branch, RUN_SETUP },\n-\t\t{ \"show-ref\", cmd_show_ref, RUN_SETUP },\n-\t\t{ \"stage\", cmd_add, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"status\", cmd_status, RUN_SETUP | NEED_WORK_TREE },\n-\t\t{ \"stripspace\", cmd_stripspace },\n-\t\t{ \"symbolic-ref\", cmd_symbolic_ref, RUN_SETUP },\n-\t\t{ \"tag\", cmd_tag, RUN_SETUP },\n-\t\t{ \"unpack-file\", cmd_unpack_file, RUN_SETUP },\n-\t\t{ \"unpack-objects\", cmd_unpack_objects, RUN_SETUP },\n-\t\t{ \"update-index\", cmd_update_index, RUN_SETUP },\n-\t\t{ \"update-ref\", cmd_update_ref, RUN_SETUP },\n-\t\t{ \"update-server-info\", cmd_update_server_info, RUN_SETUP },\n-\t\t{ \"upload-archive\", cmd_upload_archive },\n-\t\t{ \"upload-archive--writer\", cmd_upload_archive_writer },\n-\t\t{ \"var\", cmd_var, RUN_SETUP_GENTLY },\n-\t\t{ \"verify-pack\", cmd_verify_pack },\n-\t\t{ \"verify-tag\", cmd_verify_tag, RUN_SETUP },\n-\t\t{ \"version\", cmd_version },\n-\t\t{ \"whatchanged\", cmd_whatchanged, RUN_SETUP },\n-\t\t{ \"write-tree\", cmd_write_tree, RUN_SETUP },\n-\t};\n \tint i;\n \tstatic const char ext[] = STRIP_EXTENSION;\n \n-- \n1.8.4.msysgit.0\n"},{"id":"232555","messageId":"CAP8UFD2uq5Q-2F4w2zwH582NTpo9JwiKyHPovQJW+7phbT-b-A@mail.gmail.com","threadId":"35588","inReplyTo":"52C1E09A.8040907@gmail.com","subject":"Re: [PATCH 2/2] Speed up is_git_command() by checking early for internal commands","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2014-01-02T08:51:43Z","receivedAt":"2014-01-02T08:51:43Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Mon, Dec 30, 2013 at 10:07 PM, Sebastian Schuberth\n<sschuberth@gmail.com> wrote:\n> Since 2dce956 is_git_command() was a bit slow as it does file I/O in the\n> call to list_commands_in_dir(). Avoid the file I/O by adding an early\n> check for internal commands.\n>\n> Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>\n> ---\n>  builtin/help.c |   5 ++\n>  git.c          | 242 ++++++++++++++++++++++++++++++---------------------------\n>  2 files changed, 132 insertions(+), 115 deletions(-)\n>\n> diff --git a/builtin/help.c b/builtin/help.c\n> index b6fc15e..1f0261e 100644\n> --- a/builtin/help.c\n> +++ b/builtin/help.c\n> @@ -284,10 +284,15 @@ static int git_help_config(const char *var, const char *value, void *cb)\n>         return git_default_config(var, value, cb);\n>  }\n>\n> +extern int is_internal_command(const char *s);\n> +\n\nStarting the new year in keeping with the fine tradition of asking\npeople who add stuff to clean up what others left behind, I would\nsuggest moving all the code related to internal commands (or maybe all\ncommands) in a new pair of files like \"internal-cmds.{c,h}\". This way\ngit.c and builtin/help.c could include internal-cmds.h and you\nwouldn't need such extern declaration.\n\nHappy new year everyone,\nChristian.\n"},{"id":"232556","messageId":"52C55F9E.5000609@gmail.com","threadId":"35588","inReplyTo":"CAP8UFD2uq5Q-2F4w2zwH582NTpo9JwiKyHPovQJW+7phbT-b-A@mail.gmail.com","subject":"Re: [PATCH 2/2] Speed up is_git_command() by checking early for internal commands","fromName":"Sebastian Schuberth","fromEmail":"sschuberth@gmail.com","sentAt":"2014-01-02T12:46:22Z","receivedAt":"2014-01-02T12:46:22Z","isPatch":true,"sender":{"key":"sschuberth@gmail.com","avatar":"https://avatars.githubusercontent.com/u/349154?v=4"},"body":"On 02.01.2014 09:51, Christian Couder wrote:\n\n>> diff --git a/builtin/help.c b/builtin/help.c\n>> index b6fc15e..1f0261e 100644\n>> --- a/builtin/help.c\n>> +++ b/builtin/help.c\n>> @@ -284,10 +284,15 @@ static int git_help_config(const char *var, const char *value, void *cb)\n>>          return git_default_config(var, value, cb);\n>>   }\n>>\n>> +extern int is_internal_command(const char *s);\n>> +\n>\n> Starting the new year in keeping with the fine tradition of asking\n> people who add stuff to clean up what others left behind, I would\n> suggest moving all the code related to internal commands (or maybe all\n> commands) in a new pair of files like \"internal-cmds.{c,h}\". This way\n> git.c and builtin/help.c could include internal-cmds.h and you\n> wouldn't need such extern declaration.\n\nWouldn't the existing builtin.h be a more appropriate for this? (And \ncreate a builtin.c for the implementations.)\n\nAlso, I start to realize that it's a bit unfortunate that we seem to use \nthe terms \"builtin\" and \"internal command\" interchangeably. I'll \nprobably add a patch to address this.\n\n-- \nSebastian Schuberth\n"}]}