Entropic 2.14.3
Local-first agentic inference engine
Loading...
Searching...
No Matches
ignore_matcher.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
37#pragma once
38
39#include <atomic>
40#include <cstdint>
41#include <filesystem>
42#include <regex>
43#include <string>
44#include <unordered_map>
45#include <vector>
46
47namespace entropic {
48
69public:
74 IgnoreMatcher() = default;
75
98 void load(const std::filesystem::path& root);
99
108 void add_pattern(const std::string& pattern,
109 const std::filesystem::path& base = {});
110
121 bool is_ignored(const std::string& rel_path,
122 bool is_dir) const;
123
130 std::size_t rule_count() const { return rules_.size(); }
131
147 std::uint64_t regex_evals() const {
148 return regex_evals_.load(std::memory_order_relaxed);
149 }
150
156 void reset_regex_evals() const {
157 regex_evals_.store(0, std::memory_order_relaxed);
158 }
159
174 static bool is_skipped_dir_name(const std::string& name);
175
190 struct Rule {
191 std::regex re_exact;
192 std::regex re_under;
193 bool negate = false;
194 bool dir_only = false;
195 std::string original;
196 std::string base;
197 };
198
199private:
200
209 static Rule compile_pattern(const std::string& pattern,
210 const std::string& base);
211
223 static std::string pattern_to_regex(const std::string& pattern);
224
232 void load_file(const std::filesystem::path& path,
233 const std::string& base);
234
248 void load_nested_gitignores(const std::filesystem::path& canonical_root,
249 const std::filesystem::path& root_gi);
250
263 void visit_discovery_entry(
264 std::filesystem::recursive_directory_iterator& it,
265 const std::filesystem::path& canonical_root,
266 const std::filesystem::path& root_gi);
267
278 bool prunes_discovery(
279 const std::filesystem::path& dir,
280 const std::filesystem::path& canonical_root) const;
281
292 void push_rule(Rule&& rule);
293
294 std::vector<Rule> rules_;
295
301 std::unordered_map<std::string, std::vector<std::size_t>> by_base_;
302
304 mutable std::atomic<std::uint64_t> regex_evals_{0};
305};
306
307} // namespace entropic
gitignore-style path matcher (#15, v2.1.4).
static bool is_skipped_dir_name(const std::string &name)
Directory names never walked, by name alone (gh#161).
void load(const std::filesystem::path &root)
Load gitignore + explorerignore from a workspace root.
void add_pattern(const std::string &pattern, const std::filesystem::path &base={})
Add a single pattern programmatically (test surface).
std::uint64_t regex_evals() const
Regex evaluations performed since the last reset (gh#161).
bool is_ignored(const std::string &rel_path, bool is_dir) const
Test whether a path is ignored.
IgnoreMatcher()=default
Construct an empty matcher (no rules).
void reset_regex_evals() const
Reset the regex-evaluation counter (gh#161, test surface).
std::size_t rule_count() const
Number of compiled rules (test surface).
Activate model on GPU (WARM → ACTIVE).
@ optional
optional: every escape asks the host's path approver
One compiled gitignore rule (public so internal helpers in the .cpp can construct Rules without frien...
std::regex re_under
Path is strictly below target.
std::string base
Anchor base, "" means root.
bool dir_only
Trailing / (directory match)
std::string original
Raw pattern for diagnostics.
std::regex re_exact
Path equals pattern target.