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

login
register
mail settings
Submitter phabricator
Date March 24, 2018, 6:52 p.m.
Message ID <cdf519a9e5920244fecc0bbbf3dd464b@localhost.localdomain>
Download mbox | patch
Permalink /patch/29821/
State Not Applicable
Headers show

Comments

phabricator - March 24, 2018, 6:52 p.m.
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




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

Patch

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