~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_readdir_pyx.pyx

  • Committer: Robert Collins
  • Date: 2008-09-23 23:28:27 UTC
  • mto: (3696.4.15 process-entry-optimised)
  • mto: This revision was merged to the branch mainline in revision 3731.
  • Revision ID: robertc@robertcollins.net-20080923232827-vpd4xsif8x8op6i3
Review feedback.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
    void *malloc(int)
38
38
    void free(void *)
39
39
 
 
40
 
 
41
cdef extern from 'sys/types.h':
 
42
    ctypedef long ssize_t
 
43
    ctypedef unsigned long size_t
 
44
    ctypedef long time_t
 
45
    ctypedef unsigned long ino_t
 
46
    ctypedef unsigned long long off_t
 
47
 
 
48
 
40
49
cdef extern from 'sys/stat.h':
41
50
    cdef struct stat:
42
51
        int st_mode
43
 
        int st_size
 
52
        off_t st_size
44
53
        int st_dev
45
 
        int st_ino
 
54
        ino_t st_ino
46
55
        int st_mtime
47
56
        int st_ctime
48
57
    int lstat(char *path, stat *buf)
55
64
    int S_ISSOCK(int mode)
56
65
 
57
66
 
58
 
cdef extern from 'sys/types.h':
59
 
    ctypedef long ssize_t
60
 
    ctypedef unsigned long size_t
61
 
    ctypedef long time_t
62
 
    ctypedef unsigned long ino_t
63
 
 
64
 
 
65
67
cdef extern from 'Python.h':
66
68
    char * PyString_AS_STRING(object)
67
69
    ctypedef int Py_ssize_t # Required for older pyrex versions
168
170
        return self._kind_from_mode(mode)
169
171
 
170
172
    cdef _kind_from_mode(self, int mode):
171
 
        # in order of frequency:
 
173
        # Files and directories are the most common - check them first.
172
174
        if S_ISREG(mode):
173
175
            return self._file
174
176
        if S_ISDIR(mode):
224
226
        for index from 0 <= index < length:
225
227
            atuple = PyList_GetItem_object_void(result, index)
226
228
            name = <object>PyTuple_GetItem_void_void(atuple, 1)
227
 
            # We have inode, name, None, statvalue, None
 
229
            # We have a tuple with (inode, name, None, statvalue, None)
 
230
            # Now edit it:
228
231
            # inode -> path_from_top
229
232
            # direct concat - faster than operator +.
230
233
            new_val_obj = <PyObject *>relprefix
235
238
                # at it?
236
239
                raise Exception("failed to strcat")
237
240
            PyTuple_SetItem_obj(atuple, 0, new_val_obj)
238
 
            # None -> kind
 
241
            # 1st None -> kind
239
242
            newval = self._kind_from_mode(
240
243
                (<_Stat>PyTuple_GetItem_void_void(atuple, 3)).st_mode)
241
244
            Py_INCREF(newval)
242
245
            PyTuple_SetItem(atuple, 2, newval)
243
 
            # none -> abspath # perhaps only do if its a dir?
 
246
            # 2nd None -> abspath # for all - the caller may need to stat files
 
247
            # etc.
244
248
            # direct concat - faster than operator +.
245
249
            new_val_obj = <PyObject *>top_slash
246
250
            Py_INCREF(top_slash)
257
261
    """Like os.listdir, this reads the contents of a directory.
258
262
 
259
263
    :param path: the directory to list.
260
 
    :return: a list of (sort_key, basename) tuples.
 
264
    :return: a list of single-owner (the list) tuples ready for editing into
 
265
        the result tuples walkdirs needs to yield. They contain (inode, name,
 
266
        None, statvalue, None).
261
267
    """
262
268
    cdef DIR *the_dir
263
269
    # currently this needs a fixup - the C code says 'dirent' but should say