diff options
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 44 |
1 files changed, 31 insertions, 13 deletions
@@ -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)); } @@ -1033,9 +1040,9 @@ static int add_patterns_from_buffer(char *buf, size_t size, * an index if 'istate' is non-null), parse it and store the * exclude rules in "pl". * - * If "ss" is not NULL, compute SHA-1 of the exclude file and fill + * If "oid_stat" is not NULL, compute oid of the exclude file and fill * stat data from disk (only valid if add_patterns returns zero). If - * ss_valid is non-zero, "ss" must contain good value as input. + * oid_stat.valid is non-zero, "oid_stat" must contain good value as input. */ static int add_patterns(const char *fname, const char *base, int baselen, struct pattern_list *pl, struct index_state *istate, @@ -1083,7 +1090,7 @@ static int add_patterns(const char *fname, const char *base, int baselen, int pos; if (oid_stat->valid && !match_stat_data_racy(istate, &oid_stat->stat, &st)) - ; /* no content change, ss->sha1 still good */ + ; /* no content change, oid_stat->oid still good */ else if (istate && (pos = index_name_pos(istate, fname, strlen(fname))) >= 0 && !ce_stage(istate->cache[pos]) && @@ -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 { |