A re-roll of this v1[1] to stop hardcoding the hook list, and instead generate it. The v1 used a Perl script to generate the hook-list.h, it's now a shellscsript that uses "sed" instead. The sed script is an adaptation of René's in [2]. I fixed a regression in it vis-a-vis the Perl version, we need to set LC_ALL so we don't sort the list at build-time with the locale of the user performing the build. I also turned the two sed commands into one, with a trick that's perhaps too clever, but which has worked in my cross-platform testing so far. 1. http://lore.kernel.org/git/cover-0.3-0000000000-20210617T100239Z-avarab@xxxxxxxxx 2. https://lore.kernel.org/git/648321ed-bda9-d7fc-73e1-7ccf48addf9c@xxxxxx/ Emily Shaffer (1): hook.c: add a hook_exists() wrapper and use it in bugreport.c Ævar Arnfjörð Bjarmason (2): hook.[ch]: move find_hook() to this new library hook-list.h: add a generated list of hooks, like config-list.h .gitignore | 1 + Makefile | 11 +++++- builtin/am.c | 1 + builtin/bugreport.c | 46 +++++----------------- builtin/commit.c | 1 + builtin/merge.c | 1 + builtin/receive-pack.c | 1 + builtin/worktree.c | 1 + contrib/buildsystems/CMakeLists.txt | 7 ++++ generate-hooklist.sh | 18 +++++++++ hook.c | 61 +++++++++++++++++++++++++++++ hook.h | 16 ++++++++ refs.c | 1 + run-command.c | 35 +---------------- run-command.h | 7 ---- sequencer.c | 1 + transport.c | 1 + 17 files changed, 131 insertions(+), 79 deletions(-) create mode 100755 generate-hooklist.sh create mode 100644 hook.c create mode 100644 hook.h Range-diff against v1: -: ---------- > 1: 58c37e4f06 hook.[ch]: move find_hook() to this new library -: ---------- > 2: 0cf7e078ef hook.c: add a hook_exists() wrapper and use it in bugreport.c 1: f343fc7ae6 ! 3: ba7f01f4f6 hook-list.h: add a generated list of hooks, like config-list.h @@ Commit message - 976aaedca0 (msvc: add a Makefile target to pre-generate the Visual Studio solution, 2019-07-29) + The LC_ALL=C is needed because at least in my locale the dash ("-") is + ignored for the purposes of sorting, which results in a different + order. I'm not aware of anything in git that has a hard dependency on + the order, but e.g. the bugreport output would end up using whatever + locale was in effect when git was compiled. + Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> + Signed-off-by: René Scharfe <l.s.r@xxxxxx> ## .gitignore ## @@ @@ Makefile: command-list.h: $(wildcard Documentation/git*.txt) $(patsubst %,--exclude-program %,$(EXCLUDED_PROGRAMS)) \ command-list.txt >$@+ && mv $@+ $@ -+hook-list.h: generate-hooklist.sh -+hook-list.h: Documentation/githooks.txt ++hook-list.h: generate-hooklist.sh Documentation/githooks.txt + $(QUIET_GEN)$(SHELL_PATH) ./generate-hooklist.sh \ + >$@+ && mv $@+ $@ + @@ contrib/buildsystems/CMakeLists.txt: if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-li ## generate-hooklist.sh (new) ## @@ +#!/bin/sh ++# ++# Usage: ./generate-hooklist.sh >hook-list.h + -+echo "/* Automatically generated by generate-hooklist.sh */" ++cat <<EOF ++/* Automatically generated by generate-hooklist.sh */ + -+print_hook_list () { -+ cat <<EOF +static const char *hook_name_list[] = { +EOF -+ perl -ne ' -+ chomp; -+ @l[$.] = $_; -+ push @h => $l[$. - 1] if /^~~~+$/s; -+ END { -+ print qq[\t"$_",\n] for sort @h; -+ } -+ ' <Documentation/githooks.txt -+ cat <<EOF ++ ++sed -n -e '/^~~~~*$/ {x; s/^.*$/ "&",/; p;}; x' \ ++ <Documentation/githooks.txt | ++ LC_ALL=C sort ++ ++cat <<EOF + NULL, +}; +EOF -+} -+ -+echo -+print_hook_list ## hook.c ## @@ -- 2.32.0.615.g90fb4d7369