merge_tools: leverage ok_or_else() instead of pattern matching

This commit is contained in:
Martin von Zweigbergk 2023-06-06 16:26:39 -07:00 committed by Martin von Zweigbergk
parent fb3f8b3bd3
commit 81aa90efd3

View file

@ -161,18 +161,15 @@ pub fn run_mergetool(
None => return Err(ConflictResolveError::PathNotFoundError(repo_path.clone())), None => return Err(ConflictResolveError::PathNotFoundError(repo_path.clone())),
}; };
let conflict = tree.store().read_conflict(repo_path, &conflict_id)?; let conflict = tree.store().read_conflict(repo_path, &conflict_id)?;
let file_conflict = match to_file_conflict(&conflict) { let file_conflict = to_file_conflict(&conflict).ok_or_else(|| {
Some(c) => c,
_ => {
let mut summary_bytes: Vec<u8> = vec![]; let mut summary_bytes: Vec<u8> = vec![];
describe_conflict(&conflict, &mut summary_bytes) describe_conflict(&conflict, &mut summary_bytes)
.expect("Writing to an in-memory buffer should never fail"); .expect("Writing to an in-memory buffer should never fail");
return Err(ConflictResolveError::NotNormalFilesError( ConflictResolveError::NotNormalFilesError(
repo_path.clone(), repo_path.clone(),
String::from_utf8_lossy(summary_bytes.as_slice()).to_string(), String::from_utf8_lossy(summary_bytes.as_slice()).to_string(),
)); )
} })?;
};
// We only support conflicts with 2 sides (3-way conflicts) // We only support conflicts with 2 sides (3-way conflicts)
if file_conflict.adds().len() > 2 { if file_conflict.adds().len() > 2 {
return Err(ConflictResolveError::ConflictTooComplicatedError { return Err(ConflictResolveError::ConflictTooComplicatedError {