summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorAdam Spiers <git@adamspiers.org>2013-01-06 16:58:05 +0000
committerJunio C Hamano <gitster@pobox.com>2013-01-06 14:26:37 -0800
commit270be8160493eb25ee43eb7db8dda2504343dc65 (patch)
tree93d5642a17e8d182a1c9a22c02c62e3219416ae0 /dir.c
parentc04318e46aae79b8b8df059e2118519d83dfee12 (diff)
downloadgit-270be8160493eb25ee43eb7db8dda2504343dc65.tar.gz
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>
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/dir.c b/dir.c
index d3f462bd15..46f362ed69 100644
--- a/dir.c
+++ b/dir.c
@@ -1557,3 +1557,33 @@ void free_pathspec(struct pathspec *pathspec)
free(pathspec->items);
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;
+ }
+}