comparison mercurial/osutil.c @ 18027:4ca434500dbf

osutil: tab damage, how i hate thee
author Bryan O'Sullivan <bryano@fb.com>
date Mon, 03 Dec 2012 13:17:01 -0800
parents ddc0323db78b
children bc851e2851b1
comparison
equal deleted inserted replaced
18026:ddc0323db78b 18027:4ca434500dbf
389 return ret; 389 return ret;
390 } 390 }
391 391
392 static PyObject *statfiles(PyObject *self, PyObject *args) 392 static PyObject *statfiles(PyObject *self, PyObject *args)
393 { 393 {
394 PyObject *names, *stats; 394 PyObject *names, *stats;
395 Py_ssize_t i, count; 395 Py_ssize_t i, count;
396 396
397 if (!PyArg_ParseTuple(args, "O:statfiles", &names)) 397 if (!PyArg_ParseTuple(args, "O:statfiles", &names))
398 return NULL; 398 return NULL;
399 399
400 count = PySequence_Length(names); 400 count = PySequence_Length(names);
401 if (count == -1) { 401 if (count == -1) {
402 PyErr_SetString(PyExc_TypeError, "not a sequence"); 402 PyErr_SetString(PyExc_TypeError, "not a sequence");
403 return NULL; 403 return NULL;
404 } 404 }
405 405
406 stats = PyList_New(count); 406 stats = PyList_New(count);
407 if (stats == NULL) 407 if (stats == NULL)
408 return NULL; 408 return NULL;
409 409
410 for (i = 0; i < count; i++) { 410 for (i = 0; i < count; i++) {
411 PyObject *stat; 411 PyObject *stat;
412 struct stat st; 412 struct stat st;
413 int ret, kind; 413 int ret, kind;
414 char *path; 414 char *path;
415 415
416 path = PyString_AsString(PySequence_GetItem(names, i)); 416 path = PyString_AsString(PySequence_GetItem(names, i));
417 if (path == NULL) { 417 if (path == NULL) {
418 PyErr_SetString(PyExc_TypeError, "not a string"); 418 PyErr_SetString(PyExc_TypeError, "not a string");
419 goto bail; 419 goto bail;
420 } 420 }
421 ret = lstat(path, &st); 421 ret = lstat(path, &st);
422 kind = st.st_mode & S_IFMT; 422 kind = st.st_mode & S_IFMT;
423 if (ret != -1 && (kind == S_IFREG || kind == S_IFLNK)) { 423 if (ret != -1 && (kind == S_IFREG || kind == S_IFLNK)) {
424 stat = makestat(&st); 424 stat = makestat(&st);
425 if (stat == NULL) 425 if (stat == NULL)
426 goto bail; 426 goto bail;
427 PyList_SET_ITEM(stats, i, stat); 427 PyList_SET_ITEM(stats, i, stat);
428 } else { 428 } else {
429 Py_INCREF(Py_None); 429 Py_INCREF(Py_None);
430 PyList_SET_ITEM(stats, i, Py_None); 430 PyList_SET_ITEM(stats, i, Py_None);
431 } 431 }
432 } 432 }
433 433
434 return stats; 434 return stats;
435 435
436 bail: 436 bail:
437 Py_DECREF(stats); 437 Py_DECREF(stats);
438 return NULL; 438 return NULL;
439 } 439 }
440 440
441 #endif /* ndef _WIN32 */ 441 #endif /* ndef _WIN32 */
442 442
443 static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs) 443 static PyObject *listdir(PyObject *self, PyObject *args, PyObject *kwargs)