Skip to content

Commit 709df95

Browse files
nasamuffingitster
authored andcommitted
help: move list_config_help to builtin/help
Starting in 3ac68a9, 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 976aaed (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 <[email protected]> Signed-off-by: Emily Shaffer <[email protected]>
1 parent 145d59f commit 709df95

File tree

9 files changed

+123
-113
lines changed

9 files changed

+123
-113
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
/gitweb/gitweb.cgi
190190
/gitweb/static/gitweb.js
191191
/gitweb/static/gitweb.min.*
192+
/config-list.h
192193
/command-list.h
193194
*.tar.gz
194195
*.dsc

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ LIB_FILE = libgit.a
814814
XDIFF_LIB = xdiff/lib.a
815815
VCSSVN_LIB = vcs-svn/lib.a
816816

817+
GENERATED_H += config-list.h
817818
GENERATED_H += command-list.h
818819

819820
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)
21282129

21292130
help.sp help.s help.o: command-list.h
21302131

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
21322133
builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
21332134
'-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
21342135
'-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
@@ -2148,6 +2149,12 @@ $(BUILT_INS): git$X
21482149
ln -s $< $@ 2>/dev/null || \
21492150
cp $< $@
21502151

2152+
config-list.h: generate-configlist.sh
2153+
2154+
config-list.h:
2155+
$(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh \
2156+
>$@+ && mv $@+ $@
2157+
21512158
command-list.h: generate-cmdlist.sh command-list.txt
21522159

21532160
command-list.h: $(wildcard Documentation/git*.txt) Documentation/*config.txt Documentation/config/*.txt
@@ -2781,7 +2788,7 @@ $(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE
27812788
.PHONY: sparse $(SP_OBJ)
27822789
sparse: $(SP_OBJ)
27832790

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/%
27852792
ifndef GCRYPT_SHA256
27862793
EXCEPT_HDRS += sha256/gcrypt.h
27872794
endif
@@ -2803,7 +2810,7 @@ hdr-check: $(HCO)
28032810
style:
28042811
git clang-format --style file --diff --extensions c,h
28052812

2806-
check: command-list.h
2813+
check: config-list.h command-list.h
28072814
@if sparse; \
28082815
then \
28092816
echo >&2 "Use 'make sparse' instead"; \

builtin/help.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "parse-options.h"
99
#include "run-command.h"
1010
#include "column.h"
11+
#include "config-list.h"
1112
#include "help.h"
1213
#include "alias.h"
1314

@@ -62,6 +63,91 @@ static const char * const builtin_help_usage[] = {
6263
NULL
6364
};
6465

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+
65151
static enum help_format parse_help_format(const char *format)
66152
{
67153
if (!strcmp(format, "man"))

compat/vcbuild/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ The Steps of Build Git with VS2008
9292
the git operations.
9393

9494
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.
9797

9898
4. Then either build Git with the GNU Make Makefile in the Git projects
9999
root

config.mak.uname

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,9 +721,9 @@ vcxproj:
721721
echo '</Project>') >git-remote-http/LinkOrCopyRemoteHttp.targets
722722
git add -f git/LinkOrCopyBuiltins.targets git-remote-http/LinkOrCopyRemoteHttp.targets
723723

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
727727

728728
# Add scripts
729729
rm -f perl/perl.mak

generate-cmdlist.sh

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,6 @@ print_command_list () {
7676
echo "};"
7777
}
7878

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-
9679
exclude_programs=
9780
while test "--exclude-program" = "$1"
9881
do
@@ -113,5 +96,3 @@ echo
11396
define_category_names "$1"
11497
echo
11598
print_command_list "$1"
116-
echo
117-
print_config_list

generate-configlist.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -407,91 +407,6 @@ void list_common_guides_help(void)
407407
putchar('\n');
408408
}
409409

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-
495410
static int get_alias(const char *var, const char *value, void *data)
496411
{
497412
struct string_list *list = data;

help.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ static inline void mput_char(char c, unsigned int num)
2222
void list_common_cmds_help(void);
2323
void list_all_cmds_help(void);
2424
void list_common_guides_help(void);
25-
void list_config_help(int for_human);
2625

2726
void list_all_main_cmds(struct string_list *list);
2827
void list_all_other_cmds(struct string_list *list);

0 commit comments

Comments
 (0)