diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-10-30 01:43:16 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-10-30 01:43:16 +0300 |
commit | 68fb83b58ed4ef8705974bc1cc47fb6bb7ca5bdd (patch) | |
tree | 6ab3b8297c6ec5bc92f9d54f81333cebf3cd658e /dir.c | |
parent | 7b3fd03e6acbc990b4dd540079368d4e85cc7f1b (diff) | |
parent | 20141e322c8c27054c105fca5c812043c2bc7440 (diff) |
Merge branch 'mt/fix-add-rm-with-sparse-index'
Fix-up to a topic already merged to 'master'.
* mt/fix-add-rm-with-sparse-index:
add, rm, mv: fix bug that prevents the update of non-sparse dirs
Diffstat (limited to 'dir.c')
-rw-r--r-- | dir.c | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -1504,8 +1504,9 @@ static int path_in_sparse_checkout_1(const char *path, struct index_state *istate, int require_cone_mode) { - const char *base; int dtype = DT_REG; + enum pattern_match_result match = UNDECIDED; + const char *end, *slash; /* * We default to accepting a path if there are no patterns or @@ -1516,11 +1517,27 @@ static int path_in_sparse_checkout_1(const char *path, !istate->sparse_checkout_patterns->use_cone_patterns)) return 1; - base = strrchr(path, '/'); - return path_matches_pattern_list(path, strlen(path), base ? base + 1 : path, - &dtype, - istate->sparse_checkout_patterns, - istate) > 0; + /* + * If UNDECIDED, use the match from the parent dir (recursively), or + * fall back to NOT_MATCHED at the topmost level. Note that cone mode + * never returns UNDECIDED, so we will execute only one iteration in + * this case. + */ + for (end = path + strlen(path); + end > path && match == UNDECIDED; + end = slash) { + + for (slash = end - 1; slash > path && *slash != '/'; slash--) + ; /* do nothing */ + + match = path_matches_pattern_list(path, end - path, + slash > path ? slash + 1 : path, &dtype, + istate->sparse_checkout_patterns, istate); + + /* We are going to match the parent dir now */ + dtype = DT_DIR; + } + return match > 0; } int path_in_sparse_checkout(const char *path, |