Git fork

Makefile: simplify building of templates

When we install Git we also install a set of default templates that both
git-init(1) and git-clone(1) populate into our build directories. The
way the pristine templates are laid out in our source directory is
somewhat weird though: instead of reconstructing the actual directory
hierarchy in "templates/", we represent directory separators with "--".

The only reason I could come up with for why we have this is the
"branches/" directory, which is supposed to be empty when installing it.
And as Git famously doesn't store empty directories at all we have to
work around this limitation.

Now the thing is that the "branches/" directory is a leftover to how
branches used to be stored in the dark ages. gitrepository-layout(5)
lists this directory as "slightly deprecated", which I would claim is a
strong understatement. I have never encountered anybody using it today
and would be surprised if it even works as expected. So having the "--"
hack in place for an item that is basically unused, unmaintained and
deprecated doesn't only feel unreasonable, but installing that entry by
default may also cause confusion for users that do not know what this is
supposed to be in the first place.

Remove this directory from our templates and, now that we do not require
the workaround anymore, restructure the templates to form a proper
hierarchy. This makes it way easier for build systems to install these
templates into place.

We should likely think about removing support for "branch/" altogether,
but that is outside of the scope of this patch series.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
ed060aa0 d2407bb8

+37 -37
+12 -22
contrib/buildsystems/CMakeLists.txt
··· 99 #TODO Enable NLS on windows natively 100 101 #macros for parsing the Makefile for sources and scripts 102 - macro(parse_makefile_for_sources list_var regex) 103 - file(STRINGS ${CMAKE_SOURCE_DIR}/Makefile ${list_var} REGEX "^${regex} \\+=(.*)") 104 string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}}) 105 string(REPLACE "$(COMPAT_OBJS)" "" ${list_var} ${${list_var}}) #remove "$(COMPAT_OBJS)" This is only for libgit. 106 string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces ··· 662 663 #build 664 #libgit 665 - parse_makefile_for_sources(libgit_SOURCES "LIB_OBJS") 666 667 list(TRANSFORM libgit_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") 668 list(TRANSFORM compat_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") ··· 680 add_library(libgit ${libgit_SOURCES} ${compat_SOURCES}) 681 682 #libxdiff 683 - parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS") 684 685 list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") 686 add_library(xdiff STATIC ${libxdiff_SOURCES}) 687 688 #reftable 689 - parse_makefile_for_sources(reftable_SOURCES "REFTABLE_OBJS") 690 691 list(TRANSFORM reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") 692 add_library(reftable STATIC ${reftable_SOURCES}) ··· 757 endif() 758 759 #git 760 - parse_makefile_for_sources(git_SOURCES "BUILTIN_OBJS") 761 762 list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") 763 add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES}) ··· 912 VERBATIM) 913 add_custom_target(python-gen ALL DEPENDS "${CMAKE_BINARY_DIR}/git-p4") 914 915 - #templates 916 - file(GLOB templates "${CMAKE_SOURCE_DIR}/templates/*") 917 - list(TRANSFORM templates REPLACE "${CMAKE_SOURCE_DIR}/templates/" "") 918 - list(REMOVE_ITEM templates ".gitignore") 919 - list(REMOVE_ITEM templates "Makefile") 920 - list(REMOVE_ITEM templates "blt")# Prevents an error when reconfiguring for in source builds 921 - 922 - list(REMOVE_ITEM templates "branches--") 923 - file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/branches) #create branches 924 - 925 #templates have @.*@ replacement so use configure_file instead 926 foreach(tm ${templates}) 927 - string(REPLACE "--" "/" blt_tm ${tm}) 928 - string(REPLACE "this" "" blt_tm ${blt_tm})# for this-- 929 - configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${blt_tm} @ONLY) 930 endforeach() 931 - 932 933 #translations 934 if(MSGFMT_EXE) ··· 1003 target_link_libraries(test-fake-ssh common-main) 1004 1005 #unit-tests 1006 - parse_makefile_for_sources(unit-test_SOURCES "UNIT_TEST_OBJS") 1007 list(TRANSFORM unit-test_SOURCES REPLACE "\\$\\(UNIT_TEST_DIR\\)/" "${CMAKE_SOURCE_DIR}/t/unit-tests/") 1008 add_library(unit-test-lib STATIC ${unit-test_SOURCES}) 1009 ··· 1069 endif() 1070 1071 #test-tool 1072 - parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS") 1073 add_library(test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c) 1074 1075 list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/")
··· 99 #TODO Enable NLS on windows natively 100 101 #macros for parsing the Makefile for sources and scripts 102 + macro(parse_makefile_for_sources list_var makefile regex) 103 + file(STRINGS ${makefile} ${list_var} REGEX "^${regex} \\+=(.*)") 104 string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}}) 105 string(REPLACE "$(COMPAT_OBJS)" "" ${list_var} ${${list_var}}) #remove "$(COMPAT_OBJS)" This is only for libgit. 106 string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces ··· 662 663 #build 664 #libgit 665 + parse_makefile_for_sources(libgit_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "LIB_OBJS") 666 667 list(TRANSFORM libgit_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") 668 list(TRANSFORM compat_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") ··· 680 add_library(libgit ${libgit_SOURCES} ${compat_SOURCES}) 681 682 #libxdiff 683 + parse_makefile_for_sources(libxdiff_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "XDIFF_OBJS") 684 685 list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") 686 add_library(xdiff STATIC ${libxdiff_SOURCES}) 687 688 #reftable 689 + parse_makefile_for_sources(reftable_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "REFTABLE_OBJS") 690 691 list(TRANSFORM reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") 692 add_library(reftable STATIC ${reftable_SOURCES}) ··· 757 endif() 758 759 #git 760 + parse_makefile_for_sources(git_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "BUILTIN_OBJS") 761 762 list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/") 763 add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES}) ··· 912 VERBATIM) 913 add_custom_target(python-gen ALL DEPENDS "${CMAKE_BINARY_DIR}/git-p4") 914 915 + #${CMAKE_SOURCE_DIR}/Makefile templates 916 + parse_makefile_for_sources(templates ${CMAKE_SOURCE_DIR}/templates/Makefile "TEMPLATES") 917 + string(REPLACE " " ";" templates ${templates}) 918 #templates have @.*@ replacement so use configure_file instead 919 foreach(tm ${templates}) 920 + configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${tm} @ONLY) 921 endforeach() 922 923 #translations 924 if(MSGFMT_EXE) ··· 993 target_link_libraries(test-fake-ssh common-main) 994 995 #unit-tests 996 + parse_makefile_for_sources(unit-test_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "UNIT_TEST_OBJS") 997 list(TRANSFORM unit-test_SOURCES REPLACE "\\$\\(UNIT_TEST_DIR\\)/" "${CMAKE_SOURCE_DIR}/t/unit-tests/") 998 add_library(unit-test-lib STATIC ${unit-test_SOURCES}) 999 ··· 1059 endif() 1060 1061 #test-tool 1062 + parse_makefile_for_sources(test-tool_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "TEST_BUILTINS_OBJS") 1063 add_library(test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c) 1064 1065 list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/")
+25 -14
templates/Makefile
··· 29 # in a file direc--tory--file in the source. They will be 30 # just copied to the destination. 31 32 - bpsrc = $(filter-out %~,$(wildcard *--*)) 33 - boilerplates.made : $(bpsrc) 34 - $(QUIET)umask 022 && ls *--* 2>/dev/null | \ 35 - while read boilerplate; \ 36 do \ 37 - case "$$boilerplate" in *~) continue ;; esac && \ 38 - dst=`echo "$$boilerplate" | sed -e 's|^this|.|;s|--|/|g'` && \ 39 - dir=`expr "$$dst" : '\(.*\)/'` && \ 40 mkdir -p blt/$$dir && \ 41 - case "$$boilerplate" in \ 42 - *--) continue;; \ 43 - esac && \ 44 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ 45 -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \ 46 - -e 's|@PERL_PATH@|$(PERL_PATH_SQ)|g' $$boilerplate > \ 47 - blt/$$dst && \ 48 - if test -x "$$boilerplate"; then rx=rx; else rx=r; fi && \ 49 - chmod a+$$rx "blt/$$dst" || exit; \ 50 done && \ 51 date >$@ 52
··· 29 # in a file direc--tory--file in the source. They will be 30 # just copied to the destination. 31 32 + TEMPLATES = 33 + TEMPLATES += description 34 + TEMPLATES += hooks/applypatch-msg.sample 35 + TEMPLATES += hooks/commit-msg.sample 36 + TEMPLATES += hooks/fsmonitor-watchman.sample 37 + TEMPLATES += hooks/post-update.sample 38 + TEMPLATES += hooks/pre-applypatch.sample 39 + TEMPLATES += hooks/pre-commit.sample 40 + TEMPLATES += hooks/pre-merge-commit.sample 41 + TEMPLATES += hooks/prepare-commit-msg.sample 42 + TEMPLATES += hooks/pre-push.sample 43 + TEMPLATES += hooks/pre-rebase.sample 44 + TEMPLATES += hooks/pre-receive.sample 45 + TEMPLATES += hooks/push-to-checkout.sample 46 + TEMPLATES += hooks/sendemail-validate.sample 47 + TEMPLATES += hooks/update.sample 48 + TEMPLATES += info/exclude 49 + 50 + boilerplates.made: $(TEMPLATES) 51 + $(QUIET)umask 022 && for template in $(TEMPLATES); \ 52 do \ 53 + dir=$$(dirname "$$template") && \ 54 mkdir -p blt/$$dir && \ 55 sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ 56 -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \ 57 + -e 's|@PERL_PATH@|$(PERL_PATH_SQ)|g' $$template > \ 58 + blt/$$template && \ 59 + if test -x "$$template"; then rx=rx; else rx=r; fi && \ 60 + chmod a+$$rx "blt/$$template" || exit; \ 61 done && \ 62 date >$@ 63
-1
templates/branches--
··· 1 - : this is just to ensure the directory exists.
···
templates/hooks--applypatch-msg.sample templates/hooks/applypatch-msg.sample
templates/hooks--commit-msg.sample templates/hooks/commit-msg.sample
templates/hooks--fsmonitor-watchman.sample templates/hooks/fsmonitor-watchman.sample
templates/hooks--post-update.sample templates/hooks/post-update.sample
templates/hooks--pre-applypatch.sample templates/hooks/pre-applypatch.sample
templates/hooks--pre-commit.sample templates/hooks/pre-commit.sample
templates/hooks--pre-merge-commit.sample templates/hooks/pre-merge-commit.sample
templates/hooks--pre-push.sample templates/hooks/pre-push.sample
templates/hooks--pre-rebase.sample templates/hooks/pre-rebase.sample
templates/hooks--pre-receive.sample templates/hooks/pre-receive.sample
templates/hooks--prepare-commit-msg.sample templates/hooks/prepare-commit-msg.sample
templates/hooks--push-to-checkout.sample templates/hooks/push-to-checkout.sample
templates/hooks--sendemail-validate.sample templates/hooks/sendemail-validate.sample
templates/hooks--update.sample templates/hooks/update.sample
templates/info--exclude templates/info/exclude
templates/this--description templates/description