summaryrefslogtreecommitdiff
path: root/unpack-trees.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2019-11-21 22:04:43 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-11-22 07:11:44 (GMT)
commiteb42feca974a333e58c2ca0f3cfa8bf0dd421402 (patch)
tree5e9e8425ec5a8f1b9cffd3fb9226d3457a31f927 /unpack-trees.c
parentaf09ce24a9c79f6efc12d1d8f1052e1d1dbe5016 (diff)
downloadgit-eb42feca974a333e58c2ca0f3cfa8bf0dd421402.zip
git-eb42feca974a333e58c2ca0f3cfa8bf0dd421402.tar.gz
git-eb42feca974a333e58c2ca0f3cfa8bf0dd421402.tar.bz2
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>
Diffstat (limited to 'unpack-trees.c')
-rw-r--r--unpack-trees.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/unpack-trees.c b/unpack-trees.c
index a90d718..c0dca20 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1283,15 +1283,17 @@ static int clear_ce_flags_dir(struct index_state *istate,
struct cache_entry **cache_end;
int dtype = DT_DIR;
int rc;
- enum pattern_match_result ret;
- ret = path_matches_pattern_list(prefix->buf, prefix->len,
- basename, &dtype, pl, istate);
+ enum pattern_match_result ret, orig_ret;
+ orig_ret = path_matches_pattern_list(prefix->buf, prefix->len,
+ basename, &dtype, pl, istate);
strbuf_addch(prefix, '/');
/* If undecided, use matching result of parent dir in defval */
- if (ret == UNDECIDED)
+ if (orig_ret == UNDECIDED)
ret = default_match;
+ else
+ ret = orig_ret;
for (cache_end = cache; cache_end != cache + nr; cache_end++) {
struct cache_entry *ce = *cache_end;
@@ -1299,17 +1301,23 @@ static int clear_ce_flags_dir(struct index_state *istate,
break;
}
- /*
- * TODO: check pl, if there are no patterns that may conflict
- * 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 path_matches_pattern_list() on every entry.
- */
- rc = clear_ce_flags_1(istate, cache, cache_end - cache,
- prefix,
- select_mask, clear_mask,
- pl, ret);
+ if (pl->use_cone_patterns && orig_ret == MATCHED_RECURSIVE) {
+ struct cache_entry **ce = cache;
+ rc = (cache_end - cache) / sizeof(struct cache_entry *);
+
+ while (ce < cache_end) {
+ (*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,
+ prefix,
+ select_mask, clear_mask,
+ pl, ret);
+ }
+
strbuf_setlen(prefix, prefix->len - 1);
return rc;
}