diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h index 5a67666..0684db3 100644 --- a/Include/pylifecycle.h +++ b/Include/pylifecycle.h @@ -72,6 +72,8 @@ PyAPI_FUNC(const char *) Py_GetBuildInfo(void); #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 --git a/Makefile.pre.in b/Makefile.pre.in index ce5296e..e11f94c 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -43,6 +43,8 @@ LDVERSION= @LDVERSION@ 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@ @@ -743,6 +745,8 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \ -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 --git a/Modules/getbuildinfo.c b/Modules/getbuildinfo.c index 0971a64..1cc957d 100644 --- a/Modules/getbuildinfo.c +++ b/Modules/getbuildinfo.c @@ -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 @@ _Py_hgidentifier(void) hgid = HGBRANCH; return hgid; } + +const char * +_Py_gitversion(void) +{ + return GITVERSION; +} + +const char * +_Py_gitbranch(void) +{ + return GITBRANCH; +} diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 5dd0d10..91401bb 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1945,6 +1945,9 @@ _PySys_Init(void) 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 --git a/configure.ac b/configure.ac index 1ca8825..2d73070 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,24 @@ else 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)