]> git.ipfire.org Git - thirdparty/git.git/commitdiff
help: move list_config_help to builtin/help
authorEmily Shaffer <emilyshaffer@google.com>
Thu, 16 Apr 2020 21:18:03 +0000 (14:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Apr 2020 22:22:16 +0000 (15:22 -0700)
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>
.gitignore
Makefile
builtin/help.c
compat/vcbuild/README
config.mak.uname
generate-cmdlist.sh
generate-configlist.sh [new file with mode: 0755]
help.c
help.h

index aebe7c0908f16889ea7dac2b634729c013b6fc99..ea97de83f395008bc5099279a3f03d0a224aad57 100644 (file)
 /gitweb/gitweb.cgi
 /gitweb/static/gitweb.js
 /gitweb/static/gitweb.min.*
+/config-list.h
 /command-list.h
 *.tar.gz
 *.dsc
index 09f98b777cae1dc9226f13c182011adacfd8b2fc..5a022367d41faa52d77d2ae292a9a852488be169 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -814,6 +814,7 @@ LIB_FILE = libgit.a
 XDIFF_LIB = xdiff/lib.a
 VCSSVN_LIB = vcs-svn/lib.a
 
+GENERATED_H += config-list.h
 GENERATED_H += command-list.h
 
 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)
 
 help.sp help.s help.o: command-list.h
 
-builtin/help.sp builtin/help.s builtin/help.o: command-list.h GIT-PREFIX
+builtin/help.sp builtin/help.s builtin/help.o: config-list.h GIT-PREFIX
 builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
        '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \
        '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \
@@ -2148,6 +2149,12 @@ $(BUILT_INS): git$X
        ln -s $< $@ 2>/dev/null || \
        cp $< $@
 
+config-list.h: generate-configlist.sh
+
+config-list.h:
+       $(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh \
+               >$@+ && mv $@+ $@
+
 command-list.h: generate-cmdlist.sh command-list.txt
 
 command-list.h: $(wildcard Documentation/git*.txt) Documentation/*config.txt Documentation/config/*.txt
@@ -2781,7 +2788,7 @@ $(SP_OBJ): %.sp: %.c GIT-CFLAGS FORCE
 .PHONY: sparse $(SP_OBJ)
 sparse: $(SP_OBJ)
 
-EXCEPT_HDRS := command-list.h unicode-width.h compat/% xdiff/%
+EXCEPT_HDRS := command-list.h config-list.h unicode-width.h compat/% xdiff/%
 ifndef GCRYPT_SHA256
        EXCEPT_HDRS += sha256/gcrypt.h
 endif
@@ -2803,7 +2810,7 @@ hdr-check: $(HCO)
 style:
        git clang-format --style file --diff --extensions c,h
 
-check: command-list.h
+check: config-list.h command-list.h
        @if sparse; \
        then \
                echo >&2 "Use 'make sparse' instead"; \
index e5590d7787c50af121db0ba7e6221e89c6785df1..1c5f2b9255fc2e0ff462cc255cdd3c0fff766895 100644 (file)
@@ -8,6 +8,7 @@
 #include "parse-options.h"
 #include "run-command.h"
 #include "column.h"
+#include "config-list.h"
 #include "help.h"
 #include "alias.h"
 
@@ -62,6 +63,91 @@ static const char * const builtin_help_usage[] = {
        NULL
 };
 
+struct slot_expansion {
+       const char *prefix;
+       const char *placeholder;
+       void (*fn)(struct string_list *list, const char *prefix);
+       int found;
+};
+
+static void list_config_help(int for_human)
+{
+       struct slot_expansion slot_expansions[] = {
+               { "advice", "*", list_config_advices },
+               { "color.branch", "<slot>", list_config_color_branch_slots },
+               { "color.decorate", "<slot>", list_config_color_decorate_slots },
+               { "color.diff", "<slot>", list_config_color_diff_slots },
+               { "color.grep", "<slot>", list_config_color_grep_slots },
+               { "color.interactive", "<slot>", list_config_color_interactive_slots },
+               { "color.remote", "<slot>", list_config_color_sideband_slots },
+               { "color.status", "<slot>", list_config_color_status_slots },
+               { "fsck", "<msg-id>", list_config_fsck_msg_ids },
+               { "receive.fsck", "<msg-id>", list_config_fsck_msg_ids },
+               { NULL, NULL, NULL }
+       };
+       const char **p;
+       struct slot_expansion *e;
+       struct string_list keys = STRING_LIST_INIT_DUP;
+       int i;
+
+       for (p = config_name_list; *p; p++) {
+               const char *var = *p;
+               struct strbuf sb = STRBUF_INIT;
+
+               for (e = slot_expansions; e->prefix; e++) {
+
+                       strbuf_reset(&sb);
+                       strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder);
+                       if (!strcasecmp(var, sb.buf)) {
+                               e->fn(&keys, e->prefix);
+                               e->found++;
+                               break;
+                       }
+               }
+               strbuf_release(&sb);
+               if (!e->prefix)
+                       string_list_append(&keys, var);
+       }
+
+       for (e = slot_expansions; e->prefix; e++)
+               if (!e->found)
+                       BUG("slot_expansion %s.%s is not used",
+                           e->prefix, e->placeholder);
+
+       string_list_sort(&keys);
+       for (i = 0; i < keys.nr; i++) {
+               const char *var = keys.items[i].string;
+               const char *wildcard, *tag, *cut;
+
+               if (for_human) {
+                       puts(var);
+                       continue;
+               }
+
+               wildcard = strchr(var, '*');
+               tag = strchr(var, '<');
+
+               if (!wildcard && !tag) {
+                       puts(var);
+                       continue;
+               }
+
+               if (wildcard && !tag)
+                       cut = wildcard;
+               else if (!wildcard && tag)
+                       cut = tag;
+               else
+                       cut = wildcard < tag ? wildcard : tag;
+
+               /*
+                * We may produce duplicates, but that's up to
+                * git-completion.bash to handle
+                */
+               printf("%.*s\n", (int)(cut - var), var);
+       }
+       string_list_clear(&keys, 0);
+}
+
 static enum help_format parse_help_format(const char *format)
 {
        if (!strcmp(format, "man"))
index 1b6dabf5a2310ffe25ebd1646f9a9fd3602ed839..42292e7c098e23e61f5f7e602b46ddae335da9e9 100644 (file)
@@ -92,8 +92,8 @@ The Steps of Build Git with VS2008
    the git operations.
 
 3. Inside Git's directory run the command:
-       make command-list.h
-   to generate the command-list.h file needed to compile git.
+       make command-list.h config-list.h
+   to generate the header file needed to compile git.
 
 4. Then either build Git with the GNU Make Makefile in the Git projects
    root
index 0ab8e00938397612bc28ea48a218e460a80b1c6a..f880cc2792a57840a616c2b98d440e3bd4403f07 100644 (file)
@@ -721,9 +721,9 @@ vcxproj:
         echo '</Project>') >git-remote-http/LinkOrCopyRemoteHttp.targets
        git add -f git/LinkOrCopyBuiltins.targets git-remote-http/LinkOrCopyRemoteHttp.targets
 
-       # Add command-list.h
-       $(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 command-list.h
-       git add -f command-list.h
+       # Add command-list.h and config-list.h
+       $(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 config-list.h command-list.h
+       git add -f config-list.h command-list.h
 
        # Add scripts
        rm -f perl/perl.mak
index 71158f7d8ba9c774ca6790ea8594e96accb17fce..45fecf8bdfb21abea3c8935ba926ab819773509e 100755 (executable)
@@ -76,23 +76,6 @@ print_command_list () {
        echo "};"
 }
 
-print_config_list () {
-       cat <<EOF
-static const char *config_name_list[] = {
-EOF
-       grep -h '^[a-zA-Z].*\..*::$' Documentation/*config.txt Documentation/config/*.txt |
-       sed '/deprecated/d; s/::$//; s/,  */\n/g' |
-       sort |
-       while read line
-       do
-               echo "  \"$line\","
-       done
-       cat <<EOF
-       NULL,
-};
-EOF
-}
-
 exclude_programs=
 while test "--exclude-program" = "$1"
 do
@@ -113,5 +96,3 @@ echo
 define_category_names "$1"
 echo
 print_command_list "$1"
-echo
-print_config_list
diff --git a/generate-configlist.sh b/generate-configlist.sh
new file mode 100755 (executable)
index 0000000..8692fe5
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+echo "/* Automatically generated by generate-configlist.sh */"
+echo
+
+print_config_list () {
+       cat <<EOF
+static const char *config_name_list[] = {
+EOF
+       grep -h '^[a-zA-Z].*\..*::$' Documentation/*config.txt Documentation/config/*.txt |
+       sed '/deprecated/d; s/::$//; s/,  */\n/g' |
+       sort |
+       sed 's/^.*$/    "&",/'
+       cat <<EOF
+       NULL,
+};
+EOF
+}
+
+echo
+print_config_list
diff --git a/help.c b/help.c
index cf67624a94bc47ad7d373d64a1d3b20f562c8fc1..a21487db773c2daf114b73b80d209c3fc4d41dd2 100644 (file)
--- a/help.c
+++ b/help.c
@@ -407,91 +407,6 @@ void list_common_guides_help(void)
        putchar('\n');
 }
 
-struct slot_expansion {
-       const char *prefix;
-       const char *placeholder;
-       void (*fn)(struct string_list *list, const char *prefix);
-       int found;
-};
-
-void list_config_help(int for_human)
-{
-       struct slot_expansion slot_expansions[] = {
-               { "advice", "*", list_config_advices },
-               { "color.branch", "<slot>", list_config_color_branch_slots },
-               { "color.decorate", "<slot>", list_config_color_decorate_slots },
-               { "color.diff", "<slot>", list_config_color_diff_slots },
-               { "color.grep", "<slot>", list_config_color_grep_slots },
-               { "color.interactive", "<slot>", list_config_color_interactive_slots },
-               { "color.remote", "<slot>", list_config_color_sideband_slots },
-               { "color.status", "<slot>", list_config_color_status_slots },
-               { "fsck", "<msg-id>", list_config_fsck_msg_ids },
-               { "receive.fsck", "<msg-id>", list_config_fsck_msg_ids },
-               { NULL, NULL, NULL }
-       };
-       const char **p;
-       struct slot_expansion *e;
-       struct string_list keys = STRING_LIST_INIT_DUP;
-       int i;
-
-       for (p = config_name_list; *p; p++) {
-               const char *var = *p;
-               struct strbuf sb = STRBUF_INIT;
-
-               for (e = slot_expansions; e->prefix; e++) {
-
-                       strbuf_reset(&sb);
-                       strbuf_addf(&sb, "%s.%s", e->prefix, e->placeholder);
-                       if (!strcasecmp(var, sb.buf)) {
-                               e->fn(&keys, e->prefix);
-                               e->found++;
-                               break;
-                       }
-               }
-               strbuf_release(&sb);
-               if (!e->prefix)
-                       string_list_append(&keys, var);
-       }
-
-       for (e = slot_expansions; e->prefix; e++)
-               if (!e->found)
-                       BUG("slot_expansion %s.%s is not used",
-                           e->prefix, e->placeholder);
-
-       string_list_sort(&keys);
-       for (i = 0; i < keys.nr; i++) {
-               const char *var = keys.items[i].string;
-               const char *wildcard, *tag, *cut;
-
-               if (for_human) {
-                       puts(var);
-                       continue;
-               }
-
-               wildcard = strchr(var, '*');
-               tag = strchr(var, '<');
-
-               if (!wildcard && !tag) {
-                       puts(var);
-                       continue;
-               }
-
-               if (wildcard && !tag)
-                       cut = wildcard;
-               else if (!wildcard && tag)
-                       cut = tag;
-               else
-                       cut = wildcard < tag ? wildcard : tag;
-
-               /*
-                * We may produce duplicates, but that's up to
-                * git-completion.bash to handle
-                */
-               printf("%.*s\n", (int)(cut - var), var);
-       }
-       string_list_clear(&keys, 0);
-}
-
 static int get_alias(const char *var, const char *value, void *data)
 {
        struct string_list *list = data;
diff --git a/help.h b/help.h
index 7a455beeb725e267946b1ac2c4d91ba9fee2a8c1..9071894e8cf4a4b907014a02cbfeaf028b8e5cb5 100644 (file)
--- a/help.h
+++ b/help.h
@@ -22,7 +22,6 @@ static inline void mput_char(char c, unsigned int num)
 void list_common_cmds_help(void);
 void list_all_cmds_help(void);
 void list_common_guides_help(void);
-void list_config_help(int for_human);
 
 void list_all_main_cmds(struct string_list *list);
 void list_all_other_cmds(struct string_list *list);