/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/_readdir_pyx.pyx

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
#
 
17
# cython: language_level=3
16
18
 
17
19
"""Wrapper for readdir which returns files ordered by inode."""
18
20
 
20
22
import os
21
23
import sys
22
24
 
23
 
#python2.4 support
24
25
cdef extern from "python-compat.h":
25
26
    pass
26
27
 
79
80
 
80
81
cdef extern from 'Python.h':
81
82
    int PyErr_CheckSignals() except -1
82
 
    char * PyString_AS_STRING(object)
83
 
    ctypedef int Py_ssize_t # Required for older pyrex versions
 
83
    char * PyBytes_AS_STRING(object)
84
84
    ctypedef struct PyObject:
85
85
        pass
86
 
    Py_ssize_t PyString_Size(object s)
 
86
    Py_ssize_t PyBytes_Size(object s)
87
87
    object PyList_GetItem(object lst, Py_ssize_t index)
88
88
    void *PyList_GetItem_object_void "PyList_GET_ITEM" (object lst, int index)
89
89
    int PyList_Append(object lst, object item) except -1
92
92
    int PyTuple_SetItem_obj "PyTuple_SetItem" (void *, Py_ssize_t pos, PyObject * item) except -1
93
93
    void Py_INCREF(object o)
94
94
    void Py_DECREF(object o)
95
 
    void PyString_Concat(PyObject **string, object newpart)
 
95
    void PyBytes_Concat(PyObject **string, object newpart)
96
96
 
97
97
 
98
98
cdef extern from 'dirent.h':
166
166
                     self.st_mtime, self.st_ctime))
167
167
 
168
168
 
169
 
from bzrlib import osutils
 
169
from . import osutils
170
170
 
171
171
cdef object _safe_utf8
172
172
_safe_utf8 = osutils.safe_utf8
220
220
        cdef object name
221
221
        cdef PyObject * new_val_obj
222
222
 
223
 
        if PyString_Size(prefix):
224
 
            relprefix = prefix + '/'
 
223
        if PyBytes_Size(prefix):
 
224
            relprefix = prefix + b'/'
225
225
        else:
226
 
            relprefix = ''
227
 
        top_slash = top + '/'
 
226
            relprefix = b''
 
227
        top_slash = top + b'/'
228
228
 
229
229
        # read_dir supplies in should-stat order.
230
230
        # for _, name in sorted(_listdir(top)):
240
240
            # direct concat - faster than operator +.
241
241
            new_val_obj = <PyObject *>relprefix
242
242
            Py_INCREF(relprefix)
243
 
            PyString_Concat(&new_val_obj, name)
 
243
            PyBytes_Concat(&new_val_obj, name)
244
244
            if NULL == new_val_obj:
245
 
                # PyString_Concat will have setup an exception, but how to get
 
245
                # PyBytes_Concat will have setup an exception, but how to get
246
246
                # at it?
247
247
                raise Exception("failed to strcat")
248
248
            PyTuple_SetItem_obj(atuple, 0, new_val_obj)
256
256
            # direct concat - faster than operator +.
257
257
            new_val_obj = <PyObject *>top_slash
258
258
            Py_INCREF(top_slash)
259
 
            PyString_Concat(&new_val_obj, name)
 
259
            PyBytes_Concat(&new_val_obj, name)
260
260
            if NULL == new_val_obj:
261
 
                # PyString_Concat will have setup an exception, but how to get
 
261
                # PyBytes_Concat will have setup an exception, but how to get
262
262
                # at it?
263
263
                raise Exception("failed to strcat")
264
264
            PyTuple_SetItem_obj(atuple, 4, new_val_obj)
292
292
 
293
293
    # Avoid chdir('') because it causes problems on Sun OS, and avoid this if
294
294
    # staying in .
295
 
    if path != "" and path != '.':
 
295
    if path != b"" and path != b'.':
296
296
        # we change into the requested directory before reading, and back at the
297
297
        # end, because that turns out to make the stat calls measurably faster than
298
298
        # passing full paths every time.
308
308
        orig_dir_fd = -1
309
309
 
310
310
    try:
311
 
        the_dir = opendir(".")
 
311
        the_dir = opendir(b".")
312
312
        if NULL == the_dir:
313
313
            raise_os_error(errno, "opendir: ", path)
314
314
        try:
346
346
                    if stat_result != 0:
347
347
                        if errno != ENOENT:
348
348
                            raise_os_error(errno, "lstat: ",
349
 
                                path + "/" + entry.d_name)
 
349
                                path + b"/" + entry.d_name)
350
350
                        else:
351
351
                            # the file seems to have disappeared after being
352
352
                            # seen by readdir - perhaps a transient temporary