* Loads the per-directory exclude list for the substring of base * which has a char length of baselen. */
| 1647 | * which has a char length of baselen. |
| 1648 | */ |
| 1649 | static void prep_exclude(struct dir_struct *dir, |
| 1650 | struct index_state *istate, |
| 1651 | const char *base, int baselen) |
| 1652 | { |
| 1653 | struct exclude_list_group *group; |
| 1654 | struct pattern_list *pl; |
| 1655 | struct exclude_stack *stk = NULL; |
| 1656 | struct untracked_cache_dir *untracked; |
| 1657 | int current; |
| 1658 | |
| 1659 | group = &dir->internal.exclude_list_group[EXC_DIRS]; |
| 1660 | |
| 1661 | /* |
| 1662 | * Pop the exclude lists from the EXCL_DIRS exclude_list_group |
| 1663 | * which originate from directories not in the prefix of the |
| 1664 | * path being checked. |
| 1665 | */ |
| 1666 | while ((stk = dir->internal.exclude_stack) != NULL) { |
| 1667 | if (stk->baselen <= baselen && |
| 1668 | !strncmp(dir->internal.basebuf.buf, base, stk->baselen)) |
| 1669 | break; |
| 1670 | pl = &group->pl[dir->internal.exclude_stack->exclude_ix]; |
| 1671 | dir->internal.exclude_stack = stk->prev; |
| 1672 | dir->internal.pattern = NULL; |
| 1673 | free((char *)pl->src); /* see strbuf_detach() below */ |
| 1674 | clear_pattern_list(pl); |
| 1675 | free(stk); |
| 1676 | group->nr--; |
| 1677 | } |
| 1678 | |
| 1679 | /* Skip traversing into sub directories if the parent is excluded */ |
| 1680 | if (dir->internal.pattern) |
| 1681 | return; |
| 1682 | |
| 1683 | /* |
| 1684 | * Lazy initialization. All call sites currently just |
| 1685 | * memset(dir, 0, sizeof(*dir)) before use. Changing all of |
| 1686 | * them seems lots of work for little benefit. |
| 1687 | */ |
| 1688 | if (!dir->internal.basebuf.buf) |
| 1689 | strbuf_init(&dir->internal.basebuf, PATH_MAX); |
| 1690 | |
| 1691 | /* Read from the parent directories and push them down. */ |
| 1692 | current = stk ? stk->baselen : -1; |
| 1693 | strbuf_setlen(&dir->internal.basebuf, current < 0 ? 0 : current); |
| 1694 | if (dir->untracked) |
| 1695 | untracked = stk ? stk->ucd : dir->untracked->root; |
| 1696 | else |
| 1697 | untracked = NULL; |
| 1698 | |
| 1699 | while (current < baselen) { |
| 1700 | const char *cp; |
| 1701 | struct oid_stat oid_stat; |
| 1702 | |
| 1703 | CALLOC_ARRAY(stk, 1); |
| 1704 | if (current < 0) { |
| 1705 | cp = base; |
| 1706 | current = 0; |
no test coverage detected