@matheusbsbs / matheus-bagliano / commits / 709df95b78
Fork 0

help: move list_config_help to builtin/help

Starting in 3ac68a93fd2, help.o began to depend on builtin/branch.o, builtin/clean.o, and builtin/config.o. This meant that help.o was unusable outside of the context of the main Git executable. To make help.o usable by other commands again, move list_config_help() into builtin/help.c (where it makes sense to assume other builtin libraries are present). When command-list.h is included but a member is not used, we start to hear a compiler warning. Since the config list is generated in a fairly different way than the command list, and since commands and config options are semantically different, move the config list into its own header and move the generator into its own script and build rule. For reasons explained in 976aaedc (msvc: add a Makefile target to pre-generate the Visual Studio solution, 2019-07-29), some build artifacts we consider non-source files cannot be generated in the Visual Studio environment, and we already have some Makefile tweaks to help Visual Studio to use generated command-list.h header file. Do the same to a new generated file, config-list.h, introduced by this change. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Emily Shaffer <emilyshaffer@google.com>

Emily Shaffer committed Apr 16, 2020 at 14:18 UTC 709df95b788990472775a63e8b15af3ddd0c822e
9 files changed +123 -113
.gitignore
+1
@@ -189,6 +189,7 @@
189 /gitweb/gitweb.cgi
190 /gitweb/static/gitweb.js
191 /gitweb/static/gitweb.min.*
192 +/config-list.h
193 /command-list.h
194 *.tar.gz
195 *.dsc
Makefile
+10 -3
@@ -814,6 +814,7 @@ LIB_FILE = libgit.a
814 XDIFF_LIB = xdiff/lib.a
815 VCSSVN_LIB = vcs-svn/lib.a
816
817 +GENERATED_H += config-list.h
818 GENERATED_H += command-list.h
819
820 LIB_H := $(sort $(patsubst ./%,%,$(shell git ls-files '*.h' ':!t/' ':!Documentation/' 2>/dev/null || \
@@ -2128,7 +2129,7 @@ git$X: git.o GIT-LDFLAGS $(BUILTIN_OBJS) $(GITLIBS)
2129
2130 help.sp help.s help.o: command-list.h
2131
2131 -builtin/help.sp builtin/help.s builtin/help.o: command-list.h GIT-PREFIX
2132 +builtin/help.sp builtin/help.s builtin/help.o: config-list.h GIT-PREFIX
2133 builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
2134 '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
2135 '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
@@ -2148,6 +2149,12 @@ $(BUILT_INS): git$X
2149 ln -s $< $@ 2>/dev/null || \
2150 cp $< $@
2151
2152 +config-list.h: generate-configlist.sh
2153 +
2154 +config-list.h:
2155 + $(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh \
2156 + >$@+ && mv $@+ $@
2157 +
2158 command-list.h: generate-cmdlist.sh command-list.txt
2159
2160 command-list.h: $(wildcard Documentation/git*.txt) Documentation/*config.txt Documentation/config/*.txt
@@ -2781,7 +2788,7 @@ $(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE
2788 .PHONY: sparse $(SP_OBJ)
2789 sparse: $(SP_OBJ)
2790
2784 -EXCEPT_HDRS := command-list.h unicode-width.h compat/% xdiff/%
2791 +EXCEPT_HDRS := command-list.h config-list.h unicode-width.h compat/% xdiff/%
2792 ifndef GCRYPT_SHA256
2793 EXCEPT_HDRS += sha256/gcrypt.h
2794 endif
@@ -2803,7 +2810,7 @@ hdr-check: $(HCO)
2810 style:
2811 git clang-format --style file --diff --extensions c,h
2812
2806 -check: command-list.h
2813 +check: config-list.h command-list.h
2814 @if sparse; \
2815 then \
2816 echo >&2 "Use 'make sparse' instead"; \
builtin/help.c
+86
@@ -8,6 +8,7 @@
8 #include "parse-options.h"
9 #include "run-command.h"
10 #include "column.h"
11 +#include "config-list.h"
12 #include "help.h"
13 #include "alias.h"
14
@@ -62,6 +63,91 @@ static const char * const builtin_help_usage[] = {
63 NULL
64 };
65
66 +struct slot_expansion {
67 + const char *prefix;
68 + const char *placeholder;
69 + void (*fn)(struct string_list *list, const char *prefix);
70 + int found;
71 +};
72 +
73 +static void list_config_help(int for_human)
74 +{
75 + struct slot_expansion slot_expansions[] = {
76 + { "advice", "*", list_config_advices },
77 + { "color.branch", "<slot>", list_config_color_branch_slots },
78 + { "color.decorate", "<slot>", list_config_color_decorate_slots },
79 + { "color.diff", "<slot>", list_config_color_diff_slots },
80 + { "color.grep", "<slot>", list_config_color_grep_slots },
81 + { "color.interactive", "<slot>", list_config_color_interactive_slots },
82 + { "color.remote", "<slot>", list_config_color_sideband_slots },
83 + { "color.status", "<slot>", list_config_color_status_slots },
84 + { "fsck", "<msg-id>", list_config_fsck_msg_ids },
85 + { "receive.fsck", "<msg-id>", list_config_fsck_msg_ids },
86 + { NULL, NULL, NULL }
87 + };
88 + const char **p;
89 + struct slot_expansion *e;
90 + struct string_list keys = STRING_LIST_INIT_DUP;
91 + int i;
92 +
93 + for (p = config_name_list; *p; p++) {
94 + const char *var = *p;
95 + struct strbuf sb = STRBUF_INIT;
96 +
97 + for (e = slot_expansions; e->prefix; e++) {
98 +
99 + strbuf_reset(&sb);
100 + strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder);
101 + if (!strcasecmp(var, sb.buf)) {
102 + e->fn(&keys, e->prefix);
103 + e->found++;
104 + break;
105 + }
106 + }
107 + strbuf_release(&sb);
108 + if (!e->prefix)
109 + string_list_append(&keys, var);
110 + }
111 +
112 + for (e = slot_expansions; e->prefix; e++)
113 + if (!e->found)
114 + BUG("slot_expansion %s.%s is not used",
115 + e->prefix, e->placeholder);
116 +
117 + string_list_sort(&keys);
118 + for (i = 0; i < keys.nr; i++) {
119 + const char *var = keys.items[i].string;
120 + const char *wildcard, *tag, *cut;
121 +
122 + if (for_human) {
123 + puts(var);
124 + continue;
125 + }
126 +
127 + wildcard = strchr(var, '*');
128 + tag = strchr(var, '<');
129 +
130 + if (!wildcard && !tag) {
131 + puts(var);
132 + continue;
133 + }
134 +
135 + if (wildcard && !tag)
136 + cut = wildcard;
137 + else if (!wildcard && tag)
138 + cut = tag;
139 + else
140 + cut = wildcard < tag ? wildcard : tag;
141 +
142 + /*
143 + * We may produce duplicates, but that's up to
144 + * git-completion.bash to handle
145 + */
146 + printf("%.*s\n", (int)(cut - var), var);
147 + }
148 + string_list_clear(&keys, 0);
149 +}
150 +
151 static enum help_format parse_help_format(const char *format)
152 {
153 if (!strcmp(format, "man"))
compat/vcbuild/README
+2 -2
@@ -92,8 +92,8 @@ The Steps of Build Git with VS2008
92 the git operations.
93
94 3. Inside Git's directory run the command:
95 - make command-list.h
96 - to generate the command-list.h file needed to compile git.
95 + make command-list.h config-list.h
96 + to generate the header file needed to compile git.
97
98 4. Then either build Git with the GNU Make Makefile in the Git projects
99 root
config.mak.uname
+3 -3
@@ -721,9 +721,9 @@ vcxproj:
721 echo '</Project>') >git-remote-http/LinkOrCopyRemoteHttp.targets
722 git add -f git/LinkOrCopyBuiltins.targets git-remote-http/LinkOrCopyRemoteHttp.targets
723
724 - # Add command-list.h
725 - $(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 command-list.h
726 - git add -f command-list.h
724 + # Add command-list.h and config-list.h
725 + $(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 config-list.h command-list.h
726 + git add -f config-list.h command-list.h
727
728 # Add scripts
729 rm -f perl/perl.mak
generate-cmdlist.sh
-19
@@ -76,23 +76,6 @@ print_command_list () {
76 echo "};"
77 }
78
79 -print_config_list () {
80 - cat <<EOF
81 -static const char *config_name_list[] = {
82 -EOF
83 - grep -h '^[a-zA-Z].*\..*::$' Documentation/*config.txt Documentation/config/*.txt |
84 - sed '/deprecated/d; s/::$//; s/, */\n/g' |
85 - sort |
86 - while read line
87 - do
88 - echo " \"$line\","
89 - done
90 - cat <<EOF
91 - NULL,
92 -};
93 -EOF
94 -}
95 -
79 exclude_programs=
80 while test "--exclude-program" = "$1"
81 do
@@ -113,5 +96,3 @@ echo
96 define_category_names "$1"
97 echo
98 print_command_list "$1"
116 -echo
117 -print_config_list
generate-configlist.sh new
+21
@@ -0,0 +1,21 @@
1 +#!/bin/sh
2 +
3 +echo "/* Automatically generated by generate-configlist.sh */"
4 +echo
5 +
6 +print_config_list () {
7 + cat <<EOF
8 +static const char *config_name_list[] = {
9 +EOF
10 + grep -h '^[a-zA-Z].*\..*::$' Documentation/*config.txt Documentation/config/*.txt |
11 + sed '/deprecated/d; s/::$//; s/, */\n/g' |
12 + sort |
13 + sed 's/^.*$/ "&",/'
14 + cat <<EOF
15 + NULL,
16 +};
17 +EOF
18 +}
19 +
20 +echo
21 +print_config_list
help.c
-85
@@ -407,91 +407,6 @@ void list_common_guides_help(void)
407 putchar('\n');
408 }
409
410 -struct slot_expansion {
411 - const char *prefix;
412 - const char *placeholder;
413 - void (*fn)(struct string_list *list, const char *prefix);
414 - int found;
415 -};
416 -
417 -void list_config_help(int for_human)
418 -{
419 - struct slot_expansion slot_expansions[] = {
420 - { "advice", "*", list_config_advices },
421 - { "color.branch", "<slot>", list_config_color_branch_slots },
422 - { "color.decorate", "<slot>", list_config_color_decorate_slots },
423 - { "color.diff", "<slot>", list_config_color_diff_slots },
424 - { "color.grep", "<slot>", list_config_color_grep_slots },
425 - { "color.interactive", "<slot>", list_config_color_interactive_slots },
426 - { "color.remote", "<slot>", list_config_color_sideband_slots },
427 - { "color.status", "<slot>", list_config_color_status_slots },
428 - { "fsck", "<msg-id>", list_config_fsck_msg_ids },
429 - { "receive.fsck", "<msg-id>", list_config_fsck_msg_ids },
430 - { NULL, NULL, NULL }
431 - };
432 - const char **p;
433 - struct slot_expansion *e;
434 - struct string_list keys = STRING_LIST_INIT_DUP;
435 - int i;
436 -
437 - for (p = config_name_list; *p; p++) {
438 - const char *var = *p;
439 - struct strbuf sb = STRBUF_INIT;
440 -
441 - for (e = slot_expansions; e->prefix; e++) {
442 -
443 - strbuf_reset(&sb);
444 - strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder);
445 - if (!strcasecmp(var, sb.buf)) {
446 - e->fn(&keys, e->prefix);
447 - e->found++;
448 - break;
449 - }
450 - }
451 - strbuf_release(&sb);
452 - if (!e->prefix)
453 - string_list_append(&keys, var);
454 - }
455 -
456 - for (e = slot_expansions; e->prefix; e++)
457 - if (!e->found)
458 - BUG("slot_expansion %s.%s is not used",
459 - e->prefix, e->placeholder);
460 -
461 - string_list_sort(&keys);
462 - for (i = 0; i < keys.nr; i++) {
463 - const char *var = keys.items[i].string;
464 - const char *wildcard, *tag, *cut;
465 -
466 - if (for_human) {
467 - puts(var);
468 - continue;
469 - }
470 -
471 - wildcard = strchr(var, '*');
472 - tag = strchr(var, '<');
473 -
474 - if (!wildcard && !tag) {
475 - puts(var);
476 - continue;
477 - }
478 -
479 - if (wildcard && !tag)
480 - cut = wildcard;
481 - else if (!wildcard && tag)
482 - cut = tag;
483 - else
484 - cut = wildcard < tag ? wildcard : tag;
485 -
486 - /*
487 - * We may produce duplicates, but that's up to
488 - * git-completion.bash to handle
489 - */
490 - printf("%.*s\n", (int)(cut - var), var);
491 - }
492 - string_list_clear(&keys, 0);
493 -}
494 -
410 static int get_alias(const char *var, const char *value, void *data)
411 {
412 struct string_list *list = data;
help.h
-1
@@ -22,7 +22,6 @@ static inline void mput_char(char c, unsigned int num)
22 void list_common_cmds_help(void);
23 void list_all_cmds_help(void);
24 void list_common_guides_help(void);
25 -void list_config_help(int for_human);
25
26 void list_all_main_cmds(struct string_list *list);
27 void list_all_other_cmds(struct string_list *list);