Skip to content

Commit

Permalink
working_copy: treat a missing file state as dirty
Browse files Browse the repository at this point in the history
If we don't have a recorded state for a file, we assume that it's new,
so we add it to the tree as the type it appears on disk. That means we
won't check if it exists as a conflict in the current tree. As another
step towards making the file state just a cache, let's instead treat
this case as a dirty file, so we look up the current value from the
tree. That means that adding files will be a tiny bit slower, but I
doubt it will be noticeable (we need to read the file from disk and
write it to the backend anyway).
  • Loading branch information
martinvonz committed Jul 31, 2023
1 parent cb8ff84 commit 4fa2a27
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/src/working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,29 +821,28 @@ impl TreeState {
current_tree: &Tree,
new_file_state: &FileState,
) -> Result<UpdatedFileState, SnapshotError> {
let current_file_state = match maybe_current_file_state {
let clean = match maybe_current_file_state {
None => {
// untracked
let file_type = new_file_state.file_type.clone();
let file_value =
self.write_path_to_store(repo_path, &disk_path, None, file_type)?;
return Ok(UpdatedFileState::Changed(file_value));
false
}
Some(current_file_state) => {
// If the file's mtime was set at the same time as this state file's own mtime,
// then we don't know if the file was modified before or after this state file.
current_file_state == new_file_state && current_file_state.mtime < self.own_mtime
}
Some(current_file_state) => current_file_state,
};

// If the file's mtime was set at the same time as this state file's own mtime,
// then we don't know if the file was modified before or after this state file.
if current_file_state != new_file_state || current_file_state.mtime >= self.own_mtime {
if clean {
Ok(UpdatedFileState::Unchanged)
} else {
let new_file_type = new_file_state.file_type.clone();
let current_tree_value = current_tree.path_value(repo_path);
// 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.
let new_tree_value =
self.write_path_to_store(repo_path, &disk_path, current_tree_value, new_file_type)?;
return Ok(UpdatedFileState::Changed(new_tree_value));
Ok(UpdatedFileState::Changed(new_tree_value))
}
Ok(UpdatedFileState::Unchanged)
}

fn write_conflict_to_store(
Expand Down

0 comments on commit 4fa2a27

Please sign in to comment.