This commit is contained in:
jif-oai
2025-10-16 11:17:59 +01:00
parent 25defbf253
commit de63774a9e
3 changed files with 14 additions and 7 deletions

5
codex-rs/Cargo.lock generated
View File

@@ -1390,7 +1390,6 @@ dependencies = [
"codex-common",
"codex-core",
"codex-file-search",
"codex-git-tooling",
"codex-login",
"codex-ollama",
"codex-protocol",
@@ -3088,7 +3087,7 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3"
dependencies = [
"bitflags 2.9.1",
"bitflags 2.9.4",
"inotify-sys",
"libc",
]
@@ -3727,7 +3726,7 @@ version = "8.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d3d07927151ff8575b7087f245456e549fea62edf0ec4e565a5ee50c8402bc3"
dependencies = [
"bitflags 2.9.1",
"bitflags 2.9.4",
"fsevent-sys",
"inotify",
"kqueue",

View File

@@ -177,6 +177,8 @@ pub fn restore_to_commit(repo_path: &Path, commit_id: &str) -> Result<(), GitToo
restore_to_commit_inner(repo_root.as_path(), repo_prefix.as_deref(), commit_id)
}
/// Restores the working tree and index to the given commit using `git restore`.
/// The repository root and optional repository-relative prefix limit the restore scope.
fn restore_to_commit_inner(
repo_root: &Path,
repo_prefix: Option<&Path>,
@@ -206,6 +208,7 @@ struct UntrackedSnapshot {
dirs: Vec<PathBuf>,
}
/// Captures the repository's untracked files and directories scoped to an optional subdirectory.
fn capture_existing_untracked(
repo_root: &Path,
repo_prefix: Option<&Path>,
@@ -258,6 +261,7 @@ fn capture_existing_untracked(
Ok(snapshot)
}
/// Removes untracked files and directories that were not present when the snapshot was captured.
fn remove_new_untracked(
repo_root: &Path,
preserved_files: &[PathBuf],
@@ -288,6 +292,7 @@ fn remove_new_untracked(
Ok(())
}
/// Determines whether an untracked path should be kept because it existed in the snapshot.
fn should_preserve(
path: &Path,
preserved_files: &HashSet<PathBuf>,
@@ -302,6 +307,7 @@ fn should_preserve(
.any(|dir| path.starts_with(dir.as_path()))
}
/// Deletes the file or directory at the provided path, ignoring if it is already absent.
fn remove_path(path: &Path) -> Result<(), GitToolingError> {
match fs::symlink_metadata(path) {
Ok(metadata) => {

View File

@@ -13,11 +13,13 @@ pub use ghost_commits::restore_ghost_commit;
pub use ghost_commits::restore_to_commit;
pub use platform::create_symlink;
type CommitID = String;
/// Details of a ghost commit created from a repository state.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GhostCommit {
id: String,
parent: Option<String>,
id: CommitID,
parent: Option<CommitID>,
preexisting_untracked_files: Vec<PathBuf>,
preexisting_untracked_dirs: Vec<PathBuf>,
}
@@ -25,8 +27,8 @@ pub struct GhostCommit {
impl GhostCommit {
/// Create a new ghost commit wrapper from a raw commit ID and optional parent.
pub fn new(
id: String,
parent: Option<String>,
id: CommitID,
parent: Option<CommitID>,
preexisting_untracked_files: Vec<PathBuf>,
preexisting_untracked_dirs: Vec<PathBuf>,
) -> Self {