dir.[ch]: replace dir_init() with DIR_INIT
Remove the dir_init() function and replace it with a DIR_INIT macro. In many cases in the codebase we need to initialize things with a function for good reasons, e.g. needing to call another function on initialization. The "dir_init()" function was not one such case, and could trivially be replaced with a more idiomatic macro initialization pattern. The only place where we made use of its use of memset() was in dir_clear() itself, which resets the contents of an an existing struct pointer. Let's use the new "memcpy() a 'blank' struct on the stack" idiom to do that reset. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5726a6b401
commit
ce93a4c612
9
dir.c
9
dir.c
@ -53,12 +53,6 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
|
||||
int check_only, int stop_at_first_file, const struct pathspec *pathspec);
|
||||
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));
|
||||
}
|
||||
|
||||
struct dirent *readdir_skip_dot_and_dotdot(DIR *dirp)
|
||||
{
|
||||
struct dirent *e;
|
||||
@ -3105,6 +3099,7 @@ void dir_clear(struct dir_struct *dir)
|
||||
struct exclude_list_group *group;
|
||||
struct pattern_list *pl;
|
||||
struct exclude_stack *stk;
|
||||
struct dir_struct new = DIR_INIT;
|
||||
|
||||
for (i = EXC_CMDL; i <= EXC_FILE; i++) {
|
||||
group = &dir->exclude_list_group[i];
|
||||
@ -3132,7 +3127,7 @@ void dir_clear(struct dir_struct *dir)
|
||||
}
|
||||
strbuf_release(&dir->basebuf);
|
||||
|
||||
dir_init(dir);
|
||||
memcpy(dir, &new, sizeof(*dir));
|
||||
}
|
||||
|
||||
struct ondisk_untracked_cache {
|
||||
|
Reference in New Issue
Block a user