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
!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,