dir: add {new,add}_untracked_cache()

Factor out code into new_untracked_cache() and add_untracked_cache(), which will be used in later commits. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Jan 24, 2016 at 16:28 UTC 4a4ca4796df6b81d5995f31e87e9e6a64c2b889d
3 files changed +20 -10
builtin/update-index.c
+1 -10
@@ -1123,16 +1123,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1123 if (untracked_cache == UC_TEST)
1124 return 0;
1125 }
1126 - if (!the_index.untracked) {
1127 - struct untracked_cache *uc = xcalloc(1, sizeof(*uc));
1128 - strbuf_init(&uc->ident, 100);
1129 - uc->exclude_per_dir = ".gitignore";
1130 - /* should be the same flags used by git-status */
1131 - uc->dir_flags = DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
1132 - the_index.untracked = uc;
1133 - }
1134 - add_untracked_ident(the_index.untracked);
1135 - the_index.cache_changed |= UNTRACKED_CHANGED;
1126 + add_untracked_cache(&the_index);
1127 report(_("Untracked cache enabled for '%s'"), get_git_work_tree());
1128 } else if (untracked_cache == UC_DISABLE) {
1129 if (the_index.untracked) {
dir.c
+18
@@ -1938,6 +1938,24 @@ void add_untracked_ident(struct untracked_cache *uc)
1938 strbuf_addch(&uc->ident, 0);
1939 }
1940
1941 +static void new_untracked_cache(struct index_state *istate)
1942 +{
1943 + struct untracked_cache *uc = xcalloc(1, sizeof(*uc));
1944 + strbuf_init(&uc->ident, 100);
1945 + uc->exclude_per_dir = ".gitignore";
1946 + /* should be the same flags used by git-status */
1947 + uc->dir_flags = DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
1948 + istate->untracked = uc;
1949 +}
1950 +
1951 +void add_untracked_cache(struct index_state *istate)
1952 +{
1953 + if (!istate->untracked) {
1954 + new_untracked_cache(istate);
1955 + add_untracked_ident(istate->untracked);
1956 + istate->cache_changed |= UNTRACKED_CHANGED;
1957 +}
1958 +
1959 static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir,
1960 int base_len,
1961 const struct pathspec *pathspec)
dir.h
+1
@@ -308,4 +308,5 @@ void free_untracked_cache(struct untracked_cache *);
308 struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz);
309 void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
310 void add_untracked_ident(struct untracked_cache *);
311 +void add_untracked_cache(struct index_state *istate);
312 #endif