]> git.ipfire.org Git - thirdparty/git.git/blobdiff - dir.c
Merge branch 'nk/dir-c-comment-update'
[thirdparty/git.git] / dir.c
diff --git a/dir.c b/dir.c
index 42078609824cb6b3843f74bef38154e61980035a..ebea5f1f91439a097e48ffb5983fbff2bc0ff918 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -54,6 +54,11 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
 static int resolve_dtype(int dtype, struct index_state *istate,
                         const char *path, int len);
 
+void dir_init(struct dir_struct *dir)
+{
+       memset(dir, 0, sizeof(*dir));
+}
+
 int count_slashes(const char *s)
 {
        int cnt = 0;
@@ -916,6 +921,8 @@ void clear_pattern_list(struct pattern_list *pl)
                free(pl->patterns[i]);
        free(pl->patterns);
        free(pl->filebuf);
+       hashmap_free_entries(&pl->recursive_hashmap, struct pattern_entry, ent);
+       hashmap_free_entries(&pl->parent_hashmap, struct pattern_entry, ent);
 
        memset(pl, 0, sizeof(*pl));
 }
@@ -1792,9 +1799,12 @@ static enum path_treatment treat_directory(struct dir_struct *dir,
                nested_repo = is_nonbare_repository_dir(&sb);
                strbuf_release(&sb);
        }
-       if (nested_repo)
-               return ((dir->flags & DIR_SKIP_NESTED_GIT) ? path_none :
-                       (excluded ? path_excluded : path_untracked));
+       if (nested_repo) {
+               if ((dir->flags & DIR_SKIP_NESTED_GIT) ||
+                   (matches_how == MATCHED_RECURSIVELY_LEADING_PATHSPEC))
+                       return path_none;
+               return excluded ? path_excluded : path_untracked;
+       }
 
        if (!(dir->flags & DIR_SHOW_OTHER_DIRECTORIES)) {
                if (excluded &&
@@ -2095,7 +2105,6 @@ static int resolve_dtype(int dtype, struct index_state *istate,
 }
 
 static enum path_treatment treat_path_fast(struct dir_struct *dir,
-                                          struct untracked_cache_dir *untracked,
                                           struct cached_dir *cdir,
                                           struct index_state *istate,
                                           struct strbuf *path,
@@ -2143,7 +2152,7 @@ static enum path_treatment treat_path(struct dir_struct *dir,
        int has_path_in_index, dtype, excluded;
 
        if (!cdir->d_name)
-               return treat_path_fast(dir, untracked, cdir, istate, path,
+               return treat_path_fast(dir, cdir, istate, path,
                                       baselen, pathspec);
        if (is_dot_or_dotdot(cdir->d_name) || !fspathcmp(cdir->d_name, ".git"))
                return path_none;
@@ -2209,13 +2218,13 @@ static enum path_treatment treat_path(struct dir_struct *dir,
                                       baselen, excluded, pathspec);
        case DT_REG:
        case DT_LNK:
-               if (excluded)
-                       return path_excluded;
                if (pathspec &&
                    !match_pathspec(istate, pathspec, path->buf, path->len,
                                    0 /* prefix */, NULL /* seen */,
                                    0 /* is_dir */))
                        return path_none;
+               if (excluded)
+                       return path_excluded;
                return path_untracked;
        }
 }
@@ -3009,10 +3018,10 @@ int remove_path(const char *name)
 }
 
 /*
- * Frees memory within dir which was allocated for exclude lists and
- * the exclude_stack.  Does not free dir itself.
+ * Frees memory within dir which was allocated, and resets fields for further
+ * use.  Does not free dir itself.
  */
-void clear_directory(struct dir_struct *dir)
+void dir_clear(struct dir_struct *dir)
 {
        int i, j;
        struct exclude_list_group *group;
@@ -3030,6 +3039,13 @@ void clear_directory(struct dir_struct *dir)
                free(group->pl);
        }
 
+       for (i = 0; i < dir->ignored_nr; i++)
+               free(dir->ignored[i]);
+       for (i = 0; i < dir->nr; i++)
+               free(dir->entries[i]);
+       free(dir->ignored);
+       free(dir->entries);
+
        stk = dir->exclude_stack;
        while (stk) {
                struct exclude_stack *prev = stk->prev;
@@ -3037,6 +3053,8 @@ void clear_directory(struct dir_struct *dir)
                stk = prev;
        }
        strbuf_release(&dir->basebuf);
+
+       dir_init(dir);
 }
 
 struct ondisk_untracked_cache {