Skip to content

Commit 58d1772

Browse files
committed
Merge branch 'js/enhanced-version-info'
"git version --build-options" learned to report the host CPU and the exact commit object name the binary was built from. * js/enhanced-version-info: version --build-options: report commit, too, if possible version --build-options: also report host CPU
2 parents deeb2fc + ed32b78 commit 58d1772

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ all::
425425
#
426426
# to say "export LESS=FRX (and LV=-c) if the environment variable
427427
# LESS (and LV) is not set, respectively".
428+
#
429+
# When cross-compiling, define HOST_CPU as the canonical name of the CPU on
430+
# which the built Git will run (for instance "x86_64").
428431

429432
GIT-VERSION-FILE: FORCE
430433
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1099,6 +1102,12 @@ else
10991102
BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d'
11001103
endif
11011104

1105+
ifeq (,$(HOST_CPU))
1106+
BASIC_CFLAGS += -DGIT_HOST_CPU="\"$(firstword $(subst -, ,$(uname_M)))\""
1107+
else
1108+
BASIC_CFLAGS += -DGIT_HOST_CPU="\"$(HOST_CPU)\""
1109+
endif
1110+
11021111
ifneq (,$(INLINE))
11031112
BASIC_CFLAGS += -Dinline=$(INLINE)
11041113
endif
@@ -1897,7 +1906,9 @@ builtin/help.sp builtin/help.s builtin/help.o: EXTRA_CPPFLAGS = \
18971906
version.sp version.s version.o: GIT-VERSION-FILE GIT-USER-AGENT
18981907
version.sp version.s version.o: EXTRA_CPPFLAGS = \
18991908
'-DGIT_VERSION="$(GIT_VERSION)"' \
1900-
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)'
1909+
'-DGIT_USER_AGENT=$(GIT_USER_AGENT_CQ_SQ)' \
1910+
'-DGIT_BUILT_FROM_COMMIT="$(shell GIT_CEILING_DIRECTORIES=\"$(CURDIR)/..\" \
1911+
git rev-parse -q --verify HEAD || :)"'
19011912

19021913
$(BUILT_INS): git$X
19031914
$(QUIET_BUILT_IN)$(RM) $@ && \

help.c

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

414414
if (build_options) {
415+
printf("cpu: %s\n", GIT_HOST_CPU);
416+
if (git_built_from_commit_string[0])
417+
printf("built from commit: %s\n",
418+
git_built_from_commit_string);
419+
else
420+
printf("no commit associated with this build\n");
415421
printf("sizeof-long: %d\n", (int)sizeof(long));
416422
/* NEEDSWORK: also save and output GIT-BUILD_OPTIONS? */
417423
}

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)