Skip to content

Commit b4e666a

Browse files
vdyedscho
authored andcommitted
Makefile: allow specifying GIT_BUILT_FROM_COMMIT
Allow specification of a custom `GIT_BUILT_FROM_COMMIT` string to replace the output of `git rev-parse HEAD`. This allows a build of `git` from somewhere other than an active clone of `git` (e.g. from the archive created with `make dist`) to include commit information in `git version --build-options`. Signed-off-by: Victoria Dye <vdye@github.com>
1 parent 71c0000 commit b4e666a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/fuzz_corpora
22
/GIT-BUILD-DIR
33
/GIT-BUILD-OPTIONS
4+
/GIT-BUILT-FROM-COMMIT
45
/GIT-CFLAGS
56
/GIT-LDFLAGS
67
/GIT-PREFIX

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ include shared.mak
321321
# Define GIT_USER_AGENT if you want to change how git identifies itself during
322322
# network interactions. The default is "git/$(GIT_VERSION)".
323323
#
324+
# Define GIT_BUILT_FROM_COMMIT if you want to force the commit hash identified
325+
# in 'git version --build-options' to a specific value. The default is the
326+
# commit hash of the current HEAD.
327+
#
324328
# Define DEFAULT_HELP_FORMAT to "man", "info" or "html"
325329
# (defaults to "man") if you want to have a different default when
326330
# "git help" is called without a parameter specifying the format.
@@ -2364,6 +2368,15 @@ GIT-USER-AGENT: FORCE
23642368
echo '$(GIT_USER_AGENT_SQ)' >GIT-USER-AGENT; \
23652369
fi
23662370

2371+
GIT_BUILT_FROM_COMMIT = $(eval GIT_BUILT_FROM_COMMIT := $$(shell \
2372+
GIT_CEILING_DIRECTORIES="$$(CURDIR)/.." \
2373+
git rev-parse -q --verify HEAD 2>/dev/null))$(GIT_BUILT_FROM_COMMIT)
2374+
GIT-BUILT-FROM-COMMIT: FORCE
2375+
@if test x'$(GIT_BUILT_FROM_COMMIT)' != x"`cat GIT-BUILT-FROM-COMMIT 2>/dev/null`" ; then \
2376+
echo >&2 " * new built-from commit"; \
2377+
echo '$(GIT_BUILT_FROM_COMMIT)' >GIT-BUILT-FROM-COMMIT; \
2378+
fi
2379+
23672380
ifdef DEFAULT_HELP_FORMAT
23682381
BASIC_CFLAGS += -DDEFAULT_HELP_FORMAT='"$(DEFAULT_HELP_FORMAT)"'
23692382
endif
@@ -2478,13 +2491,11 @@ PAGER_ENV_CQ_SQ = $(subst ','\'',$(PAGER_ENV_CQ))
24782491
pager.sp pager.s pager.o: EXTRA_CPPFLAGS = \
24792492
-DPAGER_ENV='$(PAGER_ENV_CQ_SQ)'
24802493

2481-
version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
2494+
version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT GIT-BUILT-FROM-COMMIT
24822495
version.sp version.s version.o: EXTRA_CPPFLAGS = \
24832496
'-DGIT_VERSION="$(GIT_VERSION)"' \
24842497
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)' \
2485-
'-DGIT_BUILT_FROM_COMMIT="$(shell \
2486-
GIT_CEILING_DIRECTORIES="$(CURDIR)/.." \
2487-
git rev-parse -q --verify HEAD 2>/dev/null)"'
2498+
'-DGIT_BUILT_FROM_COMMIT="$(GIT_BUILT_FROM_COMMIT)"'
24882499

24892500
$(BUILT_INS): git$X
24902501
$(QUIET_BUILT_IN)$(RM) $@ && \

0 commit comments

Comments
 (0)