Skip to main content

liboxen/core/v_latest/
revisions.rs

1use crate::error::OxenError;
2use crate::storage::LocalFilePath;
3use crate::{model::LocalRepository, repositories};
4use std::path::Path;
5
6/// Get the version file path from a commit id
7pub async fn get_version_file_from_commit_id(
8    repo: &LocalRepository,
9    commit_id: impl AsRef<str>,
10    path: impl AsRef<Path>,
11) -> Result<LocalFilePath, OxenError> {
12    let commit_id = commit_id.as_ref();
13    let path = path.as_ref();
14    let commit = repositories::commits::get_by_id(repo, commit_id)?
15        .ok_or_else(|| OxenError::commit_id_does_not_exist(commit_id))?;
16
17    let file_node = repositories::tree::get_file_by_path(repo, &commit, path)?
18        .ok_or_else(|| OxenError::entry_does_not_exist_in_commit(path, commit_id))?;
19
20    let version_store = repo.version_store()?;
21    let hash = file_node.hash().to_string();
22    let version_path = version_store.get_version_path(&hash).await?;
23    Ok(version_path)
24}