Skip to content

Commit 2c7085f

Browse files
authored
bpo-27593: Get SCM build info from git instead of hg (#1327)
Based on commit 5c4b0d0 by Ned Deily, which is based on original patches by Brett Cannon and Steve Dower. Remove also the private _Py_svnversion() function and SVNVERSION variable. Note: Py_SubversionRevision() and Py_SubversionShortBranch() are unchanged, they are part of the public API.
1 parent 6bed8f9 commit 2c7085f

File tree

7 files changed

+79
-140
lines changed

7 files changed

+79
-140
lines changed

Include/pythonrun.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,10 @@ PyAPI_FUNC(const char *) Py_GetPlatform(void);
111111
PyAPI_FUNC(const char *) Py_GetCopyright(void);
112112
PyAPI_FUNC(const char *) Py_GetCompiler(void);
113113
PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
114-
PyAPI_FUNC(const char *) _Py_svnversion(void);
115114
PyAPI_FUNC(const char *) Py_SubversionRevision(void);
116115
PyAPI_FUNC(const char *) Py_SubversionShortBranch(void);
117-
PyAPI_FUNC(const char *) _Py_hgidentifier(void);
118-
PyAPI_FUNC(const char *) _Py_hgversion(void);
116+
PyAPI_FUNC(const char *) _Py_gitidentifier(void);
117+
PyAPI_FUNC(const char *) _Py_gitversion(void);
119118

120119
/* Internal -- various one-time initializations */
121120
PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);

Makefile.pre.in

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ MAINCC= @MAINCC@
3838
LINKCC= @LINKCC@
3939
AR= @AR@
4040
RANLIB= @RANLIB@
41-
SVNVERSION= @SVNVERSION@
42-
HGVERSION= @HGVERSION@
43-
HGTAG= @HGTAG@
44-
HGBRANCH= @HGBRANCH@
41+
GITVERSION= @GITVERSION@
42+
GITTAG= @GITTAG@
43+
GITBRANCH= @GITBRANCH@
4544
PGO_PROF_GEN_FLAG=@PGO_PROF_GEN_FLAG@
4645
PGO_PROF_USE_FLAG=@PGO_PROF_USE_FLAG@
4746
LLVM_PROF_MERGER=@LLVM_PROF_MERGER@
@@ -314,7 +313,7 @@ ASDLGEN= $(srcdir)/Parser/asdl_c.py
314313

315314
OPCODETARGETS_H= \
316315
$(srcdir)/Python/opcode_targets.h
317-
316+
318317
OPCODETARGETGEN= \
319318
$(srcdir)/Python/makeopcodetargets.py
320319

@@ -656,10 +655,9 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \
656655
$(MODOBJS) \
657656
$(srcdir)/Modules/getbuildinfo.c
658657
$(CC) -c $(PY_CFLAGS) \
659-
-DSVNVERSION="\"`LC_ALL=C $(SVNVERSION)`\"" \
660-
-DHGVERSION="\"`LC_ALL=C $(HGVERSION)`\"" \
661-
-DHGTAG="\"`LC_ALL=C $(HGTAG)`\"" \
662-
-DHGBRANCH="\"`LC_ALL=C $(HGBRANCH)`\"" \
658+
-DGITVERSION="\"`LC_ALL=C $(GITVERSION)`\"" \
659+
-DGITTAG="\"`LC_ALL=C $(GITTAG)`\"" \
660+
-DGITBRANCH="\"`LC_ALL=C $(GITBRANCH)`\"" \
663661
-o $@ $(srcdir)/Modules/getbuildinfo.c
664662

665663
Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ Documentation
134134
Build
135135
-----
136136

137+
- bpo-27593: sys.version and the platform module python_build(),
138+
python_branch(), and python_revision() functions now use
139+
git information rather than hg when building from a repo.
140+
137141
- bpo-29643: Fix ``--enable-optimization`` configure option didn't work.
138142

139143
- bpo-29572: Update Windows build and OS X installers to use OpenSSL 1.0.2k.

Modules/getbuildinfo.c

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,66 +20,48 @@
2020
#endif
2121
#endif
2222

23-
/* on unix, SVNVERSION is passed on the command line.
24-
* on Windows, the string is interpolated using
25-
* subwcrev.exe
26-
*/
27-
#ifndef SVNVERSION
28-
#define SVNVERSION "$WCRANGE$$WCMODS?M:$"
29-
#endif
30-
3123
/* XXX Only unix build process has been tested */
32-
#ifndef HGVERSION
33-
#define HGVERSION ""
24+
#ifndef GITVERSION
25+
#define GITVERSION ""
3426
#endif
35-
#ifndef HGTAG
36-
#define HGTAG ""
27+
#ifndef GITTAG
28+
#define GITTAG ""
3729
#endif
38-
#ifndef HGBRANCH
39-
#define HGBRANCH ""
30+
#ifndef GITBRANCH
31+
#define GITBRANCH ""
4032
#endif
4133

4234
const char *
4335
Py_GetBuildInfo(void)
4436
{
45-
static char buildinfo[50 + sizeof(HGVERSION) +
46-
((sizeof(HGTAG) > sizeof(HGBRANCH)) ?
47-
sizeof(HGTAG) : sizeof(HGBRANCH))];
48-
const char *revision = _Py_hgversion();
37+
static char buildinfo[50 + sizeof(GITVERSION) +
38+
((sizeof(GITTAG) > sizeof(GITBRANCH)) ?
39+
sizeof(GITTAG) : sizeof(GITBRANCH))];
40+
const char *revision = _Py_gitversion();
4941
const char *sep = *revision ? ":" : "";
50-
const char *hgid = _Py_hgidentifier();
51-
if (!(*hgid))
52-
hgid = "default";
42+
const char *gitid = _Py_gitidentifier();
43+
if (!(*gitid))
44+
gitid = "default";
5345
PyOS_snprintf(buildinfo, sizeof(buildinfo),
54-
"%s%s%s, %.20s, %.9s", hgid, sep, revision,
46+
"%s%s%s, %.20s, %.9s", gitid, sep, revision,
5547
DATE, TIME);
5648
return buildinfo;
5749
}
5850

5951
const char *
60-
_Py_svnversion(void)
61-
{
62-
/* the following string can be modified by subwcrev.exe */
63-
static const char svnversion[] = SVNVERSION;
64-
if (svnversion[0] != '$')
65-
return svnversion; /* it was interpolated, or passed on command line */
66-
return "Unversioned directory";
67-
}
68-
69-
const char *
70-
_Py_hgversion(void)
52+
_Py_gitversion(void)
7153
{
72-
return HGVERSION;
54+
return GITVERSION;
7355
}
7456

7557
const char *
76-
_Py_hgidentifier(void)
58+
_Py_gitidentifier(void)
7759
{
78-
const char *hgtag, *hgid;
79-
hgtag = HGTAG;
80-
if ((*hgtag) && strcmp(hgtag, "tip") != 0)
81-
hgid = hgtag;
60+
const char *gittag, *gitid;
61+
gittag = GITTAG;
62+
if ((*gittag) && strcmp(gittag, "undefined") != 0)
63+
gitid = gittag;
8264
else
83-
hgid = HGBRANCH;
84-
return hgid;
65+
gitid = GITBRANCH;
66+
return gitid;
8567
}

Python/sysmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,9 +1426,9 @@ _PySys_Init(void)
14261426
SET_SYS_FROM_STRING("subversion",
14271427
Py_BuildValue("(ssz)", "CPython", branch,
14281428
svn_revision));
1429-
SET_SYS_FROM_STRING("_mercurial",
1430-
Py_BuildValue("(szz)", "CPython", _Py_hgidentifier(),
1431-
_Py_hgversion()));
1429+
SET_SYS_FROM_STRING("_git",
1430+
Py_BuildValue("(szz)", "CPython", _Py_gitidentifier(),
1431+
_Py_gitversion()));
14321432
SET_SYS_FROM_STRING("dont_write_bytecode",
14331433
PyBool_FromLong(Py_DontWriteBytecodeFlag));
14341434
SET_SYS_FROM_STRING("api_version",

configure

Lines changed: 26 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,10 @@ MKDIR_P
683683
INSTALL_DATA
684684
INSTALL_SCRIPT
685685
INSTALL_PROGRAM
686-
HAS_HG
687-
HGBRANCH
688-
HGTAG
689-
HGVERSION
690-
SVNVERSION
686+
HAS_GIT
687+
GITBRANCH
688+
GITTAG
689+
GITVERSION
691690
ARFLAGS
692691
ac_ct_AR
693692
AR
@@ -5689,63 +5688,20 @@ then
56895688
fi
56905689
56915690
5692-
# Extract the first word of "svnversion", so it can be a program name with args.
5693-
set dummy svnversion; ac_word=$2
5694-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
5695-
$as_echo_n "checking for $ac_word... " >&6; }
5696-
if ${ac_cv_prog_SVNVERSION+:} false; then :
5697-
$as_echo_n "(cached) " >&6
5698-
else
5699-
if test -n "$SVNVERSION"; then
5700-
ac_cv_prog_SVNVERSION="$SVNVERSION" # Let the user override the test.
5701-
else
5702-
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
5703-
for as_dir in $PATH
5704-
do
5705-
IFS=$as_save_IFS
5706-
test -z "$as_dir" && as_dir=.
5707-
for ac_exec_ext in '' $ac_executable_extensions; do
5708-
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
5709-
ac_cv_prog_SVNVERSION="found"
5710-
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
5711-
break 2
5712-
fi
5713-
done
5714-
done
5715-
IFS=$as_save_IFS
57165691
5717-
test -z "$ac_cv_prog_SVNVERSION" && ac_cv_prog_SVNVERSION="not-found"
5718-
fi
5719-
fi
5720-
SVNVERSION=$ac_cv_prog_SVNVERSION
5721-
if test -n "$SVNVERSION"; then
5722-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $SVNVERSION" >&5
5723-
$as_echo "$SVNVERSION" >&6; }
5724-
else
5725-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
5726-
$as_echo "no" >&6; }
5727-
fi
57285692
57295693
5730-
if test $SVNVERSION = found
5694+
if test -e $srcdir/.git/HEAD
57315695
then
5732-
SVNVERSION="svnversion \$(srcdir)"
5733-
else
5734-
SVNVERSION="echo Unversioned directory"
5735-
fi
5736-
5737-
5738-
5739-
5740-
# Extract the first word of "hg", so it can be a program name with args.
5741-
set dummy hg; ac_word=$2
5696+
# Extract the first word of "git", so it can be a program name with args.
5697+
set dummy git; ac_word=$2
57425698
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
57435699
$as_echo_n "checking for $ac_word... " >&6; }
5744-
if ${ac_cv_prog_HAS_HG+:} false; then :
5700+
if ${ac_cv_prog_HAS_GIT+:} false; then :
57455701
$as_echo_n "(cached) " >&6
57465702
else
5747-
if test -n "$HAS_HG"; then
5748-
ac_cv_prog_HAS_HG="$HAS_HG" # Let the user override the test.
5703+
if test -n "$HAS_GIT"; then
5704+
ac_cv_prog_HAS_GIT="$HAS_GIT" # Let the user override the test.
57495705
else
57505706
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
57515707
for as_dir in $PATH
@@ -5754,36 +5710,39 @@ do
57545710
test -z "$as_dir" && as_dir=.
57555711
for ac_exec_ext in '' $ac_executable_extensions; do
57565712
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
5757-
ac_cv_prog_HAS_HG="found"
5713+
ac_cv_prog_HAS_GIT="found"
57585714
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
57595715
break 2
57605716
fi
57615717
done
57625718
done
57635719
IFS=$as_save_IFS
57645720
5765-
test -z "$ac_cv_prog_HAS_HG" && ac_cv_prog_HAS_HG="not-found"
5721+
test -z "$ac_cv_prog_HAS_GIT" && ac_cv_prog_HAS_GIT="not-found"
57665722
fi
57675723
fi
5768-
HAS_HG=$ac_cv_prog_HAS_HG
5769-
if test -n "$HAS_HG"; then
5770-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAS_HG" >&5
5771-
$as_echo "$HAS_HG" >&6; }
5724+
HAS_GIT=$ac_cv_prog_HAS_GIT
5725+
if test -n "$HAS_GIT"; then
5726+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAS_GIT" >&5
5727+
$as_echo "$HAS_GIT" >&6; }
57725728
else
57735729
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
57745730
$as_echo "no" >&6; }
57755731
fi
57765732
57775733
5778-
if test $HAS_HG = found
5734+
else
5735+
HAS_GIT=no-repository
5736+
fi
5737+
if test $HAS_GIT = found
57795738
then
5780-
HGVERSION="hg id -i \$(srcdir)"
5781-
HGTAG="hg id -t \$(srcdir)"
5782-
HGBRANCH="hg id -b \$(srcdir)"
5739+
GITVERSION="git -C \$(srcdir) rev-parse --short HEAD"
5740+
GITTAG="git -C \$(srcdir) describe --all --always --dirty"
5741+
GITBRANCH="git -C \$(srcdir) name-rev --name-only HEAD"
57835742
else
5784-
HGVERSION=""
5785-
HGTAG=""
5786-
HGBRANCH=""
5743+
GITVERSION=""
5744+
GITTAG=""
5745+
GITBRANCH=""
57875746
fi
57885747
57895748
case $MACHDEP in

configure.ac

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -979,28 +979,25 @@ then
979979
ARFLAGS="rc"
980980
fi
981981

982-
AC_SUBST(SVNVERSION)
983-
AC_CHECK_PROG(SVNVERSION, svnversion, found, not-found)
984-
if test $SVNVERSION = found
982+
AC_SUBST(GITVERSION)
983+
AC_SUBST(GITTAG)
984+
AC_SUBST(GITBRANCH)
985+
986+
if test -e $srcdir/.git/HEAD
985987
then
986-
SVNVERSION="svnversion \$(srcdir)"
988+
AC_CHECK_PROG(HAS_GIT, git, found, not-found)
987989
else
988-
SVNVERSION="echo Unversioned directory"
990+
HAS_GIT=no-repository
989991
fi
990-
991-
AC_SUBST(HGVERSION)
992-
AC_SUBST(HGTAG)
993-
AC_SUBST(HGBRANCH)
994-
AC_CHECK_PROG(HAS_HG, hg, found, not-found)
995-
if test $HAS_HG = found
992+
if test $HAS_GIT = found
996993
then
997-
HGVERSION="hg id -i \$(srcdir)"
998-
HGTAG="hg id -t \$(srcdir)"
999-
HGBRANCH="hg id -b \$(srcdir)"
994+
GITVERSION="git -C \$(srcdir) rev-parse --short HEAD"
995+
GITTAG="git -C \$(srcdir) describe --all --always --dirty"
996+
GITBRANCH="git -C \$(srcdir) name-rev --name-only HEAD"
1000997
else
1001-
HGVERSION=""
1002-
HGTAG=""
1003-
HGBRANCH=""
998+
GITVERSION=""
999+
GITTAG=""
1000+
GITBRANCH=""
10041001
fi
10051002

10061003
case $MACHDEP in

0 commit comments

Comments
 (0)