in focus/internals/src/lib/model/repo.rs [960:1066]
fn sync_incremental(
&self,
commit_id: Oid,
targets: &HashSet<Target>,
outliner: &dyn Outliner,
cache: &RocksDBCache,
snapshot: Option<PathBuf>,
app: Arc<App>,
) -> Result<PatternSet> {
let index_config = &self.config().index;
let commit = self
.underlying()
.find_commit(commit_id)
.with_context(|| format!("Resolving commit {}", commit_id))?;
let tree = commit.tree().context("Resolving tree")?;
let hash_context = HashContext::new(&self.repo, &tree)?;
let ti_client = app.tool_insights_client();
let dependency_keys: HashSet<DependencyKey> =
targets.iter().cloned().map(DependencyKey::from).collect();
info!("Checking cache for sparse checkout patterns");
let mut paths_to_materialize =
get_files_to_materialize(&hash_context, cache, dependency_keys.clone())?;
if index_config.enabled {
if let PathsToMaterializeResult::MissingKeys { .. } = paths_to_materialize {
info!("Cache miss for sparse checkout patterns; fetching from the remote index");
// TODO: Re-enable after the index is moved into its own crate.
// let _: Result<ExitCode> = index::fetch_internal(
// app.clone(),
// cache,
// working_tree.work_dir().to_path_buf(),
// index_config,
// );
// Query again now that the index is populated.
paths_to_materialize =
get_files_to_materialize(&hash_context, cache, dependency_keys)?;
}
}
Ok(match paths_to_materialize {
PathsToMaterializeResult::Ok { seen_keys, paths } => {
info!(
num_seen_keys = seen_keys.len(),
"Cache hit for sparse checkout patterns"
);
ti_client
.get_context()
.add_to_custom_map("index_miss_count", "0");
ti_client
.get_context()
.add_to_custom_map("index_hit_count", seen_keys.len().to_string());
paths
.into_iter()
.map(|path| Pattern::Directory {
precedence: LAST,
path,
recursive: true,
})
.collect()
}
PathsToMaterializeResult::MissingKeys {
seen_keys,
missing_keys,
} => {
info!(
num_missing_keys = ?missing_keys.len(),
"Cache miss for sparse checkout patterns; querying Bazel"
);
// Write a file listing missing DependencyKeys.
{
let (file, _, _) =
self.app
.sandbox()
.create_file(Some("missing-keys"), Some("txt"), None)?;
let mut writer = BufWriter::new(file);
for (dependency_key, _) in missing_keys.iter() {
writeln!(&mut writer, "{:?}", dependency_key)?;
}
}
ti_client
.get_context()
.add_to_custom_map("index_miss_count", missing_keys.len().to_string());
ti_client
.get_context()
.add_to_custom_map("index_hit_count", seen_keys.len().to_string());
debug!(?missing_keys, "These are the missing keys");
let resolution_options = ResolutionOptions {
bazel_resolution_strategy: BazelResolutionStrategy::Incremental,
};
let (outline_patterns, resolution_result) = outliner
.outline(
commit_id,
targets,
&resolution_options,
snapshot,
app.clone(),
)
.context("Failed to outline")?;
debug!(?resolution_result, ?outline_patterns, "Resolved patterns");
update_object_database_from_resolution(&hash_context, cache, &resolution_result)?;
outline_patterns
}
})
}