ok/jj
1
0
Fork 0
forked from mirrors/jj

working_copy: move creation of parent dirs to one place

I'm about to add handling of parent dirs that are existing ignored
files, so it's better to have it in one place. The only functional
difference should be that we now create parent directories for git
submodules. I don't think that matters.
This commit is contained in:
Martin von Zweigbergk 2023-10-07 10:17:04 -07:00 committed by Martin von Zweigbergk
parent 7f4fe22a98
commit 4601c87710

View file

@ -1076,7 +1076,6 @@ impl TreeState {
id: &FileId, id: &FileId,
executable: bool, executable: bool,
) -> Result<FileState, CheckoutError> { ) -> Result<FileState, CheckoutError> {
create_parent_dirs(&self.working_copy_path, path)?;
let mut file = OpenOptions::new() let mut file = OpenOptions::new()
.write(true) .write(true)
.create_new(true) // Don't overwrite un-ignored file. Don't follow symlink. .create_new(true) // Don't overwrite un-ignored file. Don't follow symlink.
@ -1109,7 +1108,6 @@ impl TreeState {
path: &RepoPath, path: &RepoPath,
id: &SymlinkId, id: &SymlinkId,
) -> Result<FileState, CheckoutError> { ) -> Result<FileState, CheckoutError> {
create_parent_dirs(&self.working_copy_path, path)?;
let target = self.store.read_symlink(path, id)?; let target = self.store.read_symlink(path, id)?;
#[cfg(windows)] #[cfg(windows)]
{ {
@ -1139,7 +1137,6 @@ impl TreeState {
path: &RepoPath, path: &RepoPath,
conflict: &Merge<Option<TreeValue>>, conflict: &Merge<Option<TreeValue>>,
) -> Result<FileState, CheckoutError> { ) -> Result<FileState, CheckoutError> {
create_parent_dirs(&self.working_copy_path, path)?;
let mut file = OpenOptions::new() let mut file = OpenOptions::new()
.write(true) .write(true)
.create_new(true) // Don't overwrite un-ignored file. Don't follow symlink. .create_new(true) // Don't overwrite un-ignored file. Don't follow symlink.
@ -1238,6 +1235,9 @@ impl TreeState {
if before.is_present() { if before.is_present() {
fs::remove_file(&disk_path).ok(); fs::remove_file(&disk_path).ok();
} }
if after.is_present() {
create_parent_dirs(&self.working_copy_path, &path)?;
}
// TODO: Check that the file has not changed before overwriting/removing it. // TODO: Check that the file has not changed before overwriting/removing it.
match after.into_resolved() { match after.into_resolved() {
Ok(None) => { Ok(None) => {