Skip to content

Commit ed060aa

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2407bb commit ed060aa

19 files changed

+37
-37
lines changed

contrib/buildsystems/CMakeLists.txt

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ project(git
9999
#TODO Enable NLS on windows natively
100100

101101
#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} \\+=(.*)")
102+
macro(parse_makefile_for_sources list_var makefile regex)
103+
file(STRINGS ${makefile} ${list_var} REGEX "^${regex} \\+=(.*)")
104104
string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}})
105105
string(REPLACE "$(COMPAT_OBJS)" "" ${list_var} ${${list_var}}) #remove "$(COMPAT_OBJS)" This is only for libgit.
106106
string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces
@@ -662,7 +662,7 @@ include_directories(${CMAKE_BINARY_DIR})
662662

663663
#build
664664
#libgit
665-
parse_makefile_for_sources(libgit_SOURCES "LIB_OBJS")
665+
parse_makefile_for_sources(libgit_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "LIB_OBJS")
666666

667667
list(TRANSFORM libgit_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
668668
list(TRANSFORM compat_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
@@ -680,13 +680,13 @@ list(APPEND libgit_SOURCES "${CMAKE_BINARY_DIR}/version-def.h")
680680
add_library(libgit ${libgit_SOURCES} ${compat_SOURCES})
681681

682682
#libxdiff
683-
parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS")
683+
parse_makefile_for_sources(libxdiff_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "XDIFF_OBJS")
684684

685685
list(TRANSFORM libxdiff_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
686686
add_library(xdiff STATIC ${libxdiff_SOURCES})
687687

688688
#reftable
689-
parse_makefile_for_sources(reftable_SOURCES "REFTABLE_OBJS")
689+
parse_makefile_for_sources(reftable_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "REFTABLE_OBJS")
690690

691691
list(TRANSFORM reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
692692
add_library(reftable STATIC ${reftable_SOURCES})
@@ -757,7 +757,7 @@ elseif(UNIX)
757757
endif()
758758

759759
#git
760-
parse_makefile_for_sources(git_SOURCES "BUILTIN_OBJS")
760+
parse_makefile_for_sources(git_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "BUILTIN_OBJS")
761761

762762
list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
763763
add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES})
@@ -912,24 +912,14 @@ add_custom_command(OUTPUT "${CMAKE_BINARY_DIR}/git-p4"
912912
VERBATIM)
913913
add_custom_target(python-gen ALL DEPENDS "${CMAKE_BINARY_DIR}/git-p4")
914914

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-
915+
#${CMAKE_SOURCE_DIR}/Makefile templates
916+
parse_makefile_for_sources(templates ${CMAKE_SOURCE_DIR}/templates/Makefile "TEMPLATES")
917+
string(REPLACE " " ";" templates ${templates})
925918
#templates have @.*@ replacement so use configure_file instead
926919
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)
920+
configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${tm} @ONLY)
930921
endforeach()
931922

932-
933923
#translations
934924
if(MSGFMT_EXE)
935925
file(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*.po")
@@ -1003,7 +993,7 @@ add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c)
1003993
target_link_libraries(test-fake-ssh common-main)
1004994

1005995
#unit-tests
1006-
parse_makefile_for_sources(unit-test_SOURCES "UNIT_TEST_OBJS")
996+
parse_makefile_for_sources(unit-test_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "UNIT_TEST_OBJS")
1007997
list(TRANSFORM unit-test_SOURCES REPLACE "\\$\\(UNIT_TEST_DIR\\)/" "${CMAKE_SOURCE_DIR}/t/unit-tests/")
1008998
add_library(unit-test-lib STATIC ${unit-test_SOURCES})
1009999

@@ -1069,7 +1059,7 @@ if(MSVC)
10691059
endif()
10701060

10711061
#test-tool
1072-
parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
1062+
parse_makefile_for_sources(test-tool_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "TEST_BUILTINS_OBJS")
10731063
add_library(test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c)
10741064

10751065
list(TRANSFORM test-tool_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/t/helper/")

templates/Makefile

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,35 @@ all: boilerplates.made custom
2929
# in a file direc--tory--file in the source. They will be
3030
# just copied to the destination.
3131

32-
bpsrc = $(filter-out %~,$(wildcard *--*))
33-
boilerplates.made : $(bpsrc)
34-
$(QUIET)umask 022 && ls *--* 2>/dev/null | \
35-
while read boilerplate; \
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); \
3652
do \
37-
case "$$boilerplate" in *~) continue ;; esac && \
38-
dst=`echo "$$boilerplate" | sed -e 's|^this|.|;s|--|/|g'` && \
39-
dir=`expr "$$dst" : '\(.*\)/'` && \
53+
dir=$$(dirname "$$template") && \
4054
mkdir -p blt/$$dir && \
41-
case "$$boilerplate" in \
42-
*--) continue;; \
43-
esac && \
4455
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
4556
-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; \
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; \
5061
done && \
5162
date >$@
5263

templates/branches--

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)