Skip to content

Commit

Permalink
diff_util: unify handling of unexpected cases
Browse files Browse the repository at this point in the history
This moves the error cases last in each `match` block, switches to
using format strings, and includes the full value in the message.
  • Loading branch information
martinvonz committed Aug 27, 2023
1 parent 6df7db3 commit 5ef925d
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions cli/src/diff_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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:?}",);
}
}
}

Expand Down Expand Up @@ -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();
Expand All @@ -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 {
Expand Down Expand Up @@ -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"),
}
}

0 comments on commit 5ef925d

Please sign in to comment.