builtins: Makefile clean-up
authorJunio C Hamano <junkio@cox.net>
Fri, 4 Aug 2006 08:51:04 +0000 (01:51 -0700)
committerJunio C Hamano <junkio@cox.net>
Fri, 4 Aug 2006 08:51:04 +0000 (01:51 -0700)
This cleans up the build procedure for built-in commands by:

 - generating mostly redundant definition of BUILT_INS from
   BUILTIN_OBJS in the Makefile,
 - renaming a few files to make the above possible, and
 - sorting the built-in command table in git.c.

It might be a good idea to binary search (or perfect hash) the built-in
command table, but that can be done later when somebody feels like.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Makefile
builtin-count-objects.c [moved from builtin-count.c with 100% similarity]
builtin.h
git.c
help.c [moved from builtin-help.c with 100% similarity]

index 1a3605b1236d6bf90436655ec60299ca59c48565..dc39f72f1eb8b3a05c03ffe16e62b056924cf573 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -187,19 +187,9 @@ PROGRAMS = \
        git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
 
 BUILT_INS = \
-       git-checkout-index$X \
-       git-log$X git-whatchanged$X git-show$X git-update-ref$X \
-       git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
-       git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
-       git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
-       git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
-       git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
-       git-read-tree$X git-commit-tree$X git-write-tree$X \
-       git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \
-       git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X \
-       git-fmt-merge-msg$X git-prune$X git-mv$X git-prune-packed$X \
-       git-repo-config$X git-name-rev$X git-pack-objects$X \
-       git-unpack-objects$X git-symbolic-ref$X
+       git-format-patch$X git-show$X git-whatchanged$X \
+       git-get-tar-commit-id$X \
+       $(patsubst builtin-%.o,git-%$X,$(BUILTIN_OBJS))
 
 # what 'all' will build and 'install' will install, in gitexecdir
 ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)
@@ -228,7 +218,7 @@ LIB_H = \
        blob.h cache.h commit.h csum-file.h delta.h \
        diff.h object.h pack.h pkt-line.h quote.h refs.h \
        run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \
-       tree-walk.h log-tree.h dir.h path-list.h
+       tree-walk.h log-tree.h dir.h path-list.h builtin.h
 
 DIFF_OBJS = \
        diff.o diff-lib.o diffcore-break.o diffcore-order.o \
@@ -243,23 +233,49 @@ LIB_OBJS = \
        server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
        tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
        fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
-       alloc.o merge-file.o path-list.o $(DIFF_OBJS)
+       alloc.o merge-file.o path-list.o help.o $(DIFF_OBJS)
 
 BUILTIN_OBJS = \
+       builtin-add.o \
+       builtin-apply.o \
+       builtin-cat-file.o \
        builtin-checkout-index.o \
-       builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
-       builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
-       builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
-       builtin-tar-tree.o builtin-upload-tar.o builtin-update-index.o \
-       builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
-       builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
-       builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
-       builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
-       builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \
-       builtin-update-ref.o builtin-fmt-merge-msg.o builtin-prune.o \
-       builtin-mv.o builtin-prune-packed.o builtin-repo-config.o \
-       builtin-name-rev.o builtin-pack-objects.o builtin-unpack-objects.o \
-       builtin-symbolic-ref.o
+       builtin-check-ref-format.o \
+       builtin-commit-tree.o \
+       builtin-count-objects.o \
+       builtin-diff.o \
+       builtin-diff-files.o \
+       builtin-diff-index.o \
+       builtin-diff-stages.o \
+       builtin-diff-tree.o \
+       builtin-fmt-merge-msg.o \
+       builtin-grep.o \
+       builtin-init-db.o \
+       builtin-log.o \
+       builtin-ls-files.o \
+       builtin-ls-tree.o \
+       builtin-mailinfo.o \
+       builtin-mailsplit.o \
+       builtin-mv.o \
+       builtin-name-rev.o \
+       builtin-pack-objects.o \
+       builtin-prune.o \
+       builtin-prune-packed.o \
+       builtin-push.o \
+       builtin-read-tree.o \
+       builtin-repo-config.o \
+       builtin-rev-list.o \
+       builtin-rev-parse.o \
+       builtin-rm.o \
+       builtin-show-branch.o \
+       builtin-stripspace.o \
+       builtin-symbolic-ref.o \
+       builtin-tar-tree.o \
+       builtin-unpack-objects.o \
+       builtin-update-index.o \
+       builtin-update-ref.o \
+       builtin-upload-tar.o \
+       builtin-write-tree.o
 
 GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
 LIBS = $(GITLIBS) -lz
@@ -540,7 +556,7 @@ git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS) GIT-CFLAGS
                $(ALL_CFLAGS) -o $@ $(filter %.c,$^) \
                $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
 
-builtin-help.o: common-cmds.h
+help.o: common-cmds.h
 
 $(BUILT_INS): git$X
        rm -f $@ && ln git$X $@
similarity index 100%
rename from builtin-count.c
rename to builtin-count-objects.c
index 3a24637b11d11b1014b5ea3b6927d47e9c0b50fe..c0bdb051bd07775898e7e3a118956024eeb86d78 100644 (file)
--- a/builtin.h
+++ b/builtin.h
@@ -8,62 +8,56 @@ extern const char git_version_string[];
 extern const char git_usage_string[];
 
 extern void help_unknown_cmd(const char *cmd);
+extern int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, const char *msg, const char *patch);
+extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
+extern void stripspace(FILE *in, FILE *out);
+extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
 
-extern int cmd_help(int argc, const char **argv, const char *prefix);
-extern int cmd_version(int argc, const char **argv, const char *prefix);
-
-extern int cmd_whatchanged(int argc, const char **argv, const char *prefix);
-extern int cmd_show(int argc, const char **argv, const char *prefix);
-extern int cmd_log(int argc, const char **argv, const char *prefix);
-extern int cmd_diff(int argc, const char **argv, const char *prefix);
-extern int cmd_format_patch(int argc, const char **argv, const char *prefix);
-extern int cmd_count_objects(int argc, const char **argv, const char *prefix);
-
-extern int cmd_prune(int argc, const char **argv, const char *prefix);
-extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
-
-extern int cmd_push(int argc, const char **argv, const char *prefix);
-extern int cmd_grep(int argc, const char **argv, const char *prefix);
-extern int cmd_rm(int argc, const char **argv, const char *prefix);
 extern int cmd_add(int argc, const char **argv, const char *prefix);
-extern int cmd_rev_list(int argc, const char **argv, const char *prefix);
+extern int cmd_apply(int argc, const char **argv, const char *prefix);
+extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
+extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);
 extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix);
-extern int cmd_init_db(int argc, const char **argv, const char *prefix);
-extern int cmd_tar_tree(int argc, const char **argv, const char *prefix);
-extern int cmd_upload_tar(int argc, const char **argv, const char *prefix);
-extern int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
-extern int cmd_ls_files(int argc, const char **argv, const char *prefix);
-extern int cmd_ls_tree(int argc, const char **argv, const char *prefix);
-extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
 extern int cmd_commit_tree(int argc, const char **argv, const char *prefix);
-extern int cmd_apply(int argc, const char **argv, const char *prefix);
-extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
+extern int cmd_count_objects(int argc, const char **argv, const char *prefix);
 extern int cmd_diff_files(int argc, const char **argv, const char *prefix);
 extern int cmd_diff_index(int argc, const char **argv, const char *prefix);
+extern int cmd_diff(int argc, const char **argv, const char *prefix);
 extern int cmd_diff_stages(int argc, const char **argv, const char *prefix);
 extern int cmd_diff_tree(int argc, const char **argv, const char *prefix);
-extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
-extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
-extern int cmd_update_index(int argc, const char **argv, const char *prefix);
-extern int cmd_update_ref(int argc, const char **argv, const char *prefix);
 extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix);
+extern int cmd_format_patch(int argc, const char **argv, const char *prefix);
+extern int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
+extern int cmd_grep(int argc, const char **argv, const char *prefix);
+extern int cmd_help(int argc, const char **argv, const char *prefix);
+extern int cmd_init_db(int argc, const char **argv, const char *prefix);
+extern int cmd_log(int argc, const char **argv, const char *prefix);
+extern int cmd_ls_files(int argc, const char **argv, const char *prefix);
+extern int cmd_ls_tree(int argc, const char **argv, const char *prefix);
+extern int cmd_mailinfo(int argc, const char **argv, const char *prefix);
+extern int cmd_mailsplit(int argc, const char **argv, const char *prefix);
 extern int cmd_mv(int argc, const char **argv, const char *prefix);
-extern int cmd_repo_config(int argc, const char **argv, const char *prefix);
 extern int cmd_name_rev(int argc, const char **argv, const char *prefix);
 extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);
-extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
+extern int cmd_prune(int argc, const char **argv, const char *prefix);
+extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
+extern int cmd_push(int argc, const char **argv, const char *prefix);
+extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
+extern int cmd_repo_config(int argc, const char **argv, const char *prefix);
+extern int cmd_rev_list(int argc, const char **argv, const char *prefix);
+extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
+extern int cmd_rm(int argc, const char **argv, const char *prefix);
+extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
+extern int cmd_show(int argc, const char **argv, const char *prefix);
+extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
 extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
-extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);
-
+extern int cmd_tar_tree(int argc, const char **argv, const char *prefix);
+extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
+extern int cmd_update_index(int argc, const char **argv, const char *prefix);
+extern int cmd_update_ref(int argc, const char **argv, const char *prefix);
+extern int cmd_upload_tar(int argc, const char **argv, const char *prefix);
+extern int cmd_version(int argc, const char **argv, const char *prefix);
+extern int cmd_whatchanged(int argc, const char **argv, const char *prefix);
 extern int cmd_write_tree(int argc, const char **argv, const char *prefix);
-extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
-
-extern int cmd_mailsplit(int argc, const char **argv, const char *prefix);
-extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
 
-extern int cmd_mailinfo(int argc, const char **argv, const char *prefix);
-extern int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, const char *msg, const char *patch);
-
-extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
-extern void stripspace(FILE *in, FILE *out);
 #endif
diff --git a/git.c b/git.c
index 07b6d3e9ddb63c09781677c89e1d2d5e837ce0f7..754db1a2ee91dd78277ad11fab3c8c620bb12815 100644 (file)
--- a/git.c
+++ b/git.c
@@ -224,52 +224,52 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
                int (*fn)(int, const char **, const char *);
                int option;
        } commands[] = {
-               { "version", cmd_version },
-               { "help", cmd_help },
-               { "log", cmd_log, NEEDS_PREFIX | USE_PAGER },
-               { "whatchanged", cmd_whatchanged, NEEDS_PREFIX | USE_PAGER },
-               { "show", cmd_show, NEEDS_PREFIX | USE_PAGER },
-               { "push", cmd_push },
-               { "format-patch", cmd_format_patch, NEEDS_PREFIX },
-               { "count-objects", cmd_count_objects },
-               { "diff", cmd_diff, NEEDS_PREFIX },
-               { "grep", cmd_grep, NEEDS_PREFIX },
-               { "rm", cmd_rm, NEEDS_PREFIX },
                { "add", cmd_add, NEEDS_PREFIX },
-               { "rev-list", cmd_rev_list, NEEDS_PREFIX },
-               { "init-db", cmd_init_db },
-               { "get-tar-commit-id", cmd_get_tar_commit_id },
-               { "upload-tar", cmd_upload_tar },
+               { "apply", cmd_apply },
+               { "cat-file", cmd_cat_file, NEEDS_PREFIX },
+               { "checkout-index", cmd_checkout_index, NEEDS_PREFIX },
                { "check-ref-format", cmd_check_ref_format },
-               { "ls-files", cmd_ls_files, NEEDS_PREFIX },
-               { "ls-tree", cmd_ls_tree, NEEDS_PREFIX },
-               { "tar-tree", cmd_tar_tree, NEEDS_PREFIX },
-               { "read-tree", cmd_read_tree, NEEDS_PREFIX },
                { "commit-tree", cmd_commit_tree, NEEDS_PREFIX },
-               { "apply", cmd_apply },
-               { "show-branch", cmd_show_branch, NEEDS_PREFIX },
+               { "count-objects", cmd_count_objects },
+               { "diff", cmd_diff, NEEDS_PREFIX },
                { "diff-files", cmd_diff_files, NEEDS_PREFIX },
                { "diff-index", cmd_diff_index, NEEDS_PREFIX },
                { "diff-stages", cmd_diff_stages, NEEDS_PREFIX },
                { "diff-tree", cmd_diff_tree, NEEDS_PREFIX },
-               { "cat-file", cmd_cat_file, NEEDS_PREFIX },
-               { "rev-parse", cmd_rev_parse, NEEDS_PREFIX },
-               { "write-tree", cmd_write_tree, NEEDS_PREFIX },
-               { "mailsplit", cmd_mailsplit },
-               { "mailinfo", cmd_mailinfo },
-               { "stripspace", cmd_stripspace },
-               { "update-index", cmd_update_index, NEEDS_PREFIX },
-               { "update-ref", cmd_update_ref, NEEDS_PREFIX },
                { "fmt-merge-msg", cmd_fmt_merge_msg, NEEDS_PREFIX },
-               { "prune", cmd_prune, NEEDS_PREFIX },
+               { "format-patch", cmd_format_patch, NEEDS_PREFIX },
+               { "get-tar-commit-id", cmd_get_tar_commit_id },
+               { "grep", cmd_grep, NEEDS_PREFIX },
+               { "help", cmd_help },
+               { "init-db", cmd_init_db },
+               { "log", cmd_log, NEEDS_PREFIX | USE_PAGER },
+               { "ls-files", cmd_ls_files, NEEDS_PREFIX },
+               { "ls-tree", cmd_ls_tree, NEEDS_PREFIX },
+               { "mailinfo", cmd_mailinfo },
+               { "mailsplit", cmd_mailsplit },
                { "mv", cmd_mv, NEEDS_PREFIX },
-               { "prune-packed", cmd_prune_packed, NEEDS_PREFIX },
-               { "repo-config", cmd_repo_config },
                { "name-rev", cmd_name_rev, NEEDS_PREFIX },
                { "pack-objects", cmd_pack_objects, NEEDS_PREFIX },
-               { "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX },
+               { "prune", cmd_prune, NEEDS_PREFIX },
+               { "prune-packed", cmd_prune_packed, NEEDS_PREFIX },
+               { "push", cmd_push },
+               { "read-tree", cmd_read_tree, NEEDS_PREFIX },
+               { "repo-config", cmd_repo_config },
+               { "rev-list", cmd_rev_list, NEEDS_PREFIX },
+               { "rev-parse", cmd_rev_parse, NEEDS_PREFIX },
+               { "rm", cmd_rm, NEEDS_PREFIX },
+               { "show-branch", cmd_show_branch, NEEDS_PREFIX },
+               { "show", cmd_show, NEEDS_PREFIX | USE_PAGER },
+               { "stripspace", cmd_stripspace },
                { "symbolic-ref", cmd_symbolic_ref, NEEDS_PREFIX },
-               { "checkout-index", cmd_checkout_index, NEEDS_PREFIX },
+               { "tar-tree", cmd_tar_tree, NEEDS_PREFIX },
+               { "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX },
+               { "update-index", cmd_update_index, NEEDS_PREFIX },
+               { "update-ref", cmd_update_ref, NEEDS_PREFIX },
+               { "upload-tar", cmd_upload_tar },
+               { "version", cmd_version },
+               { "whatchanged", cmd_whatchanged, NEEDS_PREFIX | USE_PAGER },
+               { "write-tree", cmd_write_tree, NEEDS_PREFIX },
        };
        int i;
 
similarity index 100%
rename from builtin-help.c
rename to help.c