D2695: osutil: implement minimal __getitem__ compatibility on our custom listdir type
This revision was automatically updated to reflect the committed changes. Closed by commit rHGf3c314020beb: osutil: implement minimal __getitem__ compatibility on our custom listdir type (authored by durin42, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2695?vs=6678&id=6727 REVISION DETAIL https://phab.mercurial-scm.org/D2695 AFFECTED FILES mercurial/cext/osutil.c mercurial/policy.py CHANGE DETAILS diff --git a/mercurial/policy.py b/mercurial/policy.py --- a/mercurial/policy.py +++ b/mercurial/policy.py @@ -69,7 +69,7 @@ (r'cext', r'bdiff'): 3, (r'cext', r'diffhelpers'): 1, (r'cext', r'mpatch'): 1, -(r'cext', r'osutil'): 3, +(r'cext', r'osutil'): 4, (r'cext', r'parsers'): 4, } diff --git a/mercurial/cext/osutil.c b/mercurial/cext/osutil.c --- a/mercurial/cext/osutil.c +++ b/mercurial/cext/osutil.c @@ -121,6 +121,27 @@ o->ob_type->tp_free(o); } +static PyObject *listdir_stat_getitem(PyObject *self, PyObject *key) +{ + long index = PyLong_AsLong(key); + if (index == -1 && PyErr_Occurred()) { + return NULL; + } + if (index != 8) { + PyErr_Format(PyExc_IndexError, "osutil.stat objects only " + "support stat.ST_MTIME in " + "__getitem__"); + return NULL; + } + return listdir_stat_st_mtime(self, NULL); +} + +static PyMappingMethods listdir_stat_type_mapping_methods = { + (lenfunc)NULL, /* mp_length */ + (binaryfunc)listdir_stat_getitem, /* mp_subscript */ + (objobjargproc)NULL,/* mp_ass_subscript */ +}; + static PyTypeObject listdir_stat_type = { PyVarObject_HEAD_INIT(NULL, 0) /* header */ "osutil.stat", /*tp_name*/ @@ -134,7 +155,7 @@ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ + &listdir_stat_type_mapping_methods, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ @@ -1352,7 +1373,7 @@ {NULL, NULL} }; -static const int version = 3; +static const int version = 4; #ifdef IS_PY3K static struct PyModuleDef osutil_module = { To: durin42, #hg-reviewers, indygreg, yuja Cc: mharbison72, indygreg, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2695: osutil: implement minimal __getitem__ compatibility on our custom listdir type
durin42 updated this revision to Diff 6678. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2695?vs=6675&id=6678 REVISION DETAIL https://phab.mercurial-scm.org/D2695 AFFECTED FILES mercurial/cext/osutil.c mercurial/policy.py CHANGE DETAILS diff --git a/mercurial/policy.py b/mercurial/policy.py --- a/mercurial/policy.py +++ b/mercurial/policy.py @@ -69,7 +69,7 @@ (r'cext', r'bdiff'): 3, (r'cext', r'diffhelpers'): 1, (r'cext', r'mpatch'): 1, -(r'cext', r'osutil'): 3, +(r'cext', r'osutil'): 4, (r'cext', r'parsers'): 4, } diff --git a/mercurial/cext/osutil.c b/mercurial/cext/osutil.c --- a/mercurial/cext/osutil.c +++ b/mercurial/cext/osutil.c @@ -121,6 +121,27 @@ o->ob_type->tp_free(o); } +static PyObject *listdir_stat_getitem(PyObject *self, PyObject *key) +{ + long index = PyLong_AsLong(key); + if (index == -1 && PyErr_Occurred()) { + return NULL; + } + if (index != 8) { + PyErr_Format(PyExc_IndexError, "osutil.stat objects only " + "support stat.ST_MTIME in " + "__getitem__"); + return NULL; + } + return listdir_stat_st_mtime(self, NULL); +} + +static PyMappingMethods listdir_stat_type_mapping_methods = { + (lenfunc)NULL, /* mp_length */ + (binaryfunc)listdir_stat_getitem, /* mp_subscript */ + (objobjargproc)NULL,/* mp_ass_subscript */ +}; + static PyTypeObject listdir_stat_type = { PyVarObject_HEAD_INIT(NULL, 0) /* header */ "osutil.stat", /*tp_name*/ @@ -134,7 +155,7 @@ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ + &listdir_stat_type_mapping_methods, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ @@ -1352,7 +1373,7 @@ {NULL, NULL} }; -static const int version = 3; +static const int version = 4; #ifdef IS_PY3K static struct PyModuleDef osutil_module = { To: durin42, #hg-reviewers, indygreg Cc: mharbison72, indygreg, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2695: osutil: implement minimal __getitem__ compatibility on our custom listdir type
durin42 updated this revision to Diff 6675. REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D2695?vs=6655&id=6675 REVISION DETAIL https://phab.mercurial-scm.org/D2695 AFFECTED FILES mercurial/cext/osutil.c mercurial/policy.py CHANGE DETAILS diff --git a/mercurial/policy.py b/mercurial/policy.py --- a/mercurial/policy.py +++ b/mercurial/policy.py @@ -69,7 +69,7 @@ (r'cext', r'bdiff'): 3, (r'cext', r'diffhelpers'): 1, (r'cext', r'mpatch'): 1, -(r'cext', r'osutil'): 3, +(r'cext', r'osutil'): 4, (r'cext', r'parsers'): 4, } diff --git a/mercurial/cext/osutil.c b/mercurial/cext/osutil.c --- a/mercurial/cext/osutil.c +++ b/mercurial/cext/osutil.c @@ -121,6 +121,27 @@ o->ob_type->tp_free(o); } +static PyObject *listdir_stat_getitem(PyObject *self, PyObject *key) +{ + long index = PyInt_AsLong(key); + if (index == -1 && PyErr_Occurred()) { + return NULL; + } + if (index != 8) { + PyErr_Format(PyExc_IndexError, "osutil.stat objects only " + "support stat.ST_MTIME in " + "__getitem__"); + return NULL; + } + return listdir_stat_st_mtime(self, NULL); +} + +static PyMappingMethods listdir_stat_type_mapping_methods = { + (lenfunc)NULL, /* mp_length */ + (binaryfunc)listdir_stat_getitem, /* mp_subscript */ + (objobjargproc)NULL,/* mp_ass_subscript */ +}; + static PyTypeObject listdir_stat_type = { PyVarObject_HEAD_INIT(NULL, 0) /* header */ "osutil.stat", /*tp_name*/ @@ -134,7 +155,7 @@ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ + &listdir_stat_type_mapping_methods, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ @@ -1352,7 +1373,7 @@ {NULL, NULL} }; -static const int version = 3; +static const int version = 4; #ifdef IS_PY3K static struct PyModuleDef osutil_module = { To: durin42, #hg-reviewers, indygreg Cc: mharbison72, indygreg, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2695: osutil: implement minimal __getitem__ compatibility on our custom listdir type
mharbison72 added inline comments. INLINE COMMENTS > osutil.c:130 > + if (index != 8) { > + PyErr_Format(PyExc_TypeError, "osutil.stat objects only suport" > + " stat.ST_MTIME in __getitem__"); s/suport/support/ REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2695 To: durin42, #hg-reviewers, indygreg Cc: mharbison72, indygreg, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2695: osutil: implement minimal __getitem__ compatibility on our custom listdir type
indygreg requested changes to this revision. indygreg added inline comments. This revision now requires changes to proceed. INLINE COMMENTS > osutil.c:130 > + if (index != 8) { > + PyErr_Format(PyExc_TypeError, "osutil.stat objects only suport" > + " stat.ST_MTIME in __getitem__"); I think this should be `PyExc_IndexError`. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2695 To: durin42, #hg-reviewers, indygreg Cc: indygreg, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D2695: osutil: implement minimal __getitem__ compatibility on our custom listdir type
durin42 created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REVISION SUMMARY We previously declined to do this, but the removal of the deprecated os.stat_float_times() method in Python 3.7 forces our hand. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2695 AFFECTED FILES mercurial/cext/osutil.c mercurial/policy.py CHANGE DETAILS diff --git a/mercurial/policy.py b/mercurial/policy.py --- a/mercurial/policy.py +++ b/mercurial/policy.py @@ -69,7 +69,7 @@ (r'cext', r'bdiff'): 3, (r'cext', r'diffhelpers'): 1, (r'cext', r'mpatch'): 1, -(r'cext', r'osutil'): 3, +(r'cext', r'osutil'): 4, (r'cext', r'parsers'): 4, } diff --git a/mercurial/cext/osutil.c b/mercurial/cext/osutil.c --- a/mercurial/cext/osutil.c +++ b/mercurial/cext/osutil.c @@ -121,6 +121,25 @@ o->ob_type->tp_free(o); } +static PyObject *listdir_stat_getitem(PyObject *self, PyObject *key) { + long index = PyInt_AsLong(key); + if (index == -1 && PyErr_Occurred()) { + return NULL; + } + if (index != 8) { + PyErr_Format(PyExc_TypeError, "osutil.stat objects only suport" +" stat.ST_MTIME in __getitem__"); + return NULL; + } + return listdir_stat_st_mtime(self, NULL); +} + +static PyMappingMethods listdir_stat_type_mapping_methods = { + (lenfunc)NULL, /* mp_length */ + (binaryfunc)listdir_stat_getitem, /* mp_subscript */ + (objobjargproc)NULL,/* mp_ass_subscript */ +}; + static PyTypeObject listdir_stat_type = { PyVarObject_HEAD_INIT(NULL, 0) /* header */ "osutil.stat", /*tp_name*/ @@ -134,7 +153,7 @@ 0, /*tp_repr*/ 0, /*tp_as_number*/ 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ + &listdir_stat_type_mapping_methods, /*tp_as_mapping*/ 0, /*tp_hash */ 0, /*tp_call*/ 0, /*tp_str*/ @@ -1352,7 +1371,7 @@ {NULL, NULL} }; -static const int version = 3; +static const int version = 4; #ifdef IS_PY3K static struct PyModuleDef osutil_module = { To: durin42, #hg-reviewers Cc: mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel