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

Function update_content_index_paths

atomic-repository/src/content_search.rs:92–139  ·  view source on GitHub ↗

Incrementally refresh the content index for a set of repo-relative paths that changed (e.g. the files touched by a recorded change) and persist the result to disk. Each path is re-read from disk: added/modified files are re-indexed and deleted files are removed, keeping the index in sync with the working copy without re-walking the whole tree. Ignored and Atomic-internal paths are skipped so buil

(
    repo_root: &Path,
    paths: I,
)

Source from the content-addressed store, hash-verified

90/// No-op when the content index does not yet exist — building it is the job of
91/// [`build_content_index`]; this only maintains an existing index.
92pub fn update_content_index_paths<I, P>(
93 repo_root: &Path,
94 paths: I,
95) -> Result<(), ContentSearchError>
96where
97 I: IntoIterator<Item = P>,
98 P: AsRef<Path>,
99{
100 if !has_content_index(repo_root) {
101 return Ok(());
102 }
103
104 let ignore_rules = crate::ignore::IgnoreRules::load_for_enrichment(repo_root);
105 let config = content_config(repo_root);
106 let index = Index::open(config)?;
107
108 let mut any = false;
109 for path in paths {
110 let rel = path.as_ref();
111 if crate::ignore::is_enrichment_internal(rel) || ignore_rules.is_ignored(rel, false) {
112 continue;
113 }
114 // syntext strips `repo_root` to derive the relative path, so hand it an
115 // absolute path. The file need not exist — a missing file is treated as
116 // a deletion and removed from the index.
117 let absolute = repo_root.join(rel);
118 index.notify_change(&absolute)?;
119 any = true;
120 }
121
122 if !any {
123 return Ok(());
124 }
125
126 // Commit the pending overlay and fold it into on-disk base segments so the
127 // change survives to the next `Index::open`. When the changed set is large
128 // relative to the index (syntext caps the overlay at 50% of base docs),
129 // `compact` reports `OverlayFull`; the sanctioned recovery is a full
130 // (filtered) rebuild.
131 match index.compact() {
132 Ok(()) => Ok(()),
133 Err(IndexError::OverlayFull { .. }) => {
134 drop(index);
135 build_content_index(repo_root)
136 }
137 Err(e) => Err(e.into()),
138 }
139}
140
141/// Search the content index.
142///

Callers 3

enrich_changeMethod · 0.85
recordMethod · 0.85

Calls 6

has_content_indexFunction · 0.85
content_configFunction · 0.85
is_enrichment_internalFunction · 0.85
build_content_indexFunction · 0.85
as_refMethod · 0.80
is_ignoredMethod · 0.45