Skip to content

fix(discover): honor .git/info/exclude during file discovery#493

Open
ShauryaaSharma wants to merge 2 commits into
DeusData:mainfrom
ShauryaaSharma:main
Open

fix(discover): honor .git/info/exclude during file discovery#493
ShauryaaSharma wants to merge 2 commits into
DeusData:mainfrom
ShauryaaSharma:main

Conversation

@ShauryaaSharma

Copy link
Copy Markdown

Fixes #489

Problem

index_repository honored .gitignore but silently ignored .git/info/exclude — the per-clone exclude file that Git itself treats as authoritative. Any paths excluded only via info/exclude (e.g. Sandcastle worktrees) were walked in full.

In the reported case this caused the indexer to traverse 661,430 files / 170 GB of worktree content and OOM.

Solution

Added cbm_gitignore_merge() to append patterns from one matcher into another. In cbm_discover_ex, after loading .gitignore, the code now also loads .git/info/exclude and merges its patterns in. If only the exclude file exists (no .gitignore), it is used directly. No downstream call paths change.

Changes

  • src/discover/discover.h — declare cbm_gitignore_merge
  • src/discover/gitignore.c — implement cbm_gitignore_merge
  • src/discover/discover.c — load and merge .git/info/exclude in cbm_discover_ex
  • tests/test_gitignore.c — 3 unit tests for cbm_gitignore_merge
  • tests/test_discover.c — 2 integration tests reproducing the issue scenario

Testing

Added discover_git_info_exclude and discover_git_info_exclude_stacks_with_gitignore to the discover suite, covering the exact reproduction case from the issue report.

index_repository only loaded .gitignore when building the exclusion
matcher. .git/info/exclude — the per-clone exclude file that Git treats
as authoritative — was never read, so paths excluded only there were
walked in full. On repos with Sandcastle worktrees this caused the
indexer to traverse 661K files / 170 GB and OOM (issue DeusData#489).

Add cbm_gitignore_merge() to append patterns from one matcher into
another. In cbm_discover_ex, after loading .gitignore, also load
.git/info/exclude and merge its patterns in. If only the exclude file
exists, use it directly. No downstream call paths change.

Add three unit tests for cbm_gitignore_merge and two integration tests
that reproduce the issue scenario (exclude-only and exclude-stacked-
with-gitignore).

Signed-off-by: ShauryaaSharma <shauryasofficial27@gmail.com>
Signed-off-by: ShauryaaSharma <shauryasofficial27@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

index_repository ignores .git/info/exclude (only .gitignore honored) → indexes excluded worktrees → OOM

1 participant