Minimal, pure-Clojure .gitignore matcher — the JGit-free replacement for
IgnoreNode. Parses ONE .gitignore file (the one at a walk root) into
ordered rules and evaluates a /-separated relative path against them with
git's semantics: last matching rule wins, ! negates, a trailing /
restricts to directories, a leading/embedded / anchors to the root, and a
slash-free pattern matches at any depth.
Minimal, pure-Clojure `.gitignore` matcher — the JGit-free replacement for `IgnoreNode`. Parses ONE `.gitignore` file (the one at a walk root) into ordered rules and evaluates a `/`-separated relative path against them with git's semantics: last matching rule wins, `!` negates, a trailing `/` restricts to directories, a leading/embedded `/` anchors to the root, and a slash-free pattern matches at any depth.
(compile-rules patterns)Compile config-supplied patterns (the same .gitignore pattern vocabulary
compile-rule parses: dir/, **, ?, char classes, ! negation) into a
matcher for ignored?, or nil when nothing compiles. This is how the
:search config overlay reuses the battle-tested gitignore semantics for
its :include-gitignored-paths / :always-exclude lists instead of
inventing a second glob dialect.
Compile config-supplied `patterns` (the same `.gitignore` pattern vocabulary `compile-rule` parses: `dir/`, `**`, `?`, char classes, `!` negation) into a matcher for `ignored?`, or nil when nothing compiles. This is how the `:search` config overlay reuses the battle-tested gitignore semantics for its `:include-gitignored-paths` / `:always-exclude` lists instead of inventing a second glob dialect.
(ignored? matcher rel path-dir?)True when the /-separated relative path rel (with path-dir? telling
whether it is a directory) is ignored by matcher. Last matching rule wins;
a ! rule un-ignores. nil matcher → false.
An UNANCHORED (slash-free) pattern matches a name at ANY depth. Rather than
bake a (?:^|.*/) prefix into every rule's regex — which pairs with the
trailing .* to backtrack catastrophically (ReDoS) — we match each rule's
ANCHORED ^…$ regex against every /-aligned SUFFIX of rel (the whole
path, plus the tail after each /). Those suffix starts are exactly the
positions the .*/ prefix used to enumerate, so semantics are unchanged but
evaluation is linear in path length.
True when the `/`-separated relative path `rel` (with `path-dir?` telling whether it is a directory) is ignored by `matcher`. Last matching rule wins; a `!` rule un-ignores. nil matcher → false. An UNANCHORED (slash-free) pattern matches a name at ANY depth. Rather than bake a `(?:^|.*/)` prefix into every rule's regex — which pairs with the trailing `.*` to backtrack catastrophically (ReDoS) — we match each rule's ANCHORED `^…$` regex against every `/`-aligned SUFFIX of `rel` (the whole path, plus the tail after each `/`). Those suffix starts are exactly the positions the `.*/` prefix used to enumerate, so semantics are unchanged but evaluation is linear in path length.
(load-matcher root)Parse the ignore files at root into ONE ordered rule vector, or nil when none
exist. Layers .gitignore < .ignore < .rgignore (ripgrep precedence): rules
are concatenated in that order so the later file's rules win, and a ! negation
in a higher-precedence file un-ignores what a lower one ignored. Because git
never reads .ignore/.rgignore, a !corp/ there makes our tools descend into
corp/ while .gitignore keeps git ignoring it. The returned value is opaque;
pass it to ignored?.
Parse the ignore files at `root` into ONE ordered rule vector, or nil when none exist. Layers `.gitignore` < `.ignore` < `.rgignore` (ripgrep precedence): rules are concatenated in that order so the later file's rules win, and a `!` negation in a higher-precedence file un-ignores what a lower one ignored. Because git never reads `.ignore`/`.rgignore`, a `!corp/` there makes our tools descend into `corp/` while `.gitignore` keeps git ignoring it. The returned value is opaque; pass it to `ignored?`.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |