mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-22 12:34:49 +00:00
working_copy: make write_conflict_to_store()
also handle conflicts
With this change, `write_path_to_store()` contains all the logic for reading a file from disk and writing it to a `TreeBuilder`, making the code for added and modified files more similar.
This commit is contained in:
parent
56e6233f9e
commit
37a770e8b4
1 changed files with 21 additions and 17 deletions
|
@ -812,7 +812,8 @@ impl TreeState {
|
||||||
(None, Some(new_file_state)) => {
|
(None, Some(new_file_state)) => {
|
||||||
// untracked
|
// untracked
|
||||||
let file_type = new_file_state.file_type.clone();
|
let file_type = new_file_state.file_type.clone();
|
||||||
let file_value = self.write_path_to_store(repo_path, &disk_path, file_type)?;
|
let file_value =
|
||||||
|
self.write_path_to_store(repo_path, &disk_path, None, file_type)?;
|
||||||
return Ok(UpdatedFileState::Changed(file_value, new_file_state));
|
return Ok(UpdatedFileState::Changed(file_value, new_file_state));
|
||||||
}
|
}
|
||||||
(Some(current_file_state), Some(new_file_state)) => {
|
(Some(current_file_state), Some(new_file_state)) => {
|
||||||
|
@ -836,13 +837,7 @@ impl TreeState {
|
||||||
// If the file contained a conflict before and is now a normal file on disk, we
|
// 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.
|
// try to parse any conflict markers in the file into a conflict.
|
||||||
let new_tree_value =
|
let new_tree_value =
|
||||||
if let (Some(TreeValue::Conflict(conflict_id)), FileType::Normal { executable }) =
|
self.write_path_to_store(repo_path, &disk_path, current_tree_value, new_file_type)?;
|
||||||
(current_tree_value, &new_file_type)
|
|
||||||
{
|
|
||||||
self.write_conflict_to_store(repo_path, &disk_path, conflict_id, *executable)?
|
|
||||||
} else {
|
|
||||||
self.write_path_to_store(repo_path, &disk_path, new_file_type)?
|
|
||||||
};
|
|
||||||
return Ok(UpdatedFileState::Changed(new_tree_value, new_file_state));
|
return Ok(UpdatedFileState::Changed(new_tree_value, new_file_state));
|
||||||
}
|
}
|
||||||
Ok(UpdatedFileState::Unchanged(new_file_state))
|
Ok(UpdatedFileState::Unchanged(new_file_state))
|
||||||
|
@ -882,18 +877,27 @@ impl TreeState {
|
||||||
&self,
|
&self,
|
||||||
repo_path: &RepoPath,
|
repo_path: &RepoPath,
|
||||||
disk_path: &Path,
|
disk_path: &Path,
|
||||||
|
current_tree_value: Option<TreeValue>,
|
||||||
file_type: FileType,
|
file_type: FileType,
|
||||||
) -> Result<TreeValue, SnapshotError> {
|
) -> Result<TreeValue, SnapshotError> {
|
||||||
match file_type {
|
// If the file contained a conflict before and is now a normal file on disk, we
|
||||||
FileType::Normal { executable } => {
|
// try to parse any conflict markers in the file into a conflict.
|
||||||
let id = self.write_file_to_store(repo_path, disk_path)?;
|
if let (Some(TreeValue::Conflict(conflict_id)), FileType::Normal { executable }) =
|
||||||
Ok(TreeValue::File { id, executable })
|
(current_tree_value, &file_type)
|
||||||
|
{
|
||||||
|
self.write_conflict_to_store(repo_path, disk_path, conflict_id, *executable)
|
||||||
|
} else {
|
||||||
|
match file_type {
|
||||||
|
FileType::Normal { executable } => {
|
||||||
|
let id = self.write_file_to_store(repo_path, disk_path)?;
|
||||||
|
Ok(TreeValue::File { id, executable })
|
||||||
|
}
|
||||||
|
FileType::Symlink => {
|
||||||
|
let id = self.write_symlink_to_store(repo_path, disk_path)?;
|
||||||
|
Ok(TreeValue::Symlink(id))
|
||||||
|
}
|
||||||
|
FileType::GitSubmodule => panic!("git submodule cannot be written to store"),
|
||||||
}
|
}
|
||||||
FileType::Symlink => {
|
|
||||||
let id = self.write_symlink_to_store(repo_path, disk_path)?;
|
|
||||||
Ok(TreeValue::Symlink(id))
|
|
||||||
}
|
|
||||||
FileType::GitSubmodule => panic!("git submodule cannot be written to store"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue