@matheusbsbs / matheus-bagliano / commits / fa0bde45cd
Fork 0

unpack-trees: simplify pattern_list freeing

commit e091228e17 ("sparse-checkout: update working directory in-process", 2019-11-21) allowed passing a pre-defined set of patterns to unpack_trees(). However, if o->pl was NULL, it would still read the existing patterns and use those. If those patterns were read into a data structure that was allocated, naturally they needed to be free'd. However, despite the same function being responsible for knowing about both the allocation and the free'ing, the logic for tracking whether to free the pattern_list was hoisted to an outer function with an additional flag in unpack_trees_options. Put the logic back in the relevant function and discard the now unnecessary flag. Reviewed-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Mar 27, 2020 at 00:48 UTC fa0bde45cdebee8bac95e66e4bf5ba16c77fbdba
3 files changed +5 -5
builtin/sparse-checkout.c
-1
@@ -122,7 +122,6 @@ static int update_working_directory(struct pattern_list *pl)
122 o.dst_index = r->index;
123 o.skip_sparse_checkout = 0;
124 o.pl = pl;
125 - o.keep_pattern_list = !!pl;
125
126 resolve_undo_clear_index(r->index);
127 setup_work_tree();
unpack-trees.c
+4 -2
@@ -1503,6 +1503,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1503 int i, ret;
1504 static struct cache_entry *dfc;
1505 struct pattern_list pl;
1506 + int free_pattern_list = 0;
1507
1508 if (len > MAX_UNPACK_TREES)
1509 die("unpack_trees takes at most %d trees", MAX_UNPACK_TREES);
@@ -1519,6 +1520,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1520 else
1521 o->pl = &pl;
1522 free(sparse);
1523 + free_pattern_list = 1;
1524 }
1525
1526 memset(&o->result, 0, sizeof(o->result));
@@ -1686,9 +1688,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
1688 o->src_index = NULL;
1689
1690 done:
1689 - trace_performance_leave("unpack_trees");
1690 - if (!o->keep_pattern_list)
1691 + if (free_pattern_list)
1692 clear_pattern_list(&pl);
1693 + trace_performance_leave("unpack_trees");
1694 return ret;
1695
1696 return_failed:
unpack-trees.h
+1 -2
@@ -58,8 +58,7 @@ struct unpack_trees_options {
58 quiet,
59 exiting_early,
60 show_all_errors,
61 - dry_run,
62 - keep_pattern_list;
61 + dry_run;
62 const char *prefix;
63 int cache_bottom;
64 struct dir_struct *dir;