osutil: simplify DT_REG support
authorMatt Mackall <mpm@selenic.com>
Mon, 08 Oct 2007 18:47:17 -0500
changeset 5426 e760cb72c02e
parent 5425 830f6e280c90
child 5427 dae6188e8c9e
osutil: simplify DT_REG support
mercurial/osutil.c
--- a/mercurial/osutil.c	Mon Oct 08 18:47:16 2007 -0500
+++ b/mercurial/osutil.c	Mon Oct 08 18:47:17 2007 -0500
@@ -206,37 +206,29 @@
 		PyObject *name = NULL;
 		PyObject *py_kind = NULL;
 		PyObject *val = NULL;
-		unsigned char d_type;
 		int kind = -1;
 
 		if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
 			continue;
 
 #ifdef DT_REG
-		if (do_stat)
-			d_type = 0;
-		else
-			d_type = ent->d_type;
+		if (!do_stat)
+			switch (ent->d_type) {
+			case DT_REG: kind = S_IFREG; break;
+			case DT_DIR: kind = S_IFDIR; break;
+			case DT_LNK: kind = S_IFLNK; break;
+			case DT_BLK: kind = S_IFBLK; break;
+			case DT_CHR: kind = S_IFCHR; break;
+			case DT_FIFO: kind = S_IFIFO; break;
+			case DT_SOCK: kind = S_IFSOCK; break;
+			default:
+				all_kinds = 0;
+				break;
+			}
 #else
-		d_type = 0;
+		all_kinds = 0;
 #endif
 
-		switch (d_type) {
-#ifdef DT_REG
-		case DT_REG: kind = S_IFREG; break;
-		case DT_DIR: kind = S_IFDIR; break;
-		case DT_LNK: kind = S_IFLNK; break;
-		case DT_BLK: kind = S_IFBLK; break;
-		case DT_CHR: kind = S_IFCHR; break;
-		case DT_FIFO: kind = S_IFIFO; break;
-		case DT_SOCK: kind = S_IFSOCK; break;
-#endif
-		default:
-			if (all_kinds)
-				all_kinds = 0;
-			break;
-		}
-
 		name = PyString_FromString(ent->d_name);
 		if (kind != -1)
 			py_kind = PyInt_FromLong(kind);