mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 15:16:35 +00:00
working_copy: pass in Merge
arguments to closure in update()
When we do an update between two `MergedTree` instances, we'll get diffs between two `Merge<Option<TreeValue>>`. This commit prepares for that by changing the type of the `before` and `after` arguments we pass into the closure in `update()`.
This commit is contained in:
parent
4b12dba186
commit
5610525c29
1 changed files with 11 additions and 7 deletions
|
@ -1223,14 +1223,14 @@ impl TreeState {
|
||||||
mut handle_error: impl FnMut(CheckoutError) -> Result<(), CheckoutError>,
|
mut handle_error: impl FnMut(CheckoutError) -> Result<(), CheckoutError>,
|
||||||
) -> Result<CheckoutStats, CheckoutError> {
|
) -> Result<CheckoutStats, CheckoutError> {
|
||||||
let mut apply_diff = |path: RepoPath,
|
let mut apply_diff = |path: RepoPath,
|
||||||
before: Option<TreeValue>,
|
before: Merge<Option<TreeValue>>,
|
||||||
after: Option<TreeValue>|
|
after: Merge<Option<TreeValue>>|
|
||||||
-> Result<(), CheckoutError> {
|
-> Result<(), CheckoutError> {
|
||||||
let disk_path = path.to_fs_path(&self.working_copy_path);
|
let disk_path = path.to_fs_path(&self.working_copy_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 {
|
match after.into_resolved() {
|
||||||
None => {
|
Ok(None) => {
|
||||||
fs::remove_file(&disk_path).ok();
|
fs::remove_file(&disk_path).ok();
|
||||||
let mut parent_dir = disk_path.parent().unwrap();
|
let mut parent_dir = disk_path.parent().unwrap();
|
||||||
loop {
|
loop {
|
||||||
|
@ -1241,8 +1241,8 @@ impl TreeState {
|
||||||
}
|
}
|
||||||
self.file_states.remove(&path);
|
self.file_states.remove(&path);
|
||||||
}
|
}
|
||||||
Some(after) => {
|
Ok(Some(after)) => {
|
||||||
if before.is_some() {
|
if before.is_present() {
|
||||||
fs::remove_file(&disk_path).ok();
|
fs::remove_file(&disk_path).ok();
|
||||||
}
|
}
|
||||||
let file_state = match after {
|
let file_state = match after {
|
||||||
|
@ -1264,6 +1264,9 @@ impl TreeState {
|
||||||
};
|
};
|
||||||
self.file_states.insert(path, file_state);
|
self.file_states.insert(path, file_state);
|
||||||
}
|
}
|
||||||
|
Err(_after_conflict) => {
|
||||||
|
todo!("write conflict to the working copy");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
@ -1282,7 +1285,8 @@ impl TreeState {
|
||||||
} else {
|
} else {
|
||||||
stats.updated_files += 1;
|
stats.updated_files += 1;
|
||||||
}
|
}
|
||||||
apply_diff(path, before, after).or_else(&mut handle_error)?;
|
apply_diff(path, Merge::resolved(before), Merge::resolved(after))
|
||||||
|
.or_else(&mut handle_error)?;
|
||||||
}
|
}
|
||||||
Ok(stats)
|
Ok(stats)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue