Skip to content

Commit 6473c2e

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 layed 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 c5b5ecd commit 6473c2e

19 files changed

+25
-22
lines changed

contrib/buildsystems/CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -878,23 +878,17 @@ endforeach()
878878

879879

880880
#templates
881-
file(GLOB templates "${CMAKE_SOURCE_DIR}/templates/*")
881+
file(GLOB templates "${CMAKE_SOURCE_DIR}/templates/**")
882882
list(TRANSFORM templates REPLACE "${CMAKE_SOURCE_DIR}/templates/" "")
883883
list(REMOVE_ITEM templates ".gitignore")
884884
list(REMOVE_ITEM templates "Makefile")
885885
list(REMOVE_ITEM templates "blt")# Prevents an error when reconfiguring for in source builds
886886

887-
list(REMOVE_ITEM templates "branches--")
888-
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/templates/blt/branches) #create branches
889-
890887
#templates have @.*@ replacement so use configure_file instead
891888
foreach(tm ${templates})
892-
string(REPLACE "--" "/" blt_tm ${tm})
893-
string(REPLACE "this" "" blt_tm ${blt_tm})# for this--
894889
configure_file(${CMAKE_SOURCE_DIR}/templates/${tm} ${CMAKE_BINARY_DIR}/templates/blt/${blt_tm} @ONLY)
895890
endforeach()
896891

897-
898892
#translations
899893
if(MSGFMT_EXE)
900894
file(GLOB po_files "${CMAKE_SOURCE_DIR}/po/*.po")

templates/Makefile

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,34 @@ 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 = description
33+
TEMPLATES += hooks/applypatch-msg.sample
34+
TEMPLATES += hooks/commit-msg.sample
35+
TEMPLATES += hooks/fsmonitor-watchman.sample
36+
TEMPLATES += hooks/post-update.sample
37+
TEMPLATES += hooks/pre-applypatch.sample
38+
TEMPLATES += hooks/pre-commit.sample
39+
TEMPLATES += hooks/pre-merge-commit.sample
40+
TEMPLATES += hooks/prepare-commit-msg.sample
41+
TEMPLATES += hooks/pre-push.sample
42+
TEMPLATES += hooks/pre-rebase.sample
43+
TEMPLATES += hooks/pre-receive.sample
44+
TEMPLATES += hooks/push-to-checkout.sample
45+
TEMPLATES += hooks/sendemail-validate.sample
46+
TEMPLATES += hooks/update.sample
47+
TEMPLATES += info/exclude
48+
49+
boilerplates.made: $(TEMPLATES)
50+
$(QUIET)umask 022 && for template in $(TEMPLATES); \
3651
do \
37-
case "$$boilerplate" in *~) continue ;; esac && \
38-
dst=`echo "$$boilerplate" | sed -e 's|^this|.|;s|--|/|g'` && \
39-
dir=`expr "$$dst" : '\(.*\)/'` && \
52+
dir=$$(dirname "$$template") && \
4053
mkdir -p blt/$$dir && \
41-
case "$$boilerplate" in \
42-
*--) continue;; \
43-
esac && \
4454
sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
4555
-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; \
56+
-e 's|@PERL_PATH@|$(PERL_PATH_SQ)|g' $$template > \
57+
blt/$$template && \
58+
if test -x "$$template"; then rx=rx; else rx=r; fi && \
59+
chmod a+$$rx "blt/$$template" || exit; \
5060
done && \
5161
date >$@
5262

templates/branches--

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

0 commit comments

Comments
 (0)