t0008: avoid SIGPIPE race condition on fifo
[gitweb.git] / unpack-trees.c
index ad40109432971b8b26f107a84b02aeb405e8daf9..de8da4626d400cf09605ac399127cd2327c661d3 100644 (file)
@@ -836,7 +836,8 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
 {
        struct cache_entry **cache_end;
        int dtype = DT_DIR;
-       int ret = excluded_from_list(prefix, prefix_len, basename, &dtype, el);
+       int ret = is_excluded_from_list(prefix, prefix_len,
+                                       basename, &dtype, el);
 
        prefix[prefix_len++] = '/';
 
@@ -855,7 +856,7 @@ static int clear_ce_flags_dir(struct cache_entry **cache, int nr,
         * with ret (iow, we know in advance the incl/excl
         * decision for the entire directory), clear flag here without
         * calling clear_ce_flags_1(). That function will call
-        * the expensive excluded_from_list() on every entry.
+        * the expensive is_excluded_from_list() on every entry.
         */
        return clear_ce_flags_1(cache, cache_end - cache,
                                prefix, prefix_len,
@@ -938,7 +939,8 @@ static int clear_ce_flags_1(struct cache_entry **cache, int nr,
 
                /* Non-directory */
                dtype = ce_to_dtype(ce);
-               ret = excluded_from_list(ce->name, ce_namelen(ce), name, &dtype, el);
+               ret = is_excluded_from_list(ce->name, ce_namelen(ce),
+                                           name, &dtype, el);
                if (ret < 0)
                        ret = defval;
                if (ret > 0)
@@ -1017,12 +1019,16 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
        if (!core_apply_sparse_checkout || !o->update)
                o->skip_sparse_checkout = 1;
        if (!o->skip_sparse_checkout) {
-               if (add_excludes_from_file_to_list(git_path("info/sparse-checkout"), "", 0, NULL, &el, 0) < 0)
+               if (add_excludes_from_file_to_list(git_path("info/sparse-checkout"), "", 0, &el, 0) < 0)
                        o->skip_sparse_checkout = 1;
                else
                        o->el = &el;
        }
 
+       if (o->dir) {
+               o->path_exclude_check = xmalloc(sizeof(struct path_exclude_check));
+               path_exclude_check_init(o->path_exclude_check, o->dir);
+       }
        memset(&o->result, 0, sizeof(o->result));
        o->result.initialized = 1;
        o->result.timestamp.sec = o->src_index->timestamp.sec;
@@ -1147,7 +1153,11 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
                *o->dst_index = o->result;
 
 done:
-       free_excludes(&el);
+       clear_exclude_list(&el);
+       if (o->path_exclude_check) {
+               path_exclude_check_clear(o->path_exclude_check);
+               free(o->path_exclude_check);
+       }
        return ret;
 
 return_failed:
@@ -1363,7 +1373,8 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
        if (ignore_case && icase_exists(o, name, len, st))
                return 0;
 
-       if (o->dir && excluded(o->dir, name, &dtype))
+       if (o->dir &&
+           is_path_excluded(o->path_exclude_check, name, -1, &dtype))
                /*
                 * ce->name is explicitly excluded, so it is Ok to
                 * overwrite it.