durin42 updated this revision to Diff 7915. durin42 marked 4 inline comments as done. durin42 edited the summary of this revision.
REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2939?vs=7271&id=7915 REVISION DETAIL https://phab.mercurial-scm.org/D2939 AFFECTED FILES hgext/fsmonitor/pywatchman/bser.c CHANGE DETAILS diff --git a/hgext/fsmonitor/pywatchman/bser.c b/hgext/fsmonitor/pywatchman/bser.c --- a/hgext/fsmonitor/pywatchman/bser.c +++ b/hgext/fsmonitor/pywatchman/bser.c @@ -128,27 +128,38 @@ Py_ssize_t i, n; PyObject* name_bytes = NULL; PyObject* ret = NULL; - const char* namestr; + const char* namestr = NULL; if (PyIndex_Check(name)) { i = PyNumber_AsSsize_t(name, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) { goto bail; } - ret = PySequence_GetItem(obj->values, i); - goto bail; - } - // We can be passed in Unicode objects here -- we don't support anything other - // than UTF-8 for keys. - if (PyUnicode_Check(name)) { - name_bytes = PyUnicode_AsUTF8String(name); - if (name_bytes == NULL) { + if (i == 8 && PySequence_Size(obj->values) < 9) { + // Hack alert: Python 3 removed support for os.stat().st_mtime + // being an integer.Instead, if you need an integer, you have to + // use os.stat()[stat.ST_MTIME] instead. stat.ST_MTIME is 8, and + // our stat tuples are shorter than that, so we can detect + // requests for index 8 on tuples shorter than that and return + // st_mtime instead. + namestr = "st_mtime"; + } else { + ret = PySequence_GetItem(obj->values, i); goto bail; } - namestr = PyBytes_AsString(name_bytes); } else { - namestr = PyBytes_AsString(name); + // We can be passed in Unicode objects here -- we don't support anything other + // than UTF-8 for keys. + if (PyUnicode_Check(name)) { + name_bytes = PyUnicode_AsUTF8String(name); + if (name_bytes == NULL) { + goto bail; + } + namestr = PyBytes_AsString(name_bytes); + } else { + namestr = PyBytes_AsString(name); + } } if (namestr == NULL) { To: durin42, #hg-reviewers, indygreg Cc: spectral, indygreg, mercurial-devel _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel