Skip to content

Commit a2edd3a

Browse files
authored
[3.5] bpo-27593: Get SCM build info from git instead of hg. (#446) (#454) (#455)
* bpo-27593: Get SCM build info from git instead of hg. (#446) sys.version and the platform module python_build(), python_branch(), and python_revision() functions now use git information rather than hg when building from a repo. Based on original patches by Brett Cannon and Steve Dower. (cherry picked from commit 5c4b0d0) (cherry picked from commit 95c50e5)
1 parent 2df52ac commit a2edd3a

File tree

9 files changed

+80
-83
lines changed

9 files changed

+80
-83
lines changed

Include/pylifecycle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ PyAPI_FUNC(const char *) Py_GetCopyright(void);
6969
PyAPI_FUNC(const char *) Py_GetCompiler(void);
7070
PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
7171
#ifndef Py_LIMITED_API
72-
PyAPI_FUNC(const char *) _Py_hgidentifier(void);
73-
PyAPI_FUNC(const char *) _Py_hgversion(void);
72+
PyAPI_FUNC(const char *) _Py_gitidentifier(void);
73+
PyAPI_FUNC(const char *) _Py_gitversion(void);
7474
#endif
7575

7676
/* Internal -- various one-time initializations */

Lib/platform.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,9 @@ def _sys_version(sys_version=None):
11991199
elif buildtime:
12001200
builddate = builddate + ' ' + buildtime
12011201

1202-
if hasattr(sys, '_mercurial'):
1202+
if hasattr(sys, '_git'):
1203+
_, branch, revision = sys._git
1204+
elif hasattr(sys, '_mercurial'):
12031205
_, branch, revision = sys._mercurial
12041206
elif hasattr(sys, 'subversion'):
12051207
# sys.subversion was added in Python 2.5

Lib/test/test_platform.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ def test_processor(self):
6666

6767
def setUp(self):
6868
self.save_version = sys.version
69-
self.save_mercurial = sys._mercurial
69+
self.save_git = sys._git
7070
self.save_platform = sys.platform
7171

7272
def tearDown(self):
7373
sys.version = self.save_version
74-
sys._mercurial = self.save_mercurial
74+
sys._git = self.save_git
7575
sys.platform = self.save_platform
7676

7777
def test_sys_version(self):
@@ -101,7 +101,7 @@ def test_sys_version(self):
101101
('CPython', '2.4.3', '', '', 'truncation', '', 'GCC')),
102102
):
103103
# branch and revision are not "parsed", but fetched
104-
# from sys._mercurial. Ignore them
104+
# from sys._git. Ignore them
105105
(name, version, branch, revision, buildno, builddate, compiler) \
106106
= platform._sys_version(input)
107107
self.assertEqual(
@@ -148,10 +148,10 @@ def test_sys_version(self):
148148
sys_versions.items():
149149
sys.version = version_tag
150150
if subversion is None:
151-
if hasattr(sys, "_mercurial"):
152-
del sys._mercurial
151+
if hasattr(sys, "_git"):
152+
del sys._git
153153
else:
154-
sys._mercurial = subversion
154+
sys._git = subversion
155155
if sys_platform is not None:
156156
sys.platform = sys_platform
157157
self.assertEqual(platform.python_implementation(), info[0])

Makefile.pre.in

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ RANLIB= @RANLIB@
4141
READELF= @READELF@
4242
SOABI= @SOABI@
4343
LDVERSION= @LDVERSION@
44-
HGVERSION= @HGVERSION@
45-
HGTAG= @HGTAG@
46-
HGBRANCH= @HGBRANCH@
44+
GITVERSION= @GITVERSION@
45+
GITTAG= @GITTAG@
46+
GITBRANCH= @GITBRANCH@
4747
PGO_PROF_GEN_FLAG=@PGO_PROF_GEN_FLAG@
4848
PGO_PROF_USE_FLAG=@PGO_PROF_USE_FLAG@
4949
LLVM_PROF_MERGER=@LLVM_PROF_MERGER@
@@ -739,9 +739,9 @@ Modules/getbuildinfo.o: $(PARSER_OBJS) \
739739
$(MODOBJS) \
740740
$(srcdir)/Modules/getbuildinfo.c
741741
$(CC) -c $(PY_CORE_CFLAGS) \
742-
-DHGVERSION="\"`LC_ALL=C $(HGVERSION)`\"" \
743-
-DHGTAG="\"`LC_ALL=C $(HGTAG)`\"" \
744-
-DHGBRANCH="\"`LC_ALL=C $(HGBRANCH)`\"" \
742+
-DGITVERSION="\"`LC_ALL=C $(GITVERSION)`\"" \
743+
-DGITTAG="\"`LC_ALL=C $(GITTAG)`\"" \
744+
-DGITBRANCH="\"`LC_ALL=C $(GITBRANCH)`\"" \
745745
-o $@ $(srcdir)/Modules/getbuildinfo.c
746746

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

Misc/NEWS

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ Tests
127127
determine the candidate encoding for the test regex (allowing it to correctly
128128
skip the test when the default locale encoding is a multi-byte encoding)
129129

130-
Build
131-
-----
132-
133-
- bpo-29572: Update Windows build and OS X installers to use OpenSSL 1.0.2k.
134-
135130

136131
What's New in Python 3.5.3?
137132
===========================

Modules/getbuildinfo.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,47 @@
2121
#endif
2222

2323
/* XXX Only unix build process has been tested */
24-
#ifndef HGVERSION
25-
#define HGVERSION ""
24+
#ifndef GITVERSION
25+
#define GITVERSION ""
2626
#endif
27-
#ifndef HGTAG
28-
#define HGTAG ""
27+
#ifndef GITTAG
28+
#define GITTAG ""
2929
#endif
30-
#ifndef HGBRANCH
31-
#define HGBRANCH ""
30+
#ifndef GITBRANCH
31+
#define GITBRANCH ""
3232
#endif
3333

3434
const char *
3535
Py_GetBuildInfo(void)
3636
{
37-
static char buildinfo[50 + sizeof(HGVERSION) +
38-
((sizeof(HGTAG) > sizeof(HGBRANCH)) ?
39-
sizeof(HGTAG) : sizeof(HGBRANCH))];
40-
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();
4141
const char *sep = *revision ? ":" : "";
42-
const char *hgid = _Py_hgidentifier();
43-
if (!(*hgid))
44-
hgid = "default";
42+
const char *gitid = _Py_gitidentifier();
43+
if (!(*gitid))
44+
gitid = "default";
4545
PyOS_snprintf(buildinfo, sizeof(buildinfo),
46-
"%s%s%s, %.20s, %.9s", hgid, sep, revision,
46+
"%s%s%s, %.20s, %.9s", gitid, sep, revision,
4747
DATE, TIME);
4848
return buildinfo;
4949
}
5050

5151
const char *
52-
_Py_hgversion(void)
52+
_Py_gitversion(void)
5353
{
54-
return HGVERSION;
54+
return GITVERSION;
5555
}
5656

5757
const char *
58-
_Py_hgidentifier(void)
58+
_Py_gitidentifier(void)
5959
{
60-
const char *hgtag, *hgid;
61-
hgtag = HGTAG;
62-
if ((*hgtag) && strcmp(hgtag, "tip") != 0)
63-
hgid = hgtag;
60+
const char *gittag, *gitid;
61+
gittag = GITTAG;
62+
if ((*gittag) && strcmp(gittag, "undefined") != 0)
63+
gitid = gittag;
6464
else
65-
hgid = HGBRANCH;
66-
return hgid;
65+
gitid = GITBRANCH;
66+
return gitid;
6767
}

Python/sysmodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,9 +1816,9 @@ _PySys_Init(void)
18161816
PyUnicode_FromString(Py_GetVersion()));
18171817
SET_SYS_FROM_STRING("hexversion",
18181818
PyLong_FromLong(PY_VERSION_HEX));
1819-
SET_SYS_FROM_STRING("_mercurial",
1820-
Py_BuildValue("(szz)", "CPython", _Py_hgidentifier(),
1821-
_Py_hgversion()));
1819+
SET_SYS_FROM_STRING("_git",
1820+
Py_BuildValue("(szz)", "CPython", _Py_gitidentifier(),
1821+
_Py_gitversion()));
18221822
SET_SYS_FROM_STRING("dont_write_bytecode",
18231823
PyBool_FromLong(Py_DontWriteBytecodeFlag));
18241824
SET_SYS_FROM_STRING("api_version",

configure

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,10 @@ build_os
757757
build_vendor
758758
build_cpu
759759
build
760-
HAS_HG
761-
HGBRANCH
762-
HGTAG
763-
HGVERSION
760+
HAS_GIT
761+
GITBRANCH
762+
GITTAG
763+
GITVERSION
764764
BASECPPFLAGS
765765
target_alias
766766
host_alias
@@ -2839,17 +2839,17 @@ fi
28392839

28402840

28412841

2842-
if test -e $srcdir/.hg/dirstate
2842+
if test -e $srcdir/.git/HEAD
28432843
then
2844-
# Extract the first word of "hg", so it can be a program name with args.
2845-
set dummy hg; ac_word=$2
2844+
# Extract the first word of "git", so it can be a program name with args.
2845+
set dummy git; ac_word=$2
28462846
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
28472847
$as_echo_n "checking for $ac_word... " >&6; }
2848-
if ${ac_cv_prog_HAS_HG+:} false; then :
2848+
if ${ac_cv_prog_HAS_GIT+:} false; then :
28492849
$as_echo_n "(cached) " >&6
28502850
else
2851-
if test -n "$HAS_HG"; then
2852-
ac_cv_prog_HAS_HG="$HAS_HG" # Let the user override the test.
2851+
if test -n "$HAS_GIT"; then
2852+
ac_cv_prog_HAS_GIT="$HAS_GIT" # Let the user override the test.
28532853
else
28542854
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
28552855
for as_dir in $PATH
@@ -2858,39 +2858,39 @@ do
28582858
test -z "$as_dir" && as_dir=.
28592859
for ac_exec_ext in '' $ac_executable_extensions; do
28602860
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
2861-
ac_cv_prog_HAS_HG="found"
2861+
ac_cv_prog_HAS_GIT="found"
28622862
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
28632863
break 2
28642864
fi
28652865
done
28662866
done
28672867
IFS=$as_save_IFS
28682868

2869-
test -z "$ac_cv_prog_HAS_HG" && ac_cv_prog_HAS_HG="not-found"
2869+
test -z "$ac_cv_prog_HAS_GIT" && ac_cv_prog_HAS_GIT="not-found"
28702870
fi
28712871
fi
2872-
HAS_HG=$ac_cv_prog_HAS_HG
2873-
if test -n "$HAS_HG"; then
2874-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAS_HG" >&5
2875-
$as_echo "$HAS_HG" >&6; }
2872+
HAS_GIT=$ac_cv_prog_HAS_GIT
2873+
if test -n "$HAS_GIT"; then
2874+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAS_GIT" >&5
2875+
$as_echo "$HAS_GIT" >&6; }
28762876
else
28772877
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
28782878
$as_echo "no" >&6; }
28792879
fi
28802880

28812881

28822882
else
2883-
HAS_HG=no-repository
2883+
HAS_GIT=no-repository
28842884
fi
2885-
if test $HAS_HG = found
2885+
if test $HAS_GIT = found
28862886
then
2887-
HGVERSION="hg id -i \$(srcdir)"
2888-
HGTAG="hg id -t \$(srcdir)"
2889-
HGBRANCH="hg id -b \$(srcdir)"
2887+
GITVERSION="git -C \$(srcdir) rev-parse HEAD"
2888+
GITTAG="git -C \$(srcdir) name-rev --tags --name-only HEAD"
2889+
GITBRANCH="git -C \$(srcdir) name-rev --name-only HEAD"
28902890
else
2891-
HGVERSION=""
2892-
HGTAG=""
2893-
HGBRANCH=""
2891+
GITVERSION=""
2892+
GITTAG=""
2893+
GITBRANCH=""
28942894
fi
28952895

28962896

configure.ac

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ else
2525
BASECPPFLAGS=""
2626
fi
2727

28-
AC_SUBST(HGVERSION)
29-
AC_SUBST(HGTAG)
30-
AC_SUBST(HGBRANCH)
28+
AC_SUBST(GITVERSION)
29+
AC_SUBST(GITTAG)
30+
AC_SUBST(GITBRANCH)
3131

32-
if test -e $srcdir/.hg/dirstate
32+
if test -e $srcdir/.git/HEAD
3333
then
34-
AC_CHECK_PROG(HAS_HG, hg, found, not-found)
34+
AC_CHECK_PROG(HAS_GIT, git, found, not-found)
3535
else
36-
HAS_HG=no-repository
36+
HAS_GIT=no-repository
3737
fi
38-
if test $HAS_HG = found
38+
if test $HAS_GIT = found
3939
then
40-
HGVERSION="hg id -i \$(srcdir)"
41-
HGTAG="hg id -t \$(srcdir)"
42-
HGBRANCH="hg id -b \$(srcdir)"
40+
GITVERSION="git -C \$(srcdir) rev-parse HEAD"
41+
GITTAG="git -C \$(srcdir) name-rev --tags --name-only HEAD"
42+
GITBRANCH="git -C \$(srcdir) name-rev --name-only HEAD"
4343
else
44-
HGVERSION=""
45-
HGTAG=""
46-
HGBRANCH=""
44+
GITVERSION=""
45+
GITTAG=""
46+
GITBRANCH=""
4747
fi
4848

4949
AC_CONFIG_SRCDIR([Include/object.h])

0 commit comments

Comments
 (0)