Skip to content

Commit 0a1b13c

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 66e39cf commit 0a1b13c

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
@@ -106,8 +106,8 @@ project(git
106106
#TODO Enable NLS on windows natively
107107

108108
#macros for parsing the Makefile for sources and scripts
109-
macro(parse_makefile_for_sources list_var regex)
110-
file(STRINGS ${CMAKE_SOURCE_DIR}/Makefile ${list_var} REGEX "^${regex} \\+=(.*)")
109+
macro(parse_makefile_for_sources list_var makefile regex)
110+
file(STRINGS ${makefile} ${list_var} REGEX "^${regex} \\+=(.*)")
111111
string(REPLACE "${regex} +=" "" ${list_var} ${${list_var}})
112112
string(REPLACE "$(COMPAT_OBJS)" "" ${list_var} ${${list_var}}) #remove "$(COMPAT_OBJS)" This is only for libgit.
113113
string(STRIP ${${list_var}} ${list_var}) #remove trailing/leading whitespaces
@@ -672,20 +672,20 @@ include_directories(${CMAKE_BINARY_DIR})
672672

673673
#build
674674
#libgit
675-
parse_makefile_for_sources(libgit_SOURCES "LIB_OBJS")
675+
parse_makefile_for_sources(libgit_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "LIB_OBJS")
676676

677677
list(TRANSFORM libgit_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
678678
list(TRANSFORM compat_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
679679
add_library(libgit ${libgit_SOURCES} ${compat_SOURCES})
680680

681681
#libxdiff
682-
parse_makefile_for_sources(libxdiff_SOURCES "XDIFF_OBJS")
682+
parse_makefile_for_sources(libxdiff_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "XDIFF_OBJS")
683683

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

687687
#reftable
688-
parse_makefile_for_sources(reftable_SOURCES "REFTABLE_OBJS")
688+
parse_makefile_for_sources(reftable_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "REFTABLE_OBJS")
689689

690690
list(TRANSFORM reftable_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
691691
add_library(reftable STATIC ${reftable_SOURCES})
@@ -749,7 +749,7 @@ elseif(UNIX)
749749
endif()
750750

751751
#git
752-
parse_makefile_for_sources(git_SOURCES "BUILTIN_OBJS")
752+
parse_makefile_for_sources(git_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "BUILTIN_OBJS")
753753

754754
list(TRANSFORM git_SOURCES PREPEND "${CMAKE_SOURCE_DIR}/")
755755
add_executable(git ${CMAKE_SOURCE_DIR}/git.c ${git_SOURCES})
@@ -886,24 +886,14 @@ file(STRINGS ${CMAKE_SOURCE_DIR}/git-p4.py content NEWLINE_CONSUME)
886886
string(REPLACE "#!/usr/bin/env python" "#!/usr/bin/python" content "${content}")
887887
file(WRITE ${CMAKE_BINARY_DIR}/git-p4 ${content})
888888

889-
#templates
890-
file(GLOB templates "${CMAKE_SOURCE_DIR}/templates/*")
891-
list(TRANSFORM templates REPLACE "${CMAKE_SOURCE_DIR}/templates/" "")
892-
list(REMOVE_ITEM templates ".gitignore")
893-
list(REMOVE_ITEM templates "Makefile")
894-
list(REMOVE_ITEM templates "blt")# Prevents an error when reconfiguring for in source builds
895-
896-
list(REMOVE_ITEM templates "branches--")
897-
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/branches) #create branches
898-
889+
#${CMAKE_SOURCE_DIR}/Makefile templates
890+
parse_makefile_for_sources(templates ${CMAKE_SOURCE_DIR}/templates/Makefile "TEMPLATES")
891+
string(REPLACE " " ";" templates ${templates})
899892
#templates have @.*@ replacement so use configure_file instead
900893
foreach(tm ${templates})
901-
string(REPLACE "--" "/" blt_tm ${tm})
902-
string(REPLACE "this" "" blt_tm ${blt_tm})# for this--
903-
configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${blt_tm} @ONLY)
894+
configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${tm} @ONLY)
904895
endforeach()
905896

906-
907897
#translations
908898
if(MSGFMT_EXE)
909899
file(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*.po")
@@ -977,7 +967,7 @@ add_executable(test-fake-ssh ${CMAKE_SOURCE_DIR}/t/helper/test-fake-ssh.c)
977967
target_link_libraries(test-fake-ssh common-main)
978968

979969
#unit-tests
980-
parse_makefile_for_sources(unit-test_SOURCES "UNIT_TEST_OBJS")
970+
parse_makefile_for_sources(unit-test_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "UNIT_TEST_OBJS")
981971
list(TRANSFORM unit-test_SOURCES REPLACE "\\$\\(UNIT_TEST_DIR\\)/" "${CMAKE_SOURCE_DIR}/t/unit-tests/")
982972
add_library(unit-test-lib STATIC ${unit-test_SOURCES})
983973

@@ -1035,7 +1025,7 @@ if(MSVC)
10351025
endif()
10361026

10371027
#test-tool
1038-
parse_makefile_for_sources(test-tool_SOURCES "TEST_BUILTINS_OBJS")
1028+
parse_makefile_for_sources(test-tool_SOURCES ${CMAKE_SOURCE_DIR}/Makefile "TEST_BUILTINS_OBJS")
10391029
add_library(test-lib OBJECT ${CMAKE_SOURCE_DIR}/t/unit-tests/test-lib.c)
10401030

10411031
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)