comparison Python/sysmodule.c @ 36207:825a041813fb legacy-trunk

Drop sys.build_number. Add sys.subversion.
author Martin v. Löwis <martin@v.loewis.de>
date Thu, 05 Jan 2006 23:38:54 +0000
parents 9697eeeaf246
children 6d743e5baf14
comparison
equal deleted inserted replaced
36205:01cbed5e8731 36207:825a041813fb
932 { 932 {
933 int prev_fail = ferror (stream); 933 int prev_fail = ferror (stream);
934 return fflush (stream) || prev_fail ? EOF : 0; 934 return fflush (stream) || prev_fail ? EOF : 0;
935 } 935 }
936 936
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
937 PyObject * 1018 PyObject *
938 _PySys_Init(void) 1019 _PySys_Init(void)
939 { 1020 {
940 PyObject *m, *v, *sysdict; 1021 PyObject *m, *v, *sysdict;
941 PyObject *sysin, *sysout, *syserr; 1022 PyObject *sysin, *sysout, *syserr;
1001 v = PyString_FromString(Py_GetVersion())); 1082 v = PyString_FromString(Py_GetVersion()));
1002 Py_XDECREF(v); 1083 Py_XDECREF(v);
1003 PyDict_SetItemString(sysdict, "hexversion", 1084 PyDict_SetItemString(sysdict, "hexversion",
1004 v = PyInt_FromLong(PY_VERSION_HEX)); 1085 v = PyInt_FromLong(PY_VERSION_HEX));
1005 Py_XDECREF(v); 1086 Py_XDECREF(v);
1006 PyDict_SetItemString(sysdict, "build_number", 1087 svnversion_init();
1007 v = PyString_FromString(Py_GetBuildNumber())); 1088 v = Py_BuildValue("(ssz)", "CPython", branch, svn_revision);
1089 PyDict_SetItemString(sysdict, "subversion", v);
1008 Py_XDECREF(v); 1090 Py_XDECREF(v);
1009 /* 1091 /*
1010 * These release level checks are mutually exclusive and cover 1092 * These release level checks are mutually exclusive and cover
1011 * the field, so don't get too fancy with the pre-processor! 1093 * the field, so don't get too fancy with the pre-processor!
1012 */ 1094 */