How ggreer/the_silver_searcher works
The Silver Searcher (ag) is a command-line code-search tool. A user supplies a query and paths; main parses options, then either searches standard input or traverses paths and dispatches file work to workers. Search results are formatted for standard output, with options for context, counts, colors, columns, and editor-friendly formats. The README also documents parallel search, ignore-file support, literal and PCRE matching, and mmap-based file access. Some subsystem links below are omitted or dashed because their call sites were not shown in the excerpts.
Main entry points: search.c Search workers · main.c Program entry · options.c Option parsing · ignore.c Ignore filtering
Components 15
CLI and options
- Program entry
src/main.c - Option parsing
src/options.c
File traversal
- Directory scanning
src/scandir.c - Ignore filtering
src/ignore.c
Search and matching
- Search workers
src/search.c - Decompression
src/decompress.c - Compressed files
src/zfile.c - Search utilities
src/util.c
Results and output
- Result formatting
src/print.c - Windows output
src/print_w32.c
Search support
- File types
src/lang.c - Hash utilities
src/uthash.h - Logging
src/log.c
Other components
- User
- Standard output
Connections 16
- User → Program entry: runs
README.md - Program entry → Option parsing: parses options
src/main.c - Program entry → Ignore filtering: initializes ignores
src/main.c - Program entry → Search workers: dispatches search
src/main.c - Program entry → Standard output: writes results
src/main.c - Option parsing → File types: loads file types
src/options.c - Option parsing → Ignore filtering: configures filters
src/options.c - Search workers → Directory scanning: uses scanner
src/search.c - Search workers → Result formatting: formats matches
src/search.c - Ignore filtering → Directory scanning: filters entries
src/ignore.c - Search workers → Decompression: may decompress
- Decompression → Compressed files: may read compressed data
- Search workers → Search utilities: uses match helpers
- Search workers → Hash utilities: uses symlink tracking
- Result formatting → Standard output: prints results
- Windows output → Standard output: prints results