dir.c: provide clear_directory() for reclaiming dir_struct memory
By the end of a directory traversal, a dir_struct instance will typically contains pointers to various data structures on the heap. clear_directory() provides a convenient way to reclaim that memory. Signed-off-by: Adam Spiers <git@adamspiers.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
c04318e46a
commit
270be81604
@ -81,4 +81,6 @@ marked. If you to exclude files, make sure you have loaded index first.
|
|||||||
|
|
||||||
* Use `dir.entries[]`.
|
* Use `dir.entries[]`.
|
||||||
|
|
||||||
|
* Call `free_directory()` when none of the contained elements are no longer in use.
|
||||||
|
|
||||||
(JC)
|
(JC)
|
||||||
|
30
dir.c
30
dir.c
@ -1557,3 +1557,33 @@ void free_pathspec(struct pathspec *pathspec)
|
|||||||
free(pathspec->items);
|
free(pathspec->items);
|
||||||
pathspec->items = NULL;
|
pathspec->items = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Frees memory within dir which was allocated for exclude lists and
|
||||||
|
* the exclude_stack. Does not free dir itself.
|
||||||
|
*/
|
||||||
|
void clear_directory(struct dir_struct *dir)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
struct exclude_list_group *group;
|
||||||
|
struct exclude_list *el;
|
||||||
|
struct exclude_stack *stk;
|
||||||
|
|
||||||
|
for (i = EXC_CMDL; i <= EXC_FILE; i++) {
|
||||||
|
group = &dir->exclude_list_group[i];
|
||||||
|
for (j = 0; j < group->nr; j++) {
|
||||||
|
el = &group->el[j];
|
||||||
|
if (i == EXC_DIRS)
|
||||||
|
free((char *)el->src);
|
||||||
|
clear_exclude_list(el);
|
||||||
|
}
|
||||||
|
free(group->el);
|
||||||
|
}
|
||||||
|
|
||||||
|
stk = dir->exclude_stack;
|
||||||
|
while (stk) {
|
||||||
|
struct exclude_stack *prev = stk->prev;
|
||||||
|
free(stk);
|
||||||
|
stk = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1
dir.h
1
dir.h
@ -169,6 +169,7 @@ extern void parse_exclude_pattern(const char **string, int *patternlen, int *fla
|
|||||||
extern void add_exclude(const char *string, const char *base,
|
extern void add_exclude(const char *string, const char *base,
|
||||||
int baselen, struct exclude_list *el, int srcpos);
|
int baselen, struct exclude_list *el, int srcpos);
|
||||||
extern void clear_exclude_list(struct exclude_list *el);
|
extern void clear_exclude_list(struct exclude_list *el);
|
||||||
|
extern void clear_directory(struct dir_struct *dir);
|
||||||
extern int file_exists(const char *);
|
extern int file_exists(const char *);
|
||||||
|
|
||||||
extern int is_inside_dir(const char *dir);
|
extern int is_inside_dir(const char *dir);
|
||||||
|
Loading…
Reference in New Issue
Block a user