pray_core/
resolve_git_paths.rs1use crate::hashing::sha256_prefixed;
2use std::path::{Path, PathBuf};
3
4pub fn git_source_cache_directory(project_root: &Path, clone_url: &str) -> PathBuf {
5 git_source_cache_directory_with_subdir(project_root, clone_url, None)
6}
7
8pub fn git_source_cache_directory_with_subdir(
9 project_root: &Path,
10 clone_url: &str,
11 subdir: Option<&str>,
12) -> PathBuf {
13 project_root
14 .join(".pray/cache/git")
15 .join(cache_key(&worktree_cache_identity(clone_url, subdir)))
16}
17
18pub(crate) fn cache_key(text: &str) -> String {
19 sha256_prefixed(text.as_bytes())
20 .trim_start_matches("sha256:")
21 .chars()
22 .take(16)
23 .collect()
24}
25
26fn worktree_cache_identity(clone_url: &str, subdir: Option<&str>) -> String {
27 match subdir {
28 Some(subdir) if !subdir.is_empty() => format!("{clone_url}\n{subdir}"),
29 _ => clone_url.to_string(),
30 }
31}