diff -r 1d71ce4531ac Include/pylifecycle.h --- a/Include/pylifecycle.h Sat Sep 10 16:19:45 2016 +0200 +++ b/Include/pylifecycle.h Sat Sep 10 11:18:47 2016 -0700 @@ -72,6 +72,8 @@ #ifndef Py_LIMITED_API PyAPI_FUNC(const char *) _Py_hgidentifier(void); PyAPI_FUNC(const char *) _Py_hgversion(void); +PyAPI_FUNC(const char *) _Py_gitbranch(void); +PyAPI_FUNC(const char *) _Py_gitversion(void); #endif /* Internal -- various one-time initializations */ diff -r 1d71ce4531ac Makefile.pre.in --- a/Makefile.pre.in Sat Sep 10 16:19:45 2016 +0200 +++ b/Makefile.pre.in Sat Sep 10 11:18:47 2016 -0700 @@ -43,6 +43,8 @@ HGVERSION= @HGVERSION@ HGTAG= @HGTAG@ HGBRANCH= @HGBRANCH@ +GITVERSION= @GITVERSION@ +GITBRANCH= @GITBRANCH@ PGO_PROF_GEN_FLAG=@PGO_PROF_GEN_FLAG@ PGO_PROF_USE_FLAG=@PGO_PROF_USE_FLAG@ LLVM_PROF_MERGER=@LLVM_PROF_MERGER@ @@ -735,6 +737,8 @@ -DHGVERSION="\"`LC_ALL=C $(HGVERSION)`\"" \ -DHGTAG="\"`LC_ALL=C $(HGTAG)`\"" \ -DHGBRANCH="\"`LC_ALL=C $(HGBRANCH)`\"" \ + -DGITVERSION="\"`LC_ALL=C $(GITVERSION)`\"" \ + -DGITBRANCH="\"`LC_ALL=C $(GITBRANCH)`\"" \ -o $@ $(srcdir)/Modules/getbuildinfo.c Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile diff -r 1d71ce4531ac Modules/getbuildinfo.c --- a/Modules/getbuildinfo.c Sat Sep 10 16:19:45 2016 +0200 +++ b/Modules/getbuildinfo.c Sat Sep 10 11:18:47 2016 -0700 @@ -31,19 +31,35 @@ #define HGBRANCH "" #endif +#ifndef GITVERSION +#define GITVERSION "" +#endif +#ifndef GITBRANCH +#define GITBRANCH "" +#endif + const char * Py_GetBuildInfo(void) { - static char buildinfo[50 + sizeof(HGVERSION) + + static char buildinfo[50 + + (sizeof(GITVERSION) ? + sizeof(GITVERSION) : sizeof(HGVERSION)) + + ((sizeof(GITVERSION) > + (sizeof(HGTAG) + sizeof(HGBRANCH))) ? + sizeof(GITVERSION) : ((sizeof(HGTAG) > sizeof(HGBRANCH)) ? - sizeof(HGTAG) : sizeof(HGBRANCH))]; - const char *revision = _Py_hgversion(); + sizeof(HGTAG) : sizeof(HGBRANCH)))]; + const char *revision = ((sizeof(HGVERSION) > sizeof(GITVERSION)) ? + _Py_hgversion() : _Py_gitversion()); const char *sep = *revision ? ":" : ""; - const char *hgid = _Py_hgidentifier(); - if (!(*hgid)) - hgid = "default"; + const char *id = ((sizeof(GITBRANCH) > + (sizeof(HGTAG) + sizeof(HGBRANCH))) ? + _Py_gitversion() : _Py_hgidentifier()); + if (!(*id)) { + id = "default/tip"; + } PyOS_snprintf(buildinfo, sizeof(buildinfo), - "%s%s%s, %.20s, %.9s", hgid, sep, revision, + "%s%s%s, %.20s, %.9s", id, sep, revision, DATE, TIME); return buildinfo; } @@ -65,3 +81,15 @@ hgid = HGBRANCH; return hgid; } + +const char * +_Py_gitversion(void) +{ + return GITVERSION; +} + +const char * +_Py_gitbranch(void) +{ + return GITBRANCH; +} diff -r 1d71ce4531ac Python/sysmodule.c --- a/Python/sysmodule.c Sat Sep 10 16:19:45 2016 +0200 +++ b/Python/sysmodule.c Sat Sep 10 11:18:47 2016 -0700 @@ -1907,6 +1907,9 @@ SET_SYS_FROM_STRING("_mercurial", Py_BuildValue("(szz)", "CPython", _Py_hgidentifier(), _Py_hgversion())); + SET_SYS_FROM_STRING("_git", + Py_BuildValue("(szz)", "CPython", _Py_gitbranch(), + _Py_gitversion())); SET_SYS_FROM_STRING("dont_write_bytecode", PyBool_FromLong(Py_DontWriteBytecodeFlag)); SET_SYS_FROM_STRING("api_version", diff -r 1d71ce4531ac configure --- a/configure Sat Sep 10 16:19:45 2016 +0200 +++ b/configure Sat Sep 10 11:18:47 2016 -0700 @@ -760,6 +760,9 @@ build_vendor build_cpu build +HAS_GIT +GITBRANCH +GITVERSION HAS_HG HGBRANCH HGTAG @@ -2753,6 +2756,61 @@ fi + + +if test -e $srcdir/.git/HEAD +then +# Extract the first word of "git", so it can be a program name with args. +set dummy git; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_HAS_GIT+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$HAS_GIT"; then + ac_cv_prog_HAS_GIT="$HAS_GIT" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_HAS_GIT="found" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_prog_HAS_GIT" && ac_cv_prog_HAS_GIT="not-found" +fi +fi +HAS_GIT=$ac_cv_prog_HAS_GIT +if test -n "$HAS_GIT"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAS_GIT" >&5 +$as_echo "$HAS_GIT" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + +else +HAS_GIT=no-repository +fi +if test $HAS_GIT = found +then + GITVERSION="git -C \$(srcdir) rev-parse HEAD" + GITBRANCH="git -C \$(srcdir) rev-parse --abbrev-ref HEAD" +else + GITVERSION="" + GITBRANCH="" +fi + + ac_config_headers="$ac_config_headers pyconfig.h" diff -r 1d71ce4531ac configure.ac --- a/configure.ac Sat Sep 10 16:19:45 2016 +0200 +++ b/configure.ac Sat Sep 10 11:18:47 2016 -0700 @@ -46,6 +46,24 @@ HGBRANCH="" fi +AC_SUBST(GITVERSION) +AC_SUBST(GITBRANCH) + +if test -e $srcdir/.git/HEAD +then +AC_CHECK_PROG(HAS_GIT, git, found, not-found) +else +HAS_GIT=no-repository +fi +if test $HAS_GIT = found +then + GITVERSION="git -C \$(srcdir) rev-parse HEAD" + GITBRANCH="git -C \$(srcdir) rev-parse --abbrev-ref HEAD" +else + GITVERSION="" + GITBRANCH="" +fi + AC_CONFIG_SRCDIR([Include/object.h]) AC_CONFIG_HEADER(pyconfig.h)