diff_util: unify handling of unexpected cases

This moves the error cases last in each `match` block, switches to
using format strings, and includes the full value in the message.
This commit is contained in:
Martin von Zweigbergk 2023-08-26 14:29:36 -07:00 committed by Martin von Zweigbergk
parent 6df7db3dc0
commit 5ef925deb8

View file

@ -352,12 +352,6 @@ fn diff_content(
let target = repo.store().read_symlink(path, id)?;
Ok(target.into_bytes())
}
TreeValue::Tree(_) => {
panic!(
"Got an unexpected tree in a diff of path {}",
path.to_internal_file_string()
);
}
TreeValue::GitSubmodule(id) => {
Ok(format!("Git submodule checked out at {}", id.hex()).into_bytes())
}
@ -367,6 +361,9 @@ fn diff_content(
conflicts::materialize(&conflict, repo.store(), path, &mut content).unwrap();
Ok(content)
}
TreeValue::Tree(_) => {
panic!("Unexpected {value:?} in diff at path {path:?}",);
}
}
}
@ -506,12 +503,6 @@ fn git_diff_part(
let target = repo.store().read_symlink(path, id)?;
content = target.into_bytes();
}
TreeValue::Tree(_) => {
panic!(
"Got an unexpected tree in a diff of path {}",
path.to_internal_file_string()
);
}
TreeValue::GitSubmodule(id) => {
// TODO: What should we actually do here?
mode = "040000".to_string();
@ -523,6 +514,9 @@ fn git_diff_part(
let conflict = repo.store().read_conflict(path, id).unwrap();
conflicts::materialize(&conflict, repo.store(), path, &mut content).unwrap();
}
TreeValue::Tree(_) => {
panic!("Unexpected {value:?} in diff at path {path:?}");
}
}
let hash = hash[0..10].to_string();
Ok(GitDiffPart {
@ -896,6 +890,6 @@ fn diff_summary_char(value: Option<&TreeValue>) -> char {
Some(TreeValue::Symlink(_)) => 'L',
Some(TreeValue::GitSubmodule(_)) => 'G',
Some(TreeValue::Conflict(_)) => 'C',
Some(TreeValue::Tree(_)) => panic!("unexpected tree entry in diff"),
Some(TreeValue::Tree(_)) => panic!("Unexpected {value:?} in diff"),
}
}