Skip to content

Commit eb42fec

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af09ce2 commit eb42fec

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ enum pattern_match_result path_matches_pattern_list(
12701270

12711271
if (hashmap_contains_path(&pl->recursive_hashmap,
12721272
&parent_pathname)) {
1273-
result = MATCHED;
1273+
result = MATCHED_RECURSIVE;
12741274
goto done;
12751275
}
12761276

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

12971297
done:
12981298
strbuf_release(&parent_pathname);

dir.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ enum pattern_match_result {
264264
UNDECIDED = -1,
265265
NOT_MATCHED = 0,
266266
MATCHED = 1,
267+
MATCHED_RECURSIVE = 2,
267268
};
268269

269270
/*

unpack-trees.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,33 +1283,41 @@ static int clear_ce_flags_dir(struct index_state *istate,
12831283
struct cache_entry **cache_end;
12841284
int dtype = DT_DIR;
12851285
int rc;
1286-
enum pattern_match_result ret;
1287-
ret = path_matches_pattern_list(prefix->buf, prefix->len,
1288-
basename, &dtype, pl, istate);
1286+
enum pattern_match_result ret, orig_ret;
1287+
orig_ret = path_matches_pattern_list(prefix->buf, prefix->len,
1288+
basename, &dtype, pl, istate);
12891289

12901290
strbuf_addch(prefix, '/');
12911291

12921292
/* If undecided, use matching result of parent dir in defval */
1293-
if (ret == UNDECIDED)
1293+
if (orig_ret == UNDECIDED)
12941294
ret = default_match;
1295+
else
1296+
ret = orig_ret;
12951297

12961298
for (cache_end = cache; cache_end != cache + nr; cache_end++) {
12971299
struct cache_entry *ce = *cache_end;
12981300
if (strncmp(ce->name, prefix->buf, prefix->len))
12991301
break;
13001302
}
13011303

1302-
/*
1303-
* TODO: check pl, if there are no patterns that may conflict
1304-
* with ret (iow, we know in advance the incl/excl
1305-
* decision for the entire directory), clear flag here without
1306-
* calling clear_ce_flags_1(). That function will call
1307-
* the expensive path_matches_pattern_list() on every entry.
1308-
*/
1309-
rc = clear_ce_flags_1(istate, cache, cache_end - cache,
1310-
prefix,
1311-
select_mask, clear_mask,
1312-
pl, ret);
1304+
if (pl->use_cone_patterns && orig_ret == MATCHED_RECURSIVE) {
1305+
struct cache_entry **ce = cache;
1306+
rc = (cache_end - cache) / sizeof(struct cache_entry *);
1307+
1308+
while (ce < cache_end) {
1309+
(*ce)->ce_flags &= ~clear_mask;
1310+
ce++;
1311+
}
1312+
} else if (pl->use_cone_patterns && orig_ret == NOT_MATCHED) {
1313+
rc = (cache_end - cache) / sizeof(struct cache_entry *);
1314+
} else {
1315+
rc = clear_ce_flags_1(istate, cache, cache_end - cache,
1316+
prefix,
1317+
select_mask, clear_mask,
1318+
pl, ret);
1319+
}
1320+
13131321
strbuf_setlen(prefix, prefix->len - 1);
13141322
return rc;
13151323
}

0 commit comments

Comments
 (0)