fn fetch_internal()

in focus/operations/src/index.rs [275:318]


fn fetch_internal(
    app: Arc<App>,
    cache: &RocksDBCache,
    sparse_repo_path: PathBuf,
    index_config: &IndexConfig,
) -> anyhow::Result<ExitCode> {
    let index_dir = index_repo_dir(&sparse_repo_path);
    let synchronizer = GitBackedCacheSynchronizer::create(
        index_dir,
        index_config.remote.clone(),
        app.clone(),
        TAG_NAMESPACE.to_string(),
        COMMIT_USER_EMAIL.to_string(),
        COMMIT_USER_NAME.to_string(),
    )?;
    let repo = Repo::open(sparse_repo_path.as_path(), app).context("Failed to open repo")?;
    let mut commit = repo.get_head_commit()?;

    let available_keysets = synchronizer.available_remote_keysets()?;

    let mut found_keyset: Option<KeysetID> = None;
    for _ in 0..PARENTS_TO_TRY_IN_FETCH {
        let keyset_id = commit.tree()?.id();

        if available_keysets.contains(&keyset_id) {
            found_keyset = Some(keyset_id);
            break;
        }
        commit = commit.parent(0)?;
    }
    if let Some(keyset_id) = found_keyset {
        let keyset_id_str = keyset_id.to_string();
        let span = debug_span!("Fetching index");
        info!(tag = %keyset_id_str, "Fetching index");
        let _guard = span.enter();
        synchronizer
            .fetch_and_populate(keyset_id, cache)
            .context("Fetching index data")?;
    } else {
        info!("No index matches the current commit");
    }

    Ok(ExitCode(0))
}