MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / run

Method run

atomic-repository/src/content_search.rs:283–336  ·  view source on GitHub ↗
(
        self,
        mut retrieve: impl FnMut(&str) -> Result<Option<Vec<u8>>, E>,
    )

Source from the content-addressed store, hash-verified

281 }
282
283 pub(crate) fn run<E>(
284 self,
285 mut retrieve: impl FnMut(&str) -> Result<Option<Vec<u8>>, E>,
286 ) -> Result<ContentSearchResult, E> {
287 let mut matches = Vec::new();
288 let mut total_matches = 0;
289 let mut directories = std::collections::BTreeMap::<String, usize>::new();
290 for path in self.paths {
291 let Some(content) = retrieve(&path)? else {
292 continue;
293 };
294 if content.len() > RECORDED_CONTENT_LIMIT || syntext::index::is_binary(&content) {
295 continue;
296 }
297 let mut line_start = 0;
298 let mut file_count = 0;
299 // This borrowed-line adapter implements syntext 1.4's verifier
300 // contract: first match per line, CR stripped only before LF, no
301 // artificial trailing empty line, and file-level binary detection.
302 // Differential tests below keep it pinned to verify_regex, including
303 // NULs beyond the first 8192 bytes. No dependency fork is required.
304 for (index, raw_line) in content.split_inclusive(|byte| *byte == b'\n').enumerate() {
305 let line = raw_line
306 .strip_suffix(b"\n")
307 .map(|line| line.strip_suffix(b"\r").unwrap_or(line))
308 .unwrap_or(raw_line);
309 if let Some(found) = self.re.find(line) {
310 file_count += 1;
311 if matches.len() < self.display_limit {
312 matches.push(ContentMatch {
313 path: path.clone(),
314 line_number: (index + 1) as u32,
315 line_content: String::from_utf8_lossy(line).into_owned(),
316 byte_offset: (line_start + found.start()) as u64,
317 submatch_start: found.start(),
318 submatch_end: found.end(),
319 });
320 #[cfg(any(test, feature = "query-test-instrumentation"))]
321 crate::query_diagnostics::retained(matches.len());
322 }
323 }
324 line_start += raw_line.len();
325 }
326 if file_count > 0 {
327 total_matches += file_count;
328 *directories.entry(directory_bucket(&path)).or_default() += file_count;
329 }
330 }
331 Ok(ContentSearchResult {
332 matches,
333 total_matches,
334 dir_facets: directory_facets(directories),
335 })
336 }
337}
338
339fn recorded_path_order(a: &str, b: &str) -> std::cmp::Ordering {

Callers

nothing calls this directly

Calls 9

is_binaryFunction · 0.85
retainedFunction · 0.85
directory_bucketFunction · 0.85
directory_facetsFunction · 0.85
endMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected