af search searches the files on main with a regular expression. The forge answers it from a trigram index it keeps of main, as Zoekt and Google’s code search do, so a search does not depend on your workspace: it finds files your workspace does not hold. It searches only the files you may read.
Find lines
Start a server and land some code:
$ af-server --dev
...$ source ~/af-dev/dev/env
$ af workspace add ~/demo
Workspace at /home/you/demo
Paths: **
main has no landing yet
$ cd ~/demo
$ af new -m "Add a small program"
Working on change omukmnmmoypqyylrxspyusnmkpymtzyp at commit 45e3a1f056aa3879dceae71d2d5d7ce3f3220d46380cdc4285974d9e8a213e82
$ mkdir -p src docs
$ printf 'fn main() {\n // TODO: greet by name\n println!("Hello");\n}\n' > src/main.rs
$ printf '# Notes\n\nTODO: write the guide\n' > docs/notes.md
$ af submit
Submitted commit 448a7eef3d902915a65af99742efb4487ee2ef4c0535a0c4dd17a7b289a12e20, 2 edits in its last snapshotOnce the landing is in the index, each matching line comes back as path:line:text:
$ af search TODO
docs/notes.md:3:TODO: write the guide
src/main.rs:2: // TODO: greet by nameNarrow it by file
-f keeps only files whose path matches a second expression:
$ af search TODO -f '\.rs$'
src/main.rs:2: // TODO: greet by nameWith only -f, af search lists the paths that match, which is a quick way to find files:
$ af search -f '\.md$'
docs/notes.mdThe pattern is Rust’s regular expression syntax, and ^ and $ match at the start and end of each line. Results stop at 20 files and 20 lines a file; -n and --lines change that. A search by path alone gives the first files in path order. A search of text that matches more files than the limit gives some of them, listed in path order, but which ones is not decided by path order. An expression that does not parse is refused, and so is af search with neither an expression nor -f.
What search covers
- Only
main. A change that is still open is not searched. The index takesmainin at most once a second, so a landing is searchable a moment after it lands, and a search straight after a landing can miss it. Search again. - Only files you may read. A folder you may not read gives no result, by text or by path.
- Only text. A file is searched only if it is valid UTF-8, has no line longer than 2,000 bytes and is at most a mebibyte. A file that is not text is not in the index at all, so
-fdoes not list it either. Search, caches and releases has the whole rule and says how the index is kept.
Next
af searchin the reference.- Explore history:
files()in a revset finds the commits that changed a path.