builtins: Makefile clean-up
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>
Junio C Hamano committed
Aug 4, 2006 at 01:51 UTC
f754fa9c5480c4556ad268fb5014c4b96cc7b9dc
5 files changed
+116
-106
Makefile
+45
-29
@@ -187,19 +187,9 @@ PROGRAMS = \
187
git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
188
189
BUILT_INS = \
190
- git-checkout-index$X \
191
- git-log$X git-whatchanged$X git-show$X git-update-ref$X \
192
- git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
193
- git-grep$X git-add$X git-rm$X git-rev-list$X git-stripspace$X \
194
- git-check-ref-format$X git-rev-parse$X git-mailinfo$X \
195
- git-init-db$X git-tar-tree$X git-upload-tar$X git-format-patch$X \
196
- git-ls-files$X git-ls-tree$X git-get-tar-commit-id$X \
197
- git-read-tree$X git-commit-tree$X git-write-tree$X \
198
- git-apply$X git-show-branch$X git-diff-files$X git-update-index$X \
199
- git-diff-index$X git-diff-stages$X git-diff-tree$X git-cat-file$X \
200
- git-fmt-merge-msg$X git-prune$X git-mv$X git-prune-packed$X \
201
- git-repo-config$X git-name-rev$X git-pack-objects$X \
202
- git-unpack-objects$X git-symbolic-ref$X
190
+ git-format-patch$X git-show$X git-whatchanged$X \
191
+ git-get-tar-commit-id$X \
192
+ $(patsubst builtin-%.o,git-%$X,$(BUILTIN_OBJS))
193
194
# what 'all' will build and 'install' will install, in gitexecdir
195
ALL_PROGRAMS = $(PROGRAMS) $(SIMPLE_PROGRAMS) $(SCRIPTS)
@@ -228,7 +218,7 @@ LIB_H = \
218
blob.h cache.h commit.h csum-file.h delta.h \
219
diff.h object.h pack.h pkt-line.h quote.h refs.h \
220
run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \
231
- tree-walk.h log-tree.h dir.h path-list.h
221
+ tree-walk.h log-tree.h dir.h path-list.h builtin.h
222
223
DIFF_OBJS = \
224
diff.o diff-lib.o diffcore-break.o diffcore-order.o \
@@ -243,23 +233,49 @@ LIB_OBJS = \
233
server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
234
tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
235
fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
246
- alloc.o merge-file.o path-list.o $(DIFF_OBJS)
236
+ alloc.o merge-file.o path-list.o help.o $(DIFF_OBJS)
237
238
BUILTIN_OBJS = \
239
+ builtin-add.o \
240
+ builtin-apply.o \
241
+ builtin-cat-file.o \
242
builtin-checkout-index.o \
250
- builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
251
- builtin-grep.o builtin-add.o builtin-rev-list.o builtin-check-ref-format.o \
252
- builtin-rm.o builtin-init-db.o builtin-rev-parse.o \
253
- builtin-tar-tree.o builtin-upload-tar.o builtin-update-index.o \
254
- builtin-ls-files.o builtin-ls-tree.o builtin-write-tree.o \
255
- builtin-read-tree.o builtin-commit-tree.o builtin-mailinfo.o \
256
- builtin-apply.o builtin-show-branch.o builtin-diff-files.o \
257
- builtin-diff-index.o builtin-diff-stages.o builtin-diff-tree.o \
258
- builtin-cat-file.o builtin-mailsplit.o builtin-stripspace.o \
259
- builtin-update-ref.o builtin-fmt-merge-msg.o builtin-prune.o \
260
- builtin-mv.o builtin-prune-packed.o builtin-repo-config.o \
261
- builtin-name-rev.o builtin-pack-objects.o builtin-unpack-objects.o \
262
- builtin-symbolic-ref.o
243
+ builtin-check-ref-format.o \
244
+ builtin-commit-tree.o \
245
+ builtin-count-objects.o \
246
+ builtin-diff.o \
247
+ builtin-diff-files.o \
248
+ builtin-diff-index.o \
249
+ builtin-diff-stages.o \
250
+ builtin-diff-tree.o \
251
+ builtin-fmt-merge-msg.o \
252
+ builtin-grep.o \
253
+ builtin-init-db.o \
254
+ builtin-log.o \
255
+ builtin-ls-files.o \
256
+ builtin-ls-tree.o \
257
+ builtin-mailinfo.o \
258
+ builtin-mailsplit.o \
259
+ builtin-mv.o \
260
+ builtin-name-rev.o \
261
+ builtin-pack-objects.o \
262
+ builtin-prune.o \
263
+ builtin-prune-packed.o \
264
+ builtin-push.o \
265
+ builtin-read-tree.o \
266
+ builtin-repo-config.o \
267
+ builtin-rev-list.o \
268
+ builtin-rev-parse.o \
269
+ builtin-rm.o \
270
+ builtin-show-branch.o \
271
+ builtin-stripspace.o \
272
+ builtin-symbolic-ref.o \
273
+ builtin-tar-tree.o \
274
+ builtin-unpack-objects.o \
275
+ builtin-update-index.o \
276
+ builtin-update-ref.o \
277
+ builtin-upload-tar.o \
278
+ builtin-write-tree.o
279
280
GITLIBS = $(LIB_FILE) $(XDIFF_LIB)
281
LIBS = $(GITLIBS) -lz
@@ -540,7 +556,7 @@ git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS) GIT-CFLAGS
556
$(ALL_CFLAGS) -o $@ $(filter %.c,$^) \
557
$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
558
543
-builtin-help.o: common-cmds.h
559
+help.o: common-cmds.h
560
561
$(BUILT_INS): git$X
562
rm -f $@ && ln git$X $@
builtin-count-objects.c
renamed
builtin.h
+37
-43
@@ -8,62 +8,56 @@ extern const char git_version_string[];
8
extern const char git_usage_string[];
9
10
extern void help_unknown_cmd(const char *cmd);
11
+extern int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, const char *msg, const char *patch);
12
+extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
13
+extern void stripspace(FILE *in, FILE *out);
14
+extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
15
12
-extern int cmd_help(int argc, const char **argv, const char *prefix);
13
-extern int cmd_version(int argc, const char **argv, const char *prefix);
14
-
15
-extern int cmd_whatchanged(int argc, const char **argv, const char *prefix);
16
-extern int cmd_show(int argc, const char **argv, const char *prefix);
17
-extern int cmd_log(int argc, const char **argv, const char *prefix);
18
-extern int cmd_diff(int argc, const char **argv, const char *prefix);
19
-extern int cmd_format_patch(int argc, const char **argv, const char *prefix);
20
-extern int cmd_count_objects(int argc, const char **argv, const char *prefix);
21
-
22
-extern int cmd_prune(int argc, const char **argv, const char *prefix);
23
-extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
24
-
25
-extern int cmd_push(int argc, const char **argv, const char *prefix);
26
-extern int cmd_grep(int argc, const char **argv, const char *prefix);
27
-extern int cmd_rm(int argc, const char **argv, const char *prefix);
16
extern int cmd_add(int argc, const char **argv, const char *prefix);
29
-extern int cmd_rev_list(int argc, const char **argv, const char *prefix);
17
+extern int cmd_apply(int argc, const char **argv, const char *prefix);
18
+extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
19
+extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);
20
extern int cmd_check_ref_format(int argc, const char **argv, const char *prefix);
31
-extern int cmd_init_db(int argc, const char **argv, const char *prefix);
32
-extern int cmd_tar_tree(int argc, const char **argv, const char *prefix);
33
-extern int cmd_upload_tar(int argc, const char **argv, const char *prefix);
34
-extern int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
35
-extern int cmd_ls_files(int argc, const char **argv, const char *prefix);
36
-extern int cmd_ls_tree(int argc, const char **argv, const char *prefix);
37
-extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
21
extern int cmd_commit_tree(int argc, const char **argv, const char *prefix);
39
-extern int cmd_apply(int argc, const char **argv, const char *prefix);
40
-extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
22
+extern int cmd_count_objects(int argc, const char **argv, const char *prefix);
23
extern int cmd_diff_files(int argc, const char **argv, const char *prefix);
24
extern int cmd_diff_index(int argc, const char **argv, const char *prefix);
25
+extern int cmd_diff(int argc, const char **argv, const char *prefix);
26
extern int cmd_diff_stages(int argc, const char **argv, const char *prefix);
27
extern int cmd_diff_tree(int argc, const char **argv, const char *prefix);
45
-extern int cmd_cat_file(int argc, const char **argv, const char *prefix);
46
-extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
47
-extern int cmd_update_index(int argc, const char **argv, const char *prefix);
48
-extern int cmd_update_ref(int argc, const char **argv, const char *prefix);
28
extern int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix);
29
+extern int cmd_format_patch(int argc, const char **argv, const char *prefix);
30
+extern int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix);
31
+extern int cmd_grep(int argc, const char **argv, const char *prefix);
32
+extern int cmd_help(int argc, const char **argv, const char *prefix);
33
+extern int cmd_init_db(int argc, const char **argv, const char *prefix);
34
+extern int cmd_log(int argc, const char **argv, const char *prefix);
35
+extern int cmd_ls_files(int argc, const char **argv, const char *prefix);
36
+extern int cmd_ls_tree(int argc, const char **argv, const char *prefix);
37
+extern int cmd_mailinfo(int argc, const char **argv, const char *prefix);
38
+extern int cmd_mailsplit(int argc, const char **argv, const char *prefix);
39
extern int cmd_mv(int argc, const char **argv, const char *prefix);
51
-extern int cmd_repo_config(int argc, const char **argv, const char *prefix);
40
extern int cmd_name_rev(int argc, const char **argv, const char *prefix);
41
extern int cmd_pack_objects(int argc, const char **argv, const char *prefix);
54
-extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
42
+extern int cmd_prune(int argc, const char **argv, const char *prefix);
43
+extern int cmd_prune_packed(int argc, const char **argv, const char *prefix);
44
+extern int cmd_push(int argc, const char **argv, const char *prefix);
45
+extern int cmd_read_tree(int argc, const char **argv, const char *prefix);
46
+extern int cmd_repo_config(int argc, const char **argv, const char *prefix);
47
+extern int cmd_rev_list(int argc, const char **argv, const char *prefix);
48
+extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
49
+extern int cmd_rm(int argc, const char **argv, const char *prefix);
50
+extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
51
+extern int cmd_show(int argc, const char **argv, const char *prefix);
52
+extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
53
extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);
56
-extern int cmd_checkout_index(int argc, const char **argv, const char *prefix);
57
-
54
+extern int cmd_tar_tree(int argc, const char **argv, const char *prefix);
55
+extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
56
+extern int cmd_update_index(int argc, const char **argv, const char *prefix);
57
+extern int cmd_update_ref(int argc, const char **argv, const char *prefix);
58
+extern int cmd_upload_tar(int argc, const char **argv, const char *prefix);
59
+extern int cmd_version(int argc, const char **argv, const char *prefix);
60
+extern int cmd_whatchanged(int argc, const char **argv, const char *prefix);
61
extern int cmd_write_tree(int argc, const char **argv, const char *prefix);
59
-extern int write_tree(unsigned char *sha1, int missing_ok, const char *prefix);
60
-
61
-extern int cmd_mailsplit(int argc, const char **argv, const char *prefix);
62
-extern int split_mbox(const char **mbox, const char *dir, int allow_bare, int nr_prec, int skip);
62
64
-extern int cmd_mailinfo(int argc, const char **argv, const char *prefix);
65
-extern int mailinfo(FILE *in, FILE *out, int ks, const char *encoding, const char *msg, const char *patch);
66
-
67
-extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
68
-extern void stripspace(FILE *in, FILE *out);
63
#endif
git.c
+34
-34
@@ -224,52 +224,52 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
224
int (*fn)(int, const char **, const char *);
225
int option;
226
} commands[] = {
227
- { "version", cmd_version },
228
- { "help", cmd_help },
229
- { "log", cmd_log, NEEDS_PREFIX | USE_PAGER },
230
- { "whatchanged", cmd_whatchanged, NEEDS_PREFIX | USE_PAGER },
231
- { "show", cmd_show, NEEDS_PREFIX | USE_PAGER },
232
- { "push", cmd_push },
233
- { "format-patch", cmd_format_patch, NEEDS_PREFIX },
234
- { "count-objects", cmd_count_objects },
235
- { "diff", cmd_diff, NEEDS_PREFIX },
236
- { "grep", cmd_grep, NEEDS_PREFIX },
237
- { "rm", cmd_rm, NEEDS_PREFIX },
227
{ "add", cmd_add, NEEDS_PREFIX },
239
- { "rev-list", cmd_rev_list, NEEDS_PREFIX },
240
- { "init-db", cmd_init_db },
241
- { "get-tar-commit-id", cmd_get_tar_commit_id },
242
- { "upload-tar", cmd_upload_tar },
228
+ { "apply", cmd_apply },
229
+ { "cat-file", cmd_cat_file, NEEDS_PREFIX },
230
+ { "checkout-index", cmd_checkout_index, NEEDS_PREFIX },
231
{ "check-ref-format", cmd_check_ref_format },
244
- { "ls-files", cmd_ls_files, NEEDS_PREFIX },
245
- { "ls-tree", cmd_ls_tree, NEEDS_PREFIX },
246
- { "tar-tree", cmd_tar_tree, NEEDS_PREFIX },
247
- { "read-tree", cmd_read_tree, NEEDS_PREFIX },
232
{ "commit-tree", cmd_commit_tree, NEEDS_PREFIX },
249
- { "apply", cmd_apply },
250
- { "show-branch", cmd_show_branch, NEEDS_PREFIX },
233
+ { "count-objects", cmd_count_objects },
234
+ { "diff", cmd_diff, NEEDS_PREFIX },
235
{ "diff-files", cmd_diff_files, NEEDS_PREFIX },
236
{ "diff-index", cmd_diff_index, NEEDS_PREFIX },
237
{ "diff-stages", cmd_diff_stages, NEEDS_PREFIX },
238
{ "diff-tree", cmd_diff_tree, NEEDS_PREFIX },
255
- { "cat-file", cmd_cat_file, NEEDS_PREFIX },
256
- { "rev-parse", cmd_rev_parse, NEEDS_PREFIX },
257
- { "write-tree", cmd_write_tree, NEEDS_PREFIX },
258
- { "mailsplit", cmd_mailsplit },
259
- { "mailinfo", cmd_mailinfo },
260
- { "stripspace", cmd_stripspace },
261
- { "update-index", cmd_update_index, NEEDS_PREFIX },
262
- { "update-ref", cmd_update_ref, NEEDS_PREFIX },
239
{ "fmt-merge-msg", cmd_fmt_merge_msg, NEEDS_PREFIX },
264
- { "prune", cmd_prune, NEEDS_PREFIX },
240
+ { "format-patch", cmd_format_patch, NEEDS_PREFIX },
241
+ { "get-tar-commit-id", cmd_get_tar_commit_id },
242
+ { "grep", cmd_grep, NEEDS_PREFIX },
243
+ { "help", cmd_help },
244
+ { "init-db", cmd_init_db },
245
+ { "log", cmd_log, NEEDS_PREFIX | USE_PAGER },
246
+ { "ls-files", cmd_ls_files, NEEDS_PREFIX },
247
+ { "ls-tree", cmd_ls_tree, NEEDS_PREFIX },
248
+ { "mailinfo", cmd_mailinfo },
249
+ { "mailsplit", cmd_mailsplit },
250
{ "mv", cmd_mv, NEEDS_PREFIX },
266
- { "prune-packed", cmd_prune_packed, NEEDS_PREFIX },
267
- { "repo-config", cmd_repo_config },
251
{ "name-rev", cmd_name_rev, NEEDS_PREFIX },
252
{ "pack-objects", cmd_pack_objects, NEEDS_PREFIX },
270
- { "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX },
253
+ { "prune", cmd_prune, NEEDS_PREFIX },
254
+ { "prune-packed", cmd_prune_packed, NEEDS_PREFIX },
255
+ { "push", cmd_push },
256
+ { "read-tree", cmd_read_tree, NEEDS_PREFIX },
257
+ { "repo-config", cmd_repo_config },
258
+ { "rev-list", cmd_rev_list, NEEDS_PREFIX },
259
+ { "rev-parse", cmd_rev_parse, NEEDS_PREFIX },
260
+ { "rm", cmd_rm, NEEDS_PREFIX },
261
+ { "show-branch", cmd_show_branch, NEEDS_PREFIX },
262
+ { "show", cmd_show, NEEDS_PREFIX | USE_PAGER },
263
+ { "stripspace", cmd_stripspace },
264
{ "symbolic-ref", cmd_symbolic_ref, NEEDS_PREFIX },
272
- { "checkout-index", cmd_checkout_index, NEEDS_PREFIX },
265
+ { "tar-tree", cmd_tar_tree, NEEDS_PREFIX },
266
+ { "unpack-objects", cmd_unpack_objects, NEEDS_PREFIX },
267
+ { "update-index", cmd_update_index, NEEDS_PREFIX },
268
+ { "update-ref", cmd_update_ref, NEEDS_PREFIX },
269
+ { "upload-tar", cmd_upload_tar },
270
+ { "version", cmd_version },
271
+ { "whatchanged", cmd_whatchanged, NEEDS_PREFIX | USE_PAGER },
272
+ { "write-tree", cmd_write_tree, NEEDS_PREFIX },
273
};
274
int i;
275