]> granicus.if.org Git - python/commitdiff
Drop sys.build_number. Add sys.subversion.
authorMartin v. Löwis <martin@v.loewis.de>
Thu, 5 Jan 2006 23:38:54 +0000 (23:38 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Thu, 5 Jan 2006 23:38:54 +0000 (23:38 +0000)
Doc/lib/libsys.tex
Include/patchlevel.h
Include/pythonrun.h
Modules/getbuildinfo.c
Python/sysmodule.c

index f8f015d05d440b928029c416993a56f83508cc44..6a82d1b2a41e23f17639d1558571754198ba3989 100644 (file)
@@ -27,10 +27,19 @@ It is always available.
   \versionadded{2.0}
 \end{datadesc}
 
-\begin{datadesc}{build_number}
-  A string representing the Subversion revision that this Python executable
-  was built from.  This number is a string because it may contain a trailing
-  'M' if Python was built from a mixed revision source tree.
+\begin{datadesc}{subversion}
+  A triple (repo, branch, version) representing the Subversion
+  information of the Python interpreter.
+  \var{repo} is the name of the repository, \code{'CPython'}.
+  \var{branch} is the a string of one of the forms \code{'trunk'},
+  \code{'branches/name'} or \code{'tags/name'}.
+  \var{version} is the output of \code{svnversion}, if the
+  interpreter was built from a Subversion checkout; it contains
+  the revision number (range) and possibly a trailing 'M' if
+  there were local modifications. If the tree was exported
+  (or svnversion was not available), it is the revision of
+  \code{Include/patchlevel.h} if the branch is a tag. Otherwise,
+  it is \code{None}.
   \versionadded{2.5}
 \end{datadesc}  
 
index 58ba053da53befae425685acc775bc9afe3b5a00..2904fb6b3a56baf16316b85fac38cbe045f3e893 100644 (file)
@@ -28,6 +28,9 @@
 /* Version as a string */
 #define PY_VERSION             "2.5a0"
 
+/* Subversion Revision number of this file (not of the repository) */
+#define PY_PATCHLEVEL_REVISION  "$Revision$"
+
 /* Version as a single 4-byte hex number, e.g. 0x010502B2 == 1.5.2b2.
    Use this for numeric comparisons, e.g. #if PY_VERSION_HEX >= ... */
 #define PY_VERSION_HEX ((PY_MAJOR_VERSION << 24) | \
index 6cf33d8723f4d482c6d392011282d76697c86f7c..5c78cce60514ec970da439fff87ad938bb629360 100644 (file)
@@ -108,7 +108,9 @@ PyAPI_FUNC(const char *) Py_GetPlatform(void);
 PyAPI_FUNC(const char *) Py_GetCopyright(void);
 PyAPI_FUNC(const char *) Py_GetCompiler(void);
 PyAPI_FUNC(const char *) Py_GetBuildInfo(void);
-PyAPI_FUNC(const char *) Py_GetBuildNumber(void);
+PyAPI_FUNC(const char *) _Py_svnversion(void);
+PyAPI_FUNC(const char *) Py_SubversionRevision(void);
+PyAPI_FUNC(const char *) Py_SubversionShortBranch(void);
 
 /* Internal -- various one-time initializations */
 PyAPI_FUNC(PyObject *) _PyBuiltin_Init(void);
index 1ff061f99d2a39d313fc41dec366162dce248a69..3312a87c2b103ca605a45022d77b583185040b96 100644 (file)
 #endif
 #endif
 
-static const char revision[] = "$Revision$";
-static const char headurl[] = "$HeadURL$";
-
 const char *
 Py_GetBuildInfo(void)
 {
        static char buildinfo[50];
-#ifdef SVNVERSION
-       static char svnversion[50] = SVNVERSION;
-#else
-       static char svnversion[50] = "exported";
-#endif
-       if (strcmp(svnversion, "exported") == 0 &&
-           strstr(headurl, "/tags/") != NULL) {
-               int start = 11;
-               int stop = strlen(revision)-2;
-               strncpy(svnversion, revision+start, stop-start);
-               svnversion[stop-start] = '\0';
-       }
+       char *revision = Py_SubversionRevision();
+       char *sep = revision ? ":" : "";
+       char *branch = Py_SubversionShortBranch();
        PyOS_snprintf(buildinfo, sizeof(buildinfo),
-                     "%s, %.20s, %.9s", svnversion, DATE, TIME);
+                     "%s%s%s, %.20s, %.9s", branch, sep, revision, 
+                     DATE, TIME);
        return buildinfo;
 }
 
 const char *
-Py_GetBuildNumber(void)
+_Py_svnversion(void)
 {
-       return "0";
+#ifdef SVNVERSION
+       return SVNVERSION;
+#else
+       return "exported";
+#endif
 }
index f97a56deb5b25af0eab8a2fa22f45d7fdafc2caa..db0d1a62dd77e0a7cbd0ef1390b2c0185b0de1c6 100644 (file)
@@ -934,6 +934,87 @@ _check_and_flush (FILE *stream)
   return fflush (stream) || prev_fail ? EOF : 0;
 }
 
+/* Subversion branch and revision management */
+static const char _patchlevel_revision[] = PY_PATCHLEVEL_REVISION;
+static const char headurl[] = "$HeadURL$";
+static int svn_initialized;
+static char patchlevel_revision[50]; /* Just the number */
+static char branch[50];
+static char shortbranch[50];
+static const char *svn_revision;
+
+static void svnversion_init(void)
+{
+       const char *python, *br_start, *br_end, *br_end2, *svnversion;
+       int len, istag;
+
+       if (svn_initialized)
+               return;
+
+       python = strstr(headurl, "/python/");
+       if (!python)
+               Py_FatalError("subversion keywords missing");
+
+       br_start = python + 8;
+       br_end = strchr(br_start, '/');
+       /* Works even for trunk, 
+          as we are in trunk/Python/sysmodule.c */
+       br_end2 = strchr(br_end+1, '/');
+
+       istag = strncmp(br_start, "tags", 4) == 0;
+       if (strncmp(br_start, "trunk", 5) == 0) {
+               strcpy(branch, "trunk");
+               strcpy(shortbranch, "trunk");
+
+       } 
+       else if (istag || strncmp(br_start, "branches", 8) == 0) {
+               len = br_end2 - br_start;
+               strncpy(branch, br_start, len);
+               branch[len] = '\0';
+
+               len = br_end2 - (br_end + 1);
+               strncpy(shortbranch, br_end + 1, len);
+               shortbranch[len] = '\0';
+       } 
+       else {
+               Py_FatalError("bad HeadURL");
+               return;
+       }
+
+
+       svnversion = _Py_svnversion();
+       if (strcmp(svnversion, "exported") != 0)
+               svn_revision = svnversion;
+       else if (istag) {
+               len = strlen(_patchlevel_revision);
+               strncpy(patchlevel_revision, _patchlevel_revision + 11,
+                       len - 13);
+               patchlevel_revision[len - 13] = '\0';
+               svn_revision = patchlevel_revision;
+       }
+       else
+               svn_revision = "";
+       
+       svn_initialized = 1;
+}
+
+/* Return svnversion output if available.
+   Else return Revision of patchlevel.h if on branch.
+   Else return empty string */
+const char*
+Py_SubversionRevision()
+{
+       svnversion_init();
+       return svn_revision;
+}
+
+const char*
+Py_SubversionShortBranch()
+{
+       svnversion_init();
+       return shortbranch;
+}
+
 PyObject *
 _PySys_Init(void)
 {
@@ -1003,8 +1084,9 @@ _PySys_Init(void)
        PyDict_SetItemString(sysdict, "hexversion",
                             v = PyInt_FromLong(PY_VERSION_HEX));
        Py_XDECREF(v);
-       PyDict_SetItemString(sysdict, "build_number",
-                            v = PyString_FromString(Py_GetBuildNumber()));
+       svnversion_init();
+       v = Py_BuildValue("(ssz)", "CPython", branch, svn_revision);
+       PyDict_SetItemString(sysdict, "subversion", v);
        Py_XDECREF(v);
        /*
         * These release level checks are mutually exclusive and cover