dir: add remove_untracked_cache()
[gitweb.git] / dir.c
diff --git a/dir.c b/dir.c
index d2a8f06b0243bda92c04f57d96c0b18838ee7dce..0d069c90546e9508c6226f6c4c018b09d1e2c229 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -1938,6 +1938,33 @@ void add_untracked_ident(struct untracked_cache *uc)
        strbuf_addch(&uc->ident, 0);
 }
 
+static void new_untracked_cache(struct index_state *istate)
+{
+       struct untracked_cache *uc = xcalloc(1, sizeof(*uc));
+       strbuf_init(&uc->ident, 100);
+       uc->exclude_per_dir = ".gitignore";
+       /* should be the same flags used by git-status */
+       uc->dir_flags = DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
+       istate->untracked = uc;
+}
+
+void add_untracked_cache(struct index_state *istate)
+{
+       if (!istate->untracked) {
+               new_untracked_cache(istate);
+       add_untracked_ident(istate->untracked);
+       istate->cache_changed |= UNTRACKED_CHANGED;
+}
+
+void remove_untracked_cache(struct index_state *istate)
+{
+       if (istate->untracked) {
+               free_untracked_cache(istate->untracked);
+               istate->untracked = NULL;
+               istate->cache_changed |= UNTRACKED_CHANGED;
+       }
+}
+
 static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir,
                                                      int base_len,
                                                      const struct pathspec *pathspec)