* Is a tree entry interesting given the pathspec we have? * * Pre-condition: either baselen == 0 (i.e. empty path) * or base[baselen-1] == '/' (i.e. with trailing slash). */
| 1221 | * or base[baselen-1] == '/' (i.e. with trailing slash). |
| 1222 | */ |
| 1223 | enum interesting tree_entry_interesting(struct index_state *istate, |
| 1224 | const struct name_entry *entry, |
| 1225 | struct strbuf *base, |
| 1226 | const struct pathspec *ps) |
| 1227 | { |
| 1228 | enum interesting positive, negative; |
| 1229 | positive = do_match(istate, entry, base, ps, 0); |
| 1230 | |
| 1231 | /* |
| 1232 | * case | entry | positive | negative | result |
| 1233 | * -----+-------+----------+----------+------- |
| 1234 | * 1 | file | -1 | -1..2 | -1 |
| 1235 | * 2 | file | 0 | -1..2 | 0 |
| 1236 | * 3 | file | 1 | -1 | 1 |
| 1237 | * 4 | file | 1 | 0 | 1 |
| 1238 | * 5 | file | 1 | 1 | 0 |
| 1239 | * 6 | file | 1 | 2 | 0 |
| 1240 | * 7 | file | 2 | -1 | 2 |
| 1241 | * 8 | file | 2 | 0 | 1 |
| 1242 | * 9 | file | 2 | 1 | 0 |
| 1243 | * 10 | file | 2 | 2 | -1 |
| 1244 | * -----+-------+----------+----------+------- |
| 1245 | * 11 | dir | -1 | -1..2 | -1 |
| 1246 | * 12 | dir | 0 | -1..2 | 0 |
| 1247 | * 13 | dir | 1 | -1 | 1 |
| 1248 | * 14 | dir | 1 | 0 | 1 |
| 1249 | * 15 | dir | 1 | 1 | 1 (*) |
| 1250 | * 16 | dir | 1 | 2 | 0 |
| 1251 | * 17 | dir | 2 | -1 | 2 |
| 1252 | * 18 | dir | 2 | 0 | 1 |
| 1253 | * 19 | dir | 2 | 1 | 1 (*) |
| 1254 | * 20 | dir | 2 | 2 | -1 |
| 1255 | * |
| 1256 | * (*) An exclude pattern interested in a directory does not |
| 1257 | * necessarily mean it will exclude all of the directory. In |
| 1258 | * wildcard case, it can't decide until looking at individual |
| 1259 | * files inside. So don't write such directories off yet. |
| 1260 | */ |
| 1261 | |
| 1262 | if (!(ps->magic & PATHSPEC_EXCLUDE) || |
| 1263 | positive <= entry_not_interesting) /* #1, #2, #11, #12 */ |
| 1264 | return positive; |
| 1265 | |
| 1266 | negative = do_match(istate, entry, base, ps, 1); |
| 1267 | |
| 1268 | /* #8, #18 */ |
| 1269 | if (positive == all_entries_interesting && |
| 1270 | negative == entry_not_interesting) |
| 1271 | return entry_interesting; |
| 1272 | |
| 1273 | /* #3, #4, #7, #13, #14, #17 */ |
| 1274 | if (negative <= entry_not_interesting) |
| 1275 | return positive; |
| 1276 | |
| 1277 | /* #15, #19 */ |
| 1278 | if (S_ISDIR(entry->mode) && |
| 1279 | positive >= entry_interesting && |
| 1280 | negative == entry_interesting) |
no test coverage detected