| 55 | } |
| 56 | |
| 57 | static int check_recursion_depth(const struct strbuf *name, |
| 58 | const struct pathspec *ps, |
| 59 | int max_depth) |
| 60 | { |
| 61 | int i; |
| 62 | |
| 63 | if (!ps->nr) |
| 64 | return within_depth(name->buf, name->len, 1, max_depth); |
| 65 | |
| 66 | /* |
| 67 | * We look through the pathspecs in reverse-sorted order, because we |
| 68 | * want to find the longest match first (e.g., "a/b" is better for |
| 69 | * checking depth than "a/b/c"). |
| 70 | */ |
| 71 | for (i = ps->nr - 1; i >= 0; i--) { |
| 72 | const struct pathspec_item *item = ps->items+i; |
| 73 | |
| 74 | /* |
| 75 | * If the name to match is longer than the pathspec, then we |
| 76 | * are only interested if the pathspec matches and we are |
| 77 | * within the allowed depth. |
| 78 | */ |
| 79 | if (name->len >= item->len) { |
| 80 | if (!is_dir_prefix(name->buf, item->match, item->len)) |
| 81 | continue; |
| 82 | return within_depth(name->buf + item->len, |
| 83 | name->len - item->len, |
| 84 | 1, max_depth); |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Otherwise, our name is shorter than the pathspec. We need to |
| 89 | * check if it is a prefix of the pathspec; if so, we must |
| 90 | * always recurse in order to process further (the resulting |
| 91 | * paths we find might or might not match our pathspec, but we |
| 92 | * cannot know until we recurse). |
| 93 | */ |
| 94 | if (is_dir_prefix(item->match, name->buf, name->len)) |
| 95 | return 1; |
| 96 | } |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static int should_recurse(const struct strbuf *name, struct diff_options *opt) |
| 101 | { |
no test coverage detected