Skip to content

Commit 43b5780

Browse files
committed
Drop sys.build_number. Add sys.subversion.
1 parent 2b47445 commit 43b5780

File tree

5 files changed

+114
-25
lines changed

5 files changed

+114
-25
lines changed

Doc/lib/libsys.tex

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,19 @@ \section{\module{sys} ---
2727
\versionadded{2.0}
2828
\end{datadesc}
2929

30-
\begin{datadesc}{build_number}
31-
A string representing the Subversion revision that this Python executable
32-
was built from. This number is a string because it may contain a trailing
33-
'M' if Python was built from a mixed revision source tree.
30+
\begin{datadesc}{subversion}
31+
A triple (repo, branch, version) representing the Subversion
32+
information of the Python interpreter.
33+
\var{repo} is the name of the repository, \code{'CPython'}.
34+
\var{branch} is the a string of one of the forms \code{'trunk'},
35+
\code{'branches/name'} or \code{'tags/name'}.
36+
\var{version} is the output of \code{svnversion}, if the
37+
interpreter was built from a Subversion checkout; it contains
38+
the revision number (range) and possibly a trailing 'M' if
39+
there were local modifications. If the tree was exported
40+
(or svnversion was not available), it is the revision of
41+
\code{Include/patchlevel.h} if the branch is a tag. Otherwise,
42+
it is \code{None}.
3443
\versionadded{2.5}
3544
\end{datadesc}
3645

Include/patchlevel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
/* Version as a string */
2929
#define PY_VERSION "2.5a0"
3030

31+
/* Subversion Revision number of this file (not of the repository) */
32+
#define PY_PATCHLEVEL_REVISION "$Revision$"
33+
3134
/* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
3235
Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ... */
3336
#define PY_VERSION_HEX ((PY_MAJOR_VERSION << 24) | \

Include/pythonrun.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ PyAPI_FUNC(const char *) Py_GetPlatform(void);
108108
PyAPI_FUNC(const char *) Py_GetCopyright(void);
109109
PyAPI_FUNC(const char *) Py_GetCompiler(void);
110110
PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
111-
PyAPI_FUNC(const char *) Py_GetBuildNumber(void);
111+
PyAPI_FUNC(const char *) _Py_svnversion(void);
112+
PyAPI_FUNC(const char *) Py_SubversionRevision(void);
113+
PyAPI_FUNC(const char *) Py_SubversionShortBranch(void);
112114

113115
/* Internal -- various one-time initializations */
114116
PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);

Modules/getbuildinfo.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,25 @@
2020
#endif
2121
#endif
2222

23-
static const char revision[] = "$Revision$";
24-
static const char headurl[] = "$HeadURL$";
25-
2623
const char *
2724
Py_GetBuildInfo(void)
2825
{
2926
static char buildinfo[50];
30-
#ifdef SVNVERSION
31-
static char svnversion[50] = SVNVERSION;
32-
#else
33-
static char svnversion[50] = "exported";
34-
#endif
35-
if (strcmp(svnversion, "exported") == 0 &&
36-
strstr(headurl, "/tags/") != NULL) {
37-
int start = 11;
38-
int stop = strlen(revision)-2;
39-
strncpy(svnversion, revision+start, stop-start);
40-
svnversion[stop-start] = '\0';
41-
}
27+
char *revision = Py_SubversionRevision();
28+
char *sep = revision ? ":" : "";
29+
char *branch = Py_SubversionShortBranch();
4230
PyOS_snprintf(buildinfo, sizeof(buildinfo),
43-
"%s, %.20s, %.9s", svnversion, DATE, TIME);
31+
"%s%s%s, %.20s, %.9s", branch, sep, revision,
32+
DATE, TIME);
4433
return buildinfo;
4534
}
4635

4736
const char *
48-
Py_GetBuildNumber(void)
37+
_Py_svnversion(void)
4938
{
50-
return "0";
39+
#ifdef SVNVERSION
40+
return SVNVERSION;
41+
#else
42+
return "exported";
43+
#endif
5144
}

Python/sysmodule.c

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,87 @@ _check_and_flush (FILE *stream)
934934
return fflush (stream) || prev_fail ? EOF : 0;
935935
}
936936

937+
/* Subversion branch and revision management */
938+
static const char _patchlevel_revision[] = PY_PATCHLEVEL_REVISION;
939+
static const char headurl[] = "$HeadURL$";
940+
static int svn_initialized;
941+
static char patchlevel_revision[50]; /* Just the number */
942+
static char branch[50];
943+
static char shortbranch[50];
944+
static const char *svn_revision;
945+
946+
static void svnversion_init(void)
947+
{
948+
const char *python, *br_start, *br_end, *br_end2, *svnversion;
949+
int len, istag;
950+
951+
if (svn_initialized)
952+
return;
953+
954+
python = strstr(headurl, "/python/");
955+
if (!python)
956+
Py_FatalError("subversion keywords missing");
957+
958+
br_start = python + 8;
959+
br_end = strchr(br_start, '/');
960+
/* Works even for trunk,
961+
as we are in trunk/Python/sysmodule.c */
962+
br_end2 = strchr(br_end+1, '/');
963+
964+
istag = strncmp(br_start, "tags", 4) == 0;
965+
if (strncmp(br_start, "trunk", 5) == 0) {
966+
strcpy(branch, "trunk");
967+
strcpy(shortbranch, "trunk");
968+
969+
}
970+
else if (istag || strncmp(br_start, "branches", 8) == 0) {
971+
len = br_end2 - br_start;
972+
strncpy(branch, br_start, len);
973+
branch[len] = '\0';
974+
975+
len = br_end2 - (br_end + 1);
976+
strncpy(shortbranch, br_end + 1, len);
977+
shortbranch[len] = '\0';
978+
}
979+
else {
980+
Py_FatalError("bad HeadURL");
981+
return;
982+
}
983+
984+
985+
svnversion = _Py_svnversion();
986+
if (strcmp(svnversion, "exported") != 0)
987+
svn_revision = svnversion;
988+
else if (istag) {
989+
len = strlen(_patchlevel_revision);
990+
strncpy(patchlevel_revision, _patchlevel_revision + 11,
991+
len - 13);
992+
patchlevel_revision[len - 13] = '\0';
993+
svn_revision = patchlevel_revision;
994+
}
995+
else
996+
svn_revision = "";
997+
998+
svn_initialized = 1;
999+
}
1000+
1001+
/* Return svnversion output if available.
1002+
Else return Revision of patchlevel.h if on branch.
1003+
Else return empty string */
1004+
const char*
1005+
Py_SubversionRevision()
1006+
{
1007+
svnversion_init();
1008+
return svn_revision;
1009+
}
1010+
1011+
const char*
1012+
Py_SubversionShortBranch()
1013+
{
1014+
svnversion_init();
1015+
return shortbranch;
1016+
}
1017+
9371018
PyObject *
9381019
_PySys_Init(void)
9391020
{
@@ -1003,8 +1084,9 @@ _PySys_Init(void)
10031084
PyDict_SetItemString(sysdict, "hexversion",
10041085
v = PyInt_FromLong(PY_VERSION_HEX));
10051086
Py_XDECREF(v);
1006-
PyDict_SetItemString(sysdict, "build_number",
1007-
v = PyString_FromString(Py_GetBuildNumber()));
1087+
svnversion_init();
1088+
v = Py_BuildValue("(ssz)", "CPython", branch, svn_revision);
1089+
PyDict_SetItemString(sysdict, "subversion", v);
10081090
Py_XDECREF(v);
10091091
/*
10101092
* These release level checks are mutually exclusive and cover

0 commit comments

Comments
 (0)