Skip to content

Commit ae23abe

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 40d62eb commit ae23abe

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
@@ -1889,7 +1889,9 @@ builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
18891889
version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
18901890
version.sp version.s version.o: EXTRA_CPPFLAGS = \
18911891
'-DGIT_VERSION="$(GIT_VERSION)"' \
1892-
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)'
1892+
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)' \
1893+
'-DGIT_BUILT_FROM_COMMIT="$(shell git rev-parse -q --verify HEAD || \
1894+
echo "(unknown)")"'
18931895

18941896
$(BUILT_INS): git$X
18951897
$(QUIET_BUILT_IN)$(RM) $@ && \

help.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ int cmd_version(int argc, const char **argv, const char *prefix)
413413
printf("git version %s\n", git_version_string);
414414

415415
if (build_options) {
416+
printf("built from commit: %s\n",
417+
git_built_from_commit_string);
416418
printf("sizeof-long: %d\n", (int)sizeof(long));
417419
printf("machine: %s\n", build_platform);
418420
/* 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)