forked from mirrors/jj
repo_path: make RepoPath::from_internal_string() accept owned string
I'm going to add borrowed RepoPath type, and most from_internal_string() callers will be migrated to it. For the remaining callers, it makes more sense to move the ownership of String to RepoPathBuf.
This commit is contained in:
parent
d322df0c8d
commit
f5938985f0
5 changed files with 10 additions and 11 deletions
|
@ -181,11 +181,10 @@ impl RepoPath {
|
|||
///
|
||||
/// The input `value` must not contain empty path components. For example,
|
||||
/// `"/"`, `"/foo"`, `"foo/"`, `"foo//bar"` are all invalid.
|
||||
pub fn from_internal_string(value: &str) -> Self {
|
||||
assert!(is_valid_repo_path_str(value));
|
||||
RepoPath {
|
||||
value: value.to_owned(),
|
||||
}
|
||||
pub fn from_internal_string(value: impl Into<String>) -> Self {
|
||||
let value = value.into();
|
||||
assert!(is_valid_repo_path_str(&value));
|
||||
RepoPath { value }
|
||||
}
|
||||
|
||||
/// Converts repo-relative `Path` to `RepoPath`.
|
||||
|
|
|
@ -182,7 +182,7 @@ fn test_checkout_file_transitions(backend: TestRepoBackend) {
|
|||
let mut files = vec![];
|
||||
for left_kind in &kinds {
|
||||
for right_kind in &kinds {
|
||||
let path = RepoPath::from_internal_string(&format!("{left_kind:?}_{right_kind:?}"));
|
||||
let path = RepoPath::from_internal_string(format!("{left_kind:?}_{right_kind:?}"));
|
||||
write_path(&settings, repo, &mut left_tree_builder, *left_kind, &path);
|
||||
write_path(&settings, repo, &mut right_tree_builder, *right_kind, &path);
|
||||
files.push((*left_kind, *right_kind, path));
|
||||
|
|
|
@ -87,7 +87,7 @@ fn test_checkout_parallel() {
|
|||
let num_threads = max(num_cpus::get(), 4);
|
||||
let mut tree_ids = vec![];
|
||||
for i in 0..num_threads {
|
||||
let path = RepoPath::from_internal_string(format!("file{i}").as_str());
|
||||
let path = RepoPath::from_internal_string(format!("file{i}"));
|
||||
let tree = create_tree(repo, &[(&path, "contents")]);
|
||||
tree_ids.push(tree.id());
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ fn test_same_type() {
|
|||
|
||||
let write_tree = |index: usize| -> Tree {
|
||||
let mut tree_builder = store.tree_builder(store.empty_tree_id().clone());
|
||||
for path in &files {
|
||||
for &path in &files {
|
||||
let contents = &path[index..][..1];
|
||||
if contents != "_" {
|
||||
testutils::write_normal_file(
|
||||
|
@ -194,9 +194,9 @@ fn test_executable() {
|
|||
|
||||
let write_tree = |files: &[(&str, bool)]| -> Tree {
|
||||
let mut tree_builder = store.tree_builder(store.empty_tree_id().clone());
|
||||
for (path, executable) in files {
|
||||
for &(path, executable) in files {
|
||||
let repo_path = RepoPath::from_internal_string(path);
|
||||
if *executable {
|
||||
if executable {
|
||||
testutils::write_executable_file(&mut tree_builder, &repo_path, "contents");
|
||||
} else {
|
||||
testutils::write_normal_file(&mut tree_builder, &repo_path, "contents");
|
||||
|
|
|
@ -298,7 +298,7 @@ pub fn create_tree(repo: &Arc<ReadonlyRepo>, path_contents: &[(&RepoPath, &str)]
|
|||
#[must_use]
|
||||
pub fn create_random_tree(repo: &Arc<ReadonlyRepo>) -> MergedTreeId {
|
||||
let number = rand::random::<u32>();
|
||||
let path = RepoPath::from_internal_string(format!("file{number}").as_str());
|
||||
let path = RepoPath::from_internal_string(format!("file{number}"));
|
||||
create_tree(repo, &[(&path, "contents")]).id()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue