Skip to content

Commit

Permalink
Makefile: allow specifying GIT_BUILT_FROM_COMMIT
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vdye authored and dscho committed Sep 18, 2024
1 parent 400e242 commit 66ca679
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/fuzz_corpora
/GIT-BUILD-DIR
/GIT-BUILD-OPTIONS
/GIT-BUILT-FROM-COMMIT
/GIT-CFLAGS
/GIT-LDFLAGS
/GIT-PREFIX
Expand Down
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ include shared.mak
# Define GIT_USER_AGENT if you want to change how git identifies itself during
# network interactions. The default is "git/$(GIT_VERSION)".
#
# Define GIT_BUILT_FROM_COMMIT if you want to force the commit hash identified
# in 'git version --build-options' to a specific value. The default is the
# commit hash of the current HEAD.
#
# Define DEFAULT_HELP_FORMAT to "man", "info" or "html"
# (defaults to "man") if you want to have a different default when
# "git help" is called without a parameter specifying the format.
Expand Down Expand Up @@ -2385,6 +2389,15 @@ GIT-USER-AGENT: FORCE
echo '$(GIT_USER_AGENT_SQ)' >GIT-USER-AGENT; \
fi

GIT_BUILT_FROM_COMMIT = $(eval GIT_BUILT_FROM_COMMIT := $$(shell \
GIT_CEILING_DIRECTORIES="$$(CURDIR)/.." \
git rev-parse -q --verify HEAD 2>/dev/null))$(GIT_BUILT_FROM_COMMIT)
GIT-BUILT-FROM-COMMIT: FORCE
@if test x'$(GIT_BUILT_FROM_COMMIT)' != x"`cat GIT-BUILT-FROM-COMMIT 2>/dev/null`" ; then \
echo >&2 " * new built-from commit"; \
echo '$(GIT_BUILT_FROM_COMMIT)' >GIT-BUILT-FROM-COMMIT; \
fi

ifdef DEFAULT_HELP_FORMAT
BASIC_CFLAGS += -DDEFAULT_HELP_FORMAT='"$(DEFAULT_HELP_FORMAT)"'
endif
Expand Down Expand Up @@ -2522,13 +2535,11 @@ PAGER_ENV_CQ_SQ = $(subst ','\'',$(PAGER_ENV_CQ))
pager.sp pager.s pager.o: EXTRA_CPPFLAGS = \
-DPAGER_ENV='$(PAGER_ENV_CQ_SQ)'

version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT GIT-BUILT-FROM-COMMIT
version.sp version.s version.o: EXTRA_CPPFLAGS = \
'-DGIT_VERSION="$(GIT_VERSION)"' \
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)' \
'-DGIT_BUILT_FROM_COMMIT="$(shell \
GIT_CEILING_DIRECTORIES="$(CURDIR)/.." \
git rev-parse -q --verify HEAD 2>/dev/null)"'
'-DGIT_BUILT_FROM_COMMIT="$(GIT_BUILT_FROM_COMMIT)"'

$(BUILT_INS): git$X
$(QUIET_BUILT_IN)$(RM) $@ && \
Expand Down

0 comments on commit 66ca679

Please sign in to comment.