D2939: fsmonitor: layer on another hack in bser.c for os.stat() compat (issue5811)

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Sat Mar 24 14:52:06 EDT 2018


durin42 updated this revision to Diff 7271.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2939?vs=7270&id=7271

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
@@ -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);
 }
 



To: durin42, #hg-reviewers
Cc: indygreg, mercurial-devel


More information about the Mercurial-devel mailing list