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

working_copy: inline write_conflict_to_store()

For tree-level conflicts, we're eventually not going to have
`ConflictId`. We'd want to make `write_conflict_to_store()` take a
`Merge<Option<TreeValue>>` and return an updated such value. That
would leave very little logic in the function, so let's just inline it
instead.
This commit is contained in:
Martin von Zweigbergk 2023-08-11 21:34:16 -07:00 committed by Martin von Zweigbergk
parent d57237af5d
commit 2102de94b0

View file

@ -954,20 +954,32 @@ impl TreeState {
}
}
fn write_conflict_to_store(
fn write_path_to_store(
&self,
repo_path: &RepoPath,
disk_path: &Path,
conflict_id: ConflictId,
executable: bool,
current_tree_value: Option<TreeValue>,
file_type: FileType,
) -> Result<TreeValue, SnapshotError> {
// If the file contained a conflict before and is now a normal file on disk, we
// try to parse any conflict markers in the file into a conflict.
if let (Some(TreeValue::Conflict(conflict_id)), FileType::Normal { executable }) =
(&current_tree_value, &file_type)
{
#[cfg(unix)]
let executable = *executable;
#[cfg(windows)]
let executable = {
let () = executable; // use the variable
false
};
let mut file = File::open(disk_path).map_err(|err| SnapshotError::IoError {
message: format!("Failed to open file {}", disk_path.display()),
err,
})?;
let mut content = vec![];
file.read_to_end(&mut content).unwrap();
let conflict = self.store.read_conflict(repo_path, &conflict_id)?;
let conflict = self.store.read_conflict(repo_path, conflict_id)?;
if let Some(old_file_ids) = conflict.to_file_merge() {
let new_file_ids = conflicts::update_from_content(
&old_file_ids,
@ -988,35 +1000,13 @@ impl TreeState {
self.store.write_conflict(repo_path, &new_conflict)?;
Ok(TreeValue::Conflict(new_conflict_id))
} else {
Ok(TreeValue::Conflict(conflict_id))
Ok(TreeValue::Conflict(conflict_id.clone()))
}
}
}
} else {
Ok(TreeValue::Conflict(conflict_id))
Ok(TreeValue::Conflict(conflict_id.clone()))
}
}
fn write_path_to_store(
&self,
repo_path: &RepoPath,
disk_path: &Path,
current_tree_value: Option<TreeValue>,
file_type: FileType,
) -> Result<TreeValue, SnapshotError> {
// If the file contained a conflict before and is now a normal file on disk, we
// try to parse any conflict markers in the file into a conflict.
if let (Some(TreeValue::Conflict(conflict_id)), FileType::Normal { executable }) =
(&current_tree_value, &file_type)
{
#[cfg(unix)]
let executable = *executable;
#[cfg(windows)]
let executable = {
let () = executable; // use the variable
false
};
self.write_conflict_to_store(repo_path, disk_path, conflict_id.clone(), executable)
} else {
match file_type {
FileType::Normal { executable } => {