mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-11 15:07:06 +00:00
working_copy: inline apply_diff
closure
This effectively undoes d8a313cdd4
, which is no longer needed since
we just changed that error handling. It should make it easier to share
some of the current if/else blocks.
This commit is contained in:
parent
44eb902171
commit
b9a122ffe7
1 changed files with 20 additions and 29 deletions
|
@ -1234,10 +1234,22 @@ impl TreeState {
|
||||||
new_tree: &MergedTree,
|
new_tree: &MergedTree,
|
||||||
matcher: &dyn Matcher,
|
matcher: &dyn Matcher,
|
||||||
) -> Result<CheckoutStats, CheckoutError> {
|
) -> Result<CheckoutStats, CheckoutError> {
|
||||||
let mut apply_diff = |path: RepoPath,
|
// TODO: maybe it's better not include the skipped counts in the "intended"
|
||||||
before: Merge<Option<TreeValue>>,
|
// counts
|
||||||
after: Merge<Option<TreeValue>>|
|
let mut stats = CheckoutStats {
|
||||||
-> Result<bool, CheckoutError> {
|
updated_files: 0,
|
||||||
|
added_files: 0,
|
||||||
|
removed_files: 0,
|
||||||
|
skipped_files: 0,
|
||||||
|
};
|
||||||
|
for (path, before, after) in old_tree.diff(new_tree, matcher) {
|
||||||
|
if after.is_absent() {
|
||||||
|
stats.removed_files += 1;
|
||||||
|
} else if before.is_absent() {
|
||||||
|
stats.added_files += 1;
|
||||||
|
} else {
|
||||||
|
stats.updated_files += 1;
|
||||||
|
}
|
||||||
let disk_path = path.to_fs_path(&self.working_copy_path);
|
let disk_path = path.to_fs_path(&self.working_copy_path);
|
||||||
|
|
||||||
if before.is_present() {
|
if before.is_present() {
|
||||||
|
@ -1245,13 +1257,15 @@ impl TreeState {
|
||||||
}
|
}
|
||||||
if before.is_absent() && disk_path.exists() {
|
if before.is_absent() && disk_path.exists() {
|
||||||
self.file_states.insert(path, FileState::placeholder());
|
self.file_states.insert(path, FileState::placeholder());
|
||||||
return Ok(true);
|
stats.skipped_files += 1;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if after.is_present() {
|
if after.is_present() {
|
||||||
let skip = create_parent_dirs(&self.working_copy_path, &path)?;
|
let skip = create_parent_dirs(&self.working_copy_path, &path)?;
|
||||||
if skip {
|
if skip {
|
||||||
self.file_states.insert(path, FileState::placeholder());
|
self.file_states.insert(path, FileState::placeholder());
|
||||||
return Ok(true);
|
stats.skipped_files += 1;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Check that the file has not changed before overwriting/removing it.
|
// TODO: Check that the file has not changed before overwriting/removing it.
|
||||||
|
@ -1290,29 +1304,6 @@ impl TreeState {
|
||||||
self.file_states.insert(path, file_state);
|
self.file_states.insert(path, file_state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(false)
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: maybe it's better not include the skipped counts in the "intended"
|
|
||||||
// counts
|
|
||||||
let mut stats = CheckoutStats {
|
|
||||||
updated_files: 0,
|
|
||||||
added_files: 0,
|
|
||||||
removed_files: 0,
|
|
||||||
skipped_files: 0,
|
|
||||||
};
|
|
||||||
for (path, before, after) in old_tree.diff(new_tree, matcher) {
|
|
||||||
if after.is_absent() {
|
|
||||||
stats.removed_files += 1;
|
|
||||||
} else if before.is_absent() {
|
|
||||||
stats.added_files += 1;
|
|
||||||
} else {
|
|
||||||
stats.updated_files += 1;
|
|
||||||
}
|
|
||||||
let skipped = apply_diff(path, before, after)?;
|
|
||||||
if skipped {
|
|
||||||
stats.skipped_files += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(stats)
|
Ok(stats)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue