Skip to content

Commit c480725

Browse files
committed
version --build-options: report commit, too, if possible
In particular when local tags are used (or tags that are pushed to some fork) to build Git, it is very hard to figure out from which particular revision a particular Git executable was built. Let's just report that in our build options. We need to be careful, though, to report when the current commit cannot be determined, e.g. when building from a tarball without any associated Git repository. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 114042a commit c480725

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,9 @@ builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
17751775
version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
17761776
version.sp version.s version.o: EXTRA_CPPFLAGS = \
17771777
'-DGIT_VERSION="$(GIT_VERSION)"' \
1778-
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)'
1778+
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)' \
1779+
'-DGIT_BUILT_FROM_COMMIT="$(shell git rev-parse -q --verify HEAD || \
1780+
echo "(unknown)")"'
17791781

17801782
$(BUILT_INS): git$X
17811783
$(QUIET_BUILT_IN)$(RM) $@ && \

help.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ int cmd_version(int argc, const char **argv, const char *prefix)
433433
printf("git version %s\n", git_version_string);
434434
while (*++argv) {
435435
if (!strcmp(*argv, "--build-options")) {
436+
printf("built from commit: %s\n",
437+
git_built_from_commit_string);
436438
printf("sizeof-long: %d\n", (int)sizeof(long));
437439
printf("machine: %s\n", build_platform);
438440
/* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */

version.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "strbuf.h"
44

55
const char git_version_string[] = GIT_VERSION;
6+
const char git_built_from_commit_string[] = GIT_BUILT_FROM_COMMIT;
67

78
const char *git_user_agent(void)
89
{

version.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define VERSION_H
33

44
extern const char git_version_string[];
5+
extern const char git_built_from_commit_string[];
56

67
const char *git_user_agent(void);
78
const char *git_user_agent_sanitized(void);

0 commit comments

Comments
 (0)