attr.c: drop hashmap_cmp_fn cast
[gitweb.git] / dir.c
diff --git a/dir.c b/dir.c
index f673b86f31eb841ce0ecc34f49ab9ece2dd4d128..332f9d8095faf0ec4549cab41811167aecea31d3 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -9,6 +9,7 @@
  */
 #define NO_THE_INDEX_COMPATIBILITY_MACROS
 #include "cache.h"
+#include "config.h"
 #include "dir.h"
 #include "attr.h"
 #include "refs.h"
@@ -52,6 +53,15 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
 static int get_dtype(struct dirent *de, struct index_state *istate,
                     const char *path, int len);
 
+int count_slashes(const char *s)
+{
+       int cnt = 0;
+       while (*s)
+               if (*s++ == '/')
+                       cnt++;
+       return cnt;
+}
+
 int fspathcmp(const char *a, const char *b)
 {
        return ignore_case ? strcasecmp(a, b) : strcmp(a, b);
@@ -752,9 +762,9 @@ static int add_excludes(const char *fname, const char *base, int baselen,
 
        fd = open(fname, O_RDONLY);
        if (fd < 0 || fstat(fd, &st) < 0) {
-               if (errno != ENOENT)
-                       warn_on_inaccessible(fname);
-               if (0 <= fd)
+               if (fd < 0)
+                       warn_on_fopen_errors(fname);
+               else
                        close(fd);
                if (!istate ||
                    (buf = read_skip_worktree_file_from_index(istate, fname, &size, sha1_stat)) == NULL)
@@ -2117,8 +2127,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
                for (i = j = 0; j < dir->nr; j++) {
                        if (i &&
                            check_dir_entry_contains(dir->entries[i - 1], dir->entries[j])) {
-                               free(dir->entries[j]);
-                               dir->entries[j] = NULL;
+                               FREE_AND_NULL(dir->entries[j]);
                        } else {
                                dir->entries[i++] = dir->entries[j];
                        }
@@ -2144,8 +2153,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
                     dir->untracked->dir_invalidated))
                        istate->cache_changed |= UNTRACKED_CHANGED;
                if (dir->untracked != istate->untracked) {
-                       free(dir->untracked);
-                       dir->untracked = NULL;
+                       FREE_AND_NULL(dir->untracked);
                }
        }
        return dir->nr;
@@ -2337,7 +2345,7 @@ int remove_path(const char *name)
 {
        char *slash;
 
-       if (unlink(name) && errno != ENOENT && errno != ENOTDIR)
+       if (unlink(name) && !is_missing_file_error(errno))
                return -1;
 
        slash = strrchr(name, '/');
@@ -2488,8 +2496,7 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
        strbuf_addbuf(out, &untracked->ident);
 
        strbuf_add(out, ouc, ouc_size(len));
-       free(ouc);
-       ouc = NULL;
+       FREE_AND_NULL(ouc);
 
        if (!untracked->root) {
                varint_len = encode_varint(0, varbuf);