| 1711 | } |
| 1712 | |
| 1713 | static cbm_discover_status_t discover_impl(const char *repo_path, const cbm_discover_opts_t *opts, |
| 1714 | cbm_file_info_t **out, int *count, char ***excluded_out, |
| 1715 | int *excluded_count_out, |
| 1716 | cbm_ignored_file_t **ignored_out, int *ignored_count_out, |
| 1717 | int *ignored_total_out, bool count_only, int max_files, |
| 1718 | uint64_t deadline_ms) { |
| 1719 | if (excluded_out) { |
| 1720 | *excluded_out = NULL; |
| 1721 | } |
| 1722 | if (excluded_count_out) { |
| 1723 | *excluded_count_out = 0; |
| 1724 | } |
| 1725 | if (ignored_out) { |
| 1726 | *ignored_out = NULL; |
| 1727 | } |
| 1728 | if (ignored_count_out) { |
| 1729 | *ignored_count_out = 0; |
| 1730 | } |
| 1731 | if (ignored_total_out) { |
| 1732 | *ignored_total_out = 0; |
| 1733 | } |
| 1734 | if (opts && opts->resource_violation) { |
| 1735 | *opts->resource_violation = (cbm_index_resource_violation_t){0}; |
| 1736 | } |
| 1737 | if (!repo_path || !out || !count || (count_only && max_files < 0)) { |
| 1738 | return CBM_DISCOVER_ERROR; |
| 1739 | } |
| 1740 | |
| 1741 | *out = NULL; |
| 1742 | *count = 0; |
| 1743 | |
| 1744 | /* Verify directory exists */ |
| 1745 | struct stat st; |
| 1746 | if (wide_stat(repo_path, &st) != 0 || !S_ISDIR(st.st_mode)) { |
| 1747 | return CBM_DISCOVER_ERROR; |
| 1748 | } |
| 1749 | |
| 1750 | /* Load gitignore sources for ordinary repos AND linked worktrees. |
| 1751 | * Sources merged in order (later patterns win on conflict): |
| 1752 | * 1. <repo>/.gitignore — committed exclusions |
| 1753 | * 2. <common>/info/exclude — per-clone exclusions, not committed |
| 1754 | * <common> is the git common dir, resolved via resolve_git_common_dir() so a |
| 1755 | * worktree (where .git is a gitlink file) reads the shared info/exclude/config |
| 1756 | * just like a normal checkout. Both are folded into a single matcher so all |
| 1757 | * downstream call paths remain unchanged. Fixes issue #489: OOM on repos whose |
| 1758 | * worktrees are excluded only via .git/info/exclude (e.g. Sandcastle). |
| 1759 | * |
| 1760 | * An ENCLOSING repository's ignore files (indexing a git-less subfolder, |
| 1761 | * issue #510) are deliberately NOT folded in here: their patterns are |
| 1762 | * anchored to their own directories, so they stay separate matchers on the |
| 1763 | * chain with a `base` offset. See ancestor_ignores_build(). */ |
| 1764 | cbm_gitignore_t *gitignore = NULL; |
| 1765 | char gi_path[CBM_SZ_4K]; |
| 1766 | struct stat gi_stat; |
| 1767 | /* Resolve the git common dir, transparently following a worktree gitlink so the |
| 1768 | * .git/info/exclude and core.excludesfile sources are honoured inside linked |
| 1769 | * worktrees too (where .git is a file pointing at the shared dir, not a directory). */ |
| 1770 | char git_common_dir[CBM_SZ_4K]; |
no test coverage detected