Patchwork D7204: fsmonitor: reapply b1f62cd39b5c

login
register
mail settings
Submitter phabricator
Date Nov. 2, 2019, 10:04 p.m.
Message ID <differential-rev-PHID-DREV-jllh6ca36qwcqspi3kdk-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42686/
State Superseded
Headers show

Comments

phabricator - Nov. 2, 2019, 10:04 p.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The recent revendoring of pywatchman undid this changeset.
  Let's reapply it.
  
  This commit was generated by running `hg graft -f b1f62cd39b5c`.
  It applied cleanly.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D7204

AFFECTED FILES
  hgext/fsmonitor/pywatchman/bser.c

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 20, 2019, 5:51 p.m.
marmoute added a comment.


  Same question as for D7203 <https://phab.mercurial-scm.org/D7203> Out of curiosity, was the fix submitted upstream too ?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7204/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7204

To: indygreg, #hg-reviewers
Cc: marmoute, 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
@@ -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) {