added GG_GIT_ALL behavior

This commit is contained in:
Luxferre
2026-08-21 13:56:57 +03:00
parent 86082d67c0
commit f7d9a69952
2 changed files with 382 additions and 17 deletions
+23 -5
View File
@@ -26,13 +26,17 @@ It is intentionally narrow:
skipped. A literal match that occurs *before* the first NUL in an
otherwise-text file is still reported.
- **Recursive by default.** Given a directory it walks the whole tree.
- **Git-aware by default.** When walking a tree, `gg` honours every `.gitignore`
it encounters and always skips `.git` directories — just like `git` and `rg`.
Set `GG_GIT_ALL=1` to search everything instead (equivalent to `rg
--no-ignore`).
- **Self-contained.** No third-party libraries, no shelling out to other
programs. Just `libc` + `libpthread`.
`gg` was built to be a clean, readable reference implementation that is also
fast: on a 16 GB / ~209 000-file tree it completes the equivalent of
`rg --no-ignore --hidden -l` in roughly **0.4 s**, about **1.5× faster than
`rg`** on the same machine and query, using only portable POSIX interfaces.
`rg`** on the same machine and query, using only portable POSIX interfaces. (With `GG_GIT_ALL` unset, the equivalent is `rg --hidden -l`.)
## Installation
@@ -113,8 +117,10 @@ gg "def main" src/main.py
- **Symlinks are not followed.** Symbolic links to files or directories are
skipped, which prevents infinite loops on symlink cycles.
- **Hidden files and directories are searched.** Unlike `rg`'s default, `gg`
does not consult `.gitignore` or skip hidden paths.
- **Hidden files and directories are searched.** `gg` does not skip hidden
paths. It *does* consult `.gitignore` files and skips `.git` directories by
default; set `GG_GIT_ALL=1` to disable that and search everything (including
ignored and `.git` paths).
- **Binary files are skipped.** A file containing a NUL byte is never reported,
even if it also contains the search term (except when the match occurs before
the first NUL, in which case it is reported — see FAQ).
@@ -214,8 +220,20 @@ against symlink cycles and avoids double-counting.
### Does it respect `.gitignore`?
No. `gg` searches everything it can read, including hidden files and directories.
This is why its results match `rg --no-ignore --hidden`.
Yes, by default. `gg` reads every `.gitignore` found while walking and skips
matching files and directories, and it always skips `.git` directories — the
same rules `git` itself uses (including `!` negation, `**` globs, and
trailing-`/` directory-only patterns). Hidden files and directories are still
searched; only `.gitignore`-matched paths and `.git` are excluded.
To search everything — ignored files, `.git`, the lot — set the `GG_GIT_ALL`
environment variable (to any value) before running `gg`:
```sh
GG_GIT_ALL=1 gg "needle" .
```
With `GG_GIT_ALL` set, `gg`'s results match `rg --no-ignore --hidden`.
### Why not `mmap` the files?