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 @@ -96,9 +96,21 @@ return PySequence_Length(obj->keys); } +// Prototype for this function so we can use it before its definition. +static PyObject* bserobj_getattrro(PyObject* o, PyObject* name); + static PyObject* bserobj_tuple_item(PyObject* o, Py_ssize_t i) { bserObject* obj = (bserObject*)o; + if (i == 8 && PySequence_Size(obj->values) < 7) { + // 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. + return bserobj_getattrro(o, PyBytes_FromString("st_mtime")); + } return PySequence_GetItem(obj->values, i); }