Skip to content

Commit 4a4ca47

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e7c0c53 commit 4a4ca47

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

builtin/update-index.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,16 +1123,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
11231123
if (untracked_cache == UC_TEST)
11241124
return 0;
11251125
}
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);
11361127
report(_("Untracked cache enabled for '%s'"), get_git_work_tree());
11371128
} else if (untracked_cache == UC_DISABLE) {
11381129
if (the_index.untracked) {

dir.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,24 @@ void add_untracked_ident(struct untracked_cache *uc)
19381938
strbuf_addch(&uc->ident, 0);
19391939
}
19401940

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+
19411959
static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir,
19421960
int base_len,
19431961
const struct pathspec *pathspec)

dir.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,5 @@ void free_untracked_cache(struct untracked_cache *);
308308
struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz);
309309
void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked);
310310
void add_untracked_ident(struct untracked_cache *);
311+
void add_untracked_cache(struct index_state *istate);
311312
#endif

0 commit comments

Comments
 (0)