Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object_id: don't allow ObjectId::from_hex() a dynamically allocated string #2780

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/default_index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ mod tests {
let mut index = DefaultMutableIndex::full(3, 16);
// Long linear history with some short branches
let ids = (0..11)
.map(|n| CommitId::from_hex(&format!("{n:06x}")))
.map(|n| CommitId::try_from_hex(&format!("{n:06x}")).unwrap())
.collect_vec();
index.add_commit_data(ids[0].clone(), new_change_id(), &[]);
for i in 1..ids.len() {
Expand Down
5 changes: 3 additions & 2 deletions lib/src/object_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ macro_rules! impl_id_type {

/// Parses the given hex string into an ObjectId.
///
/// The given string is usually a literal, and must be valid.
pub fn from_hex(hex: &str) -> Self {
/// The given string must be valid. A static str is required to
/// prevent API misuse.
pub fn from_hex(hex: &'static str) -> Self {
Self::try_from_hex(hex).unwrap()
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/simple_op_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,12 @@ mod tests {

#[test]
fn test_migrate_git_refs_remote_named_git() {
let normal_ref_target = |id_hex: &str| RefTarget::normal(CommitId::from_hex(id_hex));
let normal_new_remote_ref = |id_hex: &str| RemoteRef {
let normal_ref_target = |id_hex| RefTarget::normal(CommitId::from_hex(id_hex));
let normal_new_remote_ref = |id_hex| RemoteRef {
target: normal_ref_target(id_hex),
state: RemoteRefState::New,
};
let normal_tracking_remote_ref = |id_hex: &str| RemoteRef {
let normal_tracking_remote_ref = |id_hex| RemoteRef {
target: normal_ref_target(id_hex),
state: RemoteRefState::Tracking,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/test_revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2792,7 +2792,7 @@ fn test_change_id_index() {

let root_commit = repo.store().root_commit();
let mut commit_number = 0;
let mut commit_with_change_id = |change_id: &str| {
let mut commit_with_change_id = |change_id| {
commit_number += 1;
tx.mut_repo()
.new_commit(
Expand Down