mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
core: carry PathUri through patch diffs
This commit is contained in:
@@ -6,6 +6,7 @@ use std::path::PathBuf;
|
||||
|
||||
use codex_file_system::ExecutorFileSystem;
|
||||
use codex_file_system::FindUpErrorPolicy;
|
||||
use codex_file_system::find_nearest_ancestor_with_markers;
|
||||
use codex_file_system::find_nearest_native_ancestor_with_markers;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_path_uri::PathUri;
|
||||
@@ -65,6 +66,36 @@ pub async fn get_git_repo_root_with_fs(
|
||||
.ok()?
|
||||
}
|
||||
|
||||
/// Return the repository root for a URI `cwd` using the provided filesystem.
|
||||
///
|
||||
/// Native paths retain the lossless traversal behavior of
|
||||
/// [`get_git_repo_root_with_fs`]. Foreign-platform paths stay in URI space so
|
||||
/// their filesystem can be inspected without host reinterpretation.
|
||||
pub async fn get_git_repo_root_uri_with_fs(
|
||||
fs: &dyn ExecutorFileSystem,
|
||||
cwd: &PathUri,
|
||||
) -> Option<PathUri> {
|
||||
if let Ok(native_cwd) = cwd.to_abs_path() {
|
||||
return get_git_repo_root_with_fs(fs, &native_cwd)
|
||||
.await
|
||||
.map(|root| PathUri::from_abs_path(&root));
|
||||
}
|
||||
|
||||
let base = match fs.get_metadata(cwd, /*sandbox*/ None).await {
|
||||
Ok(metadata) if metadata.is_directory => cwd.clone(),
|
||||
_ => cwd.parent()?,
|
||||
};
|
||||
find_nearest_ancestor_with_markers(
|
||||
fs,
|
||||
&base,
|
||||
vec![".git".to_string()],
|
||||
FindUpErrorPolicy::Ignore,
|
||||
/*sandbox*/ None,
|
||||
)
|
||||
.await
|
||||
.ok()?
|
||||
}
|
||||
|
||||
/// Timeout for git commands to prevent freezing on large repositories
|
||||
const GIT_COMMAND_TIMEOUT: TokioDuration = TokioDuration::from_secs(5);
|
||||
const DISABLED_HOOKS_PATH: &str = if cfg!(windows) { "NUL" } else { "/dev/null" };
|
||||
|
||||
@@ -35,6 +35,7 @@ pub use info::default_branch_name;
|
||||
pub use info::get_git_remote_urls;
|
||||
pub use info::get_git_remote_urls_assume_git_repo;
|
||||
pub use info::get_git_repo_root;
|
||||
pub use info::get_git_repo_root_uri_with_fs;
|
||||
pub use info::get_git_repo_root_with_fs;
|
||||
pub use info::get_has_changes;
|
||||
pub use info::get_head_commit_hash;
|
||||
|
||||
Reference in New Issue
Block a user