Almost 1.8.4.2 ;-)
[gitweb.git] / dir.c
diff --git a/dir.c b/dir.c
index 2f82cd193e5753ac7ecb7cdda66e8e587aaa1b7f..1d63e9898783e3d26dc8b4a23fc785810142d9a1 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -820,6 +820,9 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
                                dir->basebuf, stk->baselen - 1,
                                dir->basebuf + current, &dt);
                        dir->basebuf[stk->baselen - 1] = '/';
+                       if (dir->exclude &&
+                           dir->exclude->flags & EXC_FLAG_NEGATIVE)
+                               dir->exclude = NULL;
                        if (dir->exclude) {
                                dir->basebuf[stk->baselen] = 0;
                                dir->exclude_stack = stk;
@@ -929,7 +932,7 @@ enum exist_status {
  */
 static enum exist_status directory_exists_in_index_icase(const char *dirname, int len)
 {
-       struct cache_entry *ce = cache_name_exists(dirname, len + 1, ignore_case);
+       const struct cache_entry *ce = cache_name_exists(dirname, len + 1, ignore_case);
        unsigned char endchar;
 
        if (!ce)
@@ -973,7 +976,7 @@ static enum exist_status directory_exists_in_index(const char *dirname, int len)
        if (pos < 0)
                pos = -pos-1;
        while (pos < active_nr) {
-               struct cache_entry *ce = active_cache[pos++];
+               const struct cache_entry *ce = active_cache[pos++];
                unsigned char endchar;
 
                if (strncmp(ce->name, dirname, len))
@@ -1032,9 +1035,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
                return path_recurse;
 
        case index_gitdir:
-               if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
-                       return path_none;
-               return path_untracked;
+               return path_none;
 
        case index_nonexistent:
                if (dir->flags & DIR_SHOW_OTHER_DIRECTORIES)
@@ -1111,7 +1112,7 @@ static int exclude_matches_pathspec(const char *path, int len,
 static int get_index_dtype(const char *path, int len)
 {
        int pos;
-       struct cache_entry *ce;
+       const struct cache_entry *ce;
 
        ce = cache_name_exists(path, len, 0);
        if (ce) {
@@ -1173,14 +1174,51 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
                                          int dtype, struct dirent *de)
 {
        int exclude;
+       int has_path_in_index = !!cache_name_exists(path->buf, path->len, ignore_case);
+
        if (dtype == DT_UNKNOWN)
                dtype = get_dtype(de, path->buf, path->len);
 
        /* Always exclude indexed files */
-       if (dtype != DT_DIR &&
-           cache_name_exists(path->buf, path->len, ignore_case))
+       if (dtype != DT_DIR && has_path_in_index)
                return path_none;
 
+       /*
+        * When we are looking at a directory P in the working tree,
+        * there are three cases:
+        *
+        * (1) P exists in the index.  Everything inside the directory P in
+        * the working tree needs to go when P is checked out from the
+        * index.
+        *
+        * (2) P does not exist in the index, but there is P/Q in the index.
+        * We know P will stay a directory when we check out the contents
+        * of the index, but we do not know yet if there is a directory
+        * P/Q in the working tree to be killed, so we need to recurse.
+        *
+        * (3) P does not exist in the index, and there is no P/Q in the index
+        * to require P to be a directory, either.  Only in this case, we
+        * know that everything inside P will not be killed without
+        * recursing.
+        */
+       if ((dir->flags & DIR_COLLECT_KILLED_ONLY) &&
+           (dtype == DT_DIR) &&
+           !has_path_in_index) {
+               /*
+                * NEEDSWORK: directory_exists_in_index_icase()
+                * assumes that one byte past the given path is
+                * readable and has '/', which needs to be fixed, but
+                * until then, work it around in the caller.
+                */
+               strbuf_addch(path, '/');
+               if (directory_exists_in_index(path->buf, path->len - 1) ==
+                   index_nonexistent) {
+                       strbuf_setlen(path, path->len - 1);
+                       return path_none;
+               }
+               strbuf_setlen(path, path->len - 1);
+       }
+
        exclude = is_excluded(dir, path->buf, &dtype);
 
        /*
@@ -1541,9 +1579,9 @@ void setup_standard_excludes(struct dir_struct *dir)
                home_config_paths(NULL, &xdg_path, "ignore");
                excludes_file = xdg_path;
        }
-       if (!access_or_warn(path, R_OK))
+       if (!access_or_warn(path, R_OK, 0))
                add_excludes_from_file(dir, path);
-       if (excludes_file && !access_or_warn(excludes_file, R_OK))
+       if (excludes_file && !access_or_warn(excludes_file, R_OK, 0))
                add_excludes_from_file(dir, excludes_file);
 }