unpack-trees: hash less in cone mode

The sparse-checkout feature in "cone mode" can use the fact that
the recursive patterns are "connected" to the root via parent
patterns to decide if a directory is entirely contained in the
sparse-checkout or entirely removed.

In these cases, we can skip hashing the paths within those
directories and simply set the skipworktree bit to the correct
value.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Derrick Stolee 2019-11-21 22:04:43 +00:00 committed by Junio C Hamano
parent af09ce24a9
commit eb42feca97
3 changed files with 26 additions and 17 deletions

4
dir.c
View File

@ -1270,7 +1270,7 @@ enum pattern_match_result path_matches_pattern_list(


if (hashmap_contains_path(&pl->recursive_hashmap, if (hashmap_contains_path(&pl->recursive_hashmap,
&parent_pathname)) { &parent_pathname)) {
result = MATCHED; result = MATCHED_RECURSIVE;
goto done; goto done;
} }


@ -1292,7 +1292,7 @@ enum pattern_match_result path_matches_pattern_list(
if (hashmap_contains_parent(&pl->recursive_hashmap, if (hashmap_contains_parent(&pl->recursive_hashmap,
pathname, pathname,
&parent_pathname)) &parent_pathname))
result = MATCHED; result = MATCHED_RECURSIVE;


done: done:
strbuf_release(&parent_pathname); strbuf_release(&parent_pathname);

1
dir.h
View File

@ -264,6 +264,7 @@ enum pattern_match_result {
UNDECIDED = -1, UNDECIDED = -1,
NOT_MATCHED = 0, NOT_MATCHED = 0,
MATCHED = 1, MATCHED = 1,
MATCHED_RECURSIVE = 2,
}; };


/* /*

View File

@ -1283,15 +1283,17 @@ static int clear_ce_flags_dir(struct index_state *istate,
struct cache_entry **cache_end; struct cache_entry **cache_end;
int dtype = DT_DIR; int dtype = DT_DIR;
int rc; int rc;
enum pattern_match_result ret; enum pattern_match_result ret, orig_ret;
ret = path_matches_pattern_list(prefix->buf, prefix->len, orig_ret = path_matches_pattern_list(prefix->buf, prefix->len,
basename, &dtype, pl, istate); basename, &dtype, pl, istate);


strbuf_addch(prefix, '/'); strbuf_addch(prefix, '/');


/* If undecided, use matching result of parent dir in defval */ /* If undecided, use matching result of parent dir in defval */
if (ret == UNDECIDED) if (orig_ret == UNDECIDED)
ret = default_match; ret = default_match;
else
ret = orig_ret;


for (cache_end = cache; cache_end != cache + nr; cache_end++) { for (cache_end = cache; cache_end != cache + nr; cache_end++) {
struct cache_entry *ce = *cache_end; struct cache_entry *ce = *cache_end;
@ -1299,17 +1301,23 @@ static int clear_ce_flags_dir(struct index_state *istate,
break; break;
} }


/* if (pl->use_cone_patterns && orig_ret == MATCHED_RECURSIVE) {
* TODO: check pl, if there are no patterns that may conflict struct cache_entry **ce = cache;
* with ret (iow, we know in advance the incl/excl rc = (cache_end - cache) / sizeof(struct cache_entry *);
* decision for the entire directory), clear flag here without
* calling clear_ce_flags_1(). That function will call while (ce < cache_end) {
* the expensive path_matches_pattern_list() on every entry. (*ce)->ce_flags &= ~clear_mask;
*/ ce++;
}
} else if (pl->use_cone_patterns && orig_ret == NOT_MATCHED) {
rc = (cache_end - cache) / sizeof(struct cache_entry *);
} else {
rc = clear_ce_flags_1(istate, cache, cache_end - cache, rc = clear_ce_flags_1(istate, cache, cache_end - cache,
prefix, prefix,
select_mask, clear_mask, select_mask, clear_mask,
pl, ret); pl, ret);
}

strbuf_setlen(prefix, prefix->len - 1); strbuf_setlen(prefix, prefix->len - 1);
return rc; return rc;
} }