]> git.ipfire.org Git - thirdparty/git.git/commitdiff
unpack-trees: simplify pattern_list freeing
authorElijah Newren <newren@gmail.com>
Fri, 27 Mar 2020 00:48:47 +0000 (00:48 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Mar 2020 18:33:29 +0000 (11:33 -0700)
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>
builtin/sparse-checkout.c
unpack-trees.c
unpack-trees.h

index 740da4b6d54aa1864f8357ca84798a620af9f422..d102a9697fd39813168cb0d2798a891e503ad59f 100644 (file)
@@ -122,7 +122,6 @@ static int update_working_directory(struct pattern_list *pl)
        o.dst_index = r->index;
        o.skip_sparse_checkout = 0;
        o.pl = pl;
-       o.keep_pattern_list = !!pl;
 
        resolve_undo_clear_index(r->index);
        setup_work_tree();
index 3af2e126abf12f4b2d6b67320f9ab866b28a15be..d2863fa03107a0ef16c9d485f22793c449b81479 100644 (file)
@@ -1503,6 +1503,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
        int i, ret;
        static struct cache_entry *dfc;
        struct pattern_list pl;
+       int free_pattern_list = 0;
 
        if (len > MAX_UNPACK_TREES)
                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
                else
                        o->pl = &pl;
                free(sparse);
+               free_pattern_list = 1;
        }
 
        memset(&o->result, 0, sizeof(o->result));
@@ -1686,9 +1688,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
        o->src_index = NULL;
 
 done:
-       trace_performance_leave("unpack_trees");
-       if (!o->keep_pattern_list)
+       if (free_pattern_list)
                clear_pattern_list(&pl);
+       trace_performance_leave("unpack_trees");
        return ret;
 
 return_failed:
index 6d7c7b6c2e0041f3dc177b1f0c556bdd672333d8..d3516267f362baf4e409fbadfdae1e59566a14aa 100644 (file)
@@ -58,8 +58,7 @@ struct unpack_trees_options {
                     quiet,
                     exiting_early,
                     show_all_errors,
-                    dry_run,
-                    keep_pattern_list;
+                    dry_run;
        const char *prefix;
        int cache_bottom;
        struct dir_struct *dir;