tree: return early when trying to resolve modify/delete conflict

Modify/delete conflicts cannot be automatically resolved, so there's
no point in wasting resources calculating the diff(s).
This commit is contained in:
Martin von Zweigbergk 2023-02-17 09:02:48 -08:00 committed by Martin von Zweigbergk
parent 3dfedf5814
commit 7f334656b1

View file

@ -653,6 +653,12 @@ fn try_resolve_file_conflict(
filename: &RepoPath, filename: &RepoPath,
conflict: &Conflict, conflict: &Conflict,
) -> Result<Option<(Vec<u8>, bool)>, TreeMergeError> { ) -> Result<Option<(Vec<u8>, bool)>, TreeMergeError> {
// If the file was missing from any side (typically a modify/delete conflict),
// we can't automatically merge it.
if conflict.adds.len() != conflict.removes.len() + 1 {
return Ok(None);
}
// If there are any non-file parts in the conflict, we can't merge it. We check // If there are any non-file parts in the conflict, we can't merge it. We check
// early so we don't waste time reading file contents if we can't merge them // early so we don't waste time reading file contents if we can't merge them
// anyway. At the same time we determine whether the resulting file should // anyway. At the same time we determine whether the resulting file should