forked from mirrors/jj
repo_path: rename from() to from_internal_{,dir}_string()
Since `RepoPath` can be either a file or a directory, I made its name not include `file`.
This commit is contained in:
parent
ef726be78b
commit
c66990d3a3
13 changed files with 193 additions and 141 deletions
|
@ -391,7 +391,10 @@ impl Store for GitStore {
|
|||
}
|
||||
|
||||
fn read_conflict(&self, id: &ConflictId) -> StoreResult<Conflict> {
|
||||
let mut file = self.read_file(&RepoPath::from("unused"), &FileId(id.0.clone()))?;
|
||||
let mut file = self.read_file(
|
||||
&RepoPath::from_internal_string("unused"),
|
||||
&FileId(id.0.clone()),
|
||||
)?;
|
||||
let mut data = String::new();
|
||||
file.read_to_string(&mut data)?;
|
||||
let json: serde_json::Value = serde_json::from_str(&data).unwrap();
|
||||
|
@ -578,7 +581,7 @@ mod tests {
|
|||
|
||||
let dir_tree = store
|
||||
.read_tree(
|
||||
&DirRepoPath::from("dir/"),
|
||||
&DirRepoPath::from_internal_dir_string("dir/"),
|
||||
&TreeId(dir_tree_id.as_bytes().to_vec()),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
|
@ -172,7 +172,7 @@ mod tests {
|
|||
#[test]
|
||||
fn dirs_dir() {
|
||||
let mut dirs = Dirs::new();
|
||||
dirs.add_dir(DirRepoPath::from("dir/"));
|
||||
dirs.add_dir(DirRepoPath::from_internal_dir_string("dir/"));
|
||||
assert_eq!(
|
||||
dirs.get_dirs(&DirRepoPath::root()),
|
||||
&hashset! {DirRepoPathComponent::from("dir")}
|
||||
|
@ -182,7 +182,7 @@ mod tests {
|
|||
#[test]
|
||||
fn dirs_file() {
|
||||
let mut dirs = Dirs::new();
|
||||
dirs.add_file(&RepoPath::from("dir/file"));
|
||||
dirs.add_file(&RepoPath::from_internal_string("dir/file"));
|
||||
assert_eq!(
|
||||
dirs.get_dirs(&DirRepoPath::root()),
|
||||
&hashset! {DirRepoPathComponent::from("dir")}
|
||||
|
@ -193,8 +193,8 @@ mod tests {
|
|||
#[test]
|
||||
fn filesmatcher_empty() {
|
||||
let m = FilesMatcher::new(HashSet::new());
|
||||
assert!(!m.matches(&RepoPath::from("file")));
|
||||
assert!(!m.matches(&RepoPath::from("dir/file")));
|
||||
assert!(!m.matches(&RepoPath::from_internal_string("file")));
|
||||
assert!(!m.matches(&RepoPath::from_internal_string("dir/file")));
|
||||
assert_eq!(
|
||||
m.visit(&DirRepoPath::root()),
|
||||
Visit {
|
||||
|
@ -207,10 +207,10 @@ mod tests {
|
|||
#[test]
|
||||
fn filesmatcher_nonempty() {
|
||||
let m = FilesMatcher::new(hashset! {
|
||||
RepoPath::from("dir1/subdir1/file1"),
|
||||
RepoPath::from("dir1/subdir1/file2"),
|
||||
RepoPath::from("dir1/subdir2/file3"),
|
||||
RepoPath::from("file4"),
|
||||
RepoPath::from_internal_string("dir1/subdir1/file1"),
|
||||
RepoPath::from_internal_string("dir1/subdir1/file2"),
|
||||
RepoPath::from_internal_string("dir1/subdir2/file3"),
|
||||
RepoPath::from_internal_string("file4"),
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
|
@ -221,7 +221,7 @@ mod tests {
|
|||
}
|
||||
);
|
||||
assert_eq!(
|
||||
m.visit(&DirRepoPath::from("dir1/")),
|
||||
m.visit(&DirRepoPath::from_internal_dir_string("dir1/")),
|
||||
Visit {
|
||||
dirs: VisitDirs::Set(
|
||||
&hashset! {DirRepoPathComponent::from("subdir1"), DirRepoPathComponent::from("subdir2")}
|
||||
|
@ -230,7 +230,7 @@ mod tests {
|
|||
}
|
||||
);
|
||||
assert_eq!(
|
||||
m.visit(&DirRepoPath::from("dir1/subdir1/")),
|
||||
m.visit(&DirRepoPath::from_internal_dir_string("dir1/subdir1/")),
|
||||
Visit {
|
||||
dirs: VisitDirs::Set(&hashset! {}),
|
||||
files: VisitFiles::Set(
|
||||
|
@ -239,7 +239,7 @@ mod tests {
|
|||
}
|
||||
);
|
||||
assert_eq!(
|
||||
m.visit(&DirRepoPath::from("dir1/subdir2/")),
|
||||
m.visit(&DirRepoPath::from_internal_dir_string("dir1/subdir2/")),
|
||||
Visit {
|
||||
dirs: VisitDirs::Set(&hashset! {}),
|
||||
files: VisitFiles::Set(&hashset! {RepoPathComponent::from("file3")}),
|
||||
|
|
|
@ -82,6 +82,20 @@ impl RepoPath {
|
|||
RepoPath { dir, basename }
|
||||
}
|
||||
|
||||
pub fn from_internal_string(value: &str) -> Self {
|
||||
assert!(!value.ends_with('/'));
|
||||
match value.rfind('/') {
|
||||
None => RepoPath {
|
||||
dir: DirRepoPath::root(),
|
||||
basename: RepoPathComponent::from(value),
|
||||
},
|
||||
Some(i) => RepoPath {
|
||||
dir: DirRepoPath::from_internal_dir_string(&value[..=i]),
|
||||
basename: RepoPathComponent::from(&value[i + 1..]),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// The full string form used internally, not for presenting to users (where
|
||||
/// we may want to use the platform's separator).
|
||||
pub fn to_internal_file_string(&self) -> String {
|
||||
|
@ -127,22 +141,6 @@ impl RepoPath {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&str> for RepoPath {
|
||||
fn from(value: &str) -> Self {
|
||||
assert!(!value.ends_with('/'));
|
||||
match value.rfind('/') {
|
||||
None => RepoPath {
|
||||
dir: DirRepoPath::root(),
|
||||
basename: RepoPathComponent::from(value),
|
||||
},
|
||||
Some(i) => RepoPath {
|
||||
dir: DirRepoPath::from(&value[..=i]),
|
||||
basename: RepoPathComponent::from(&value[i + 1..]),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Includes a trailing slash
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct DirRepoPath {
|
||||
|
@ -164,6 +162,22 @@ impl DirRepoPath {
|
|||
return self.components().is_empty();
|
||||
}
|
||||
|
||||
pub fn from_internal_dir_string(value: &str) -> Self {
|
||||
assert!(value.is_empty() || value.ends_with('/'));
|
||||
let mut parts: Vec<&str> = value.split('/').collect();
|
||||
// remove the trailing empty string
|
||||
parts.pop();
|
||||
|
||||
DirRepoPath {
|
||||
value: parts
|
||||
.iter()
|
||||
.map(|x| DirRepoPathComponent {
|
||||
value: x.to_string(),
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The full string form used internally, not for presenting to users (where
|
||||
/// we may want to use the platform's separator).
|
||||
pub fn to_internal_dir_string(&self) -> String {
|
||||
|
@ -211,24 +225,6 @@ impl DirRepoPath {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<&str> for DirRepoPath {
|
||||
fn from(value: &str) -> Self {
|
||||
assert!(value.is_empty() || value.ends_with('/'));
|
||||
let mut parts: Vec<&str> = value.split('/').collect();
|
||||
// remove the trailing empty string
|
||||
parts.pop();
|
||||
|
||||
DirRepoPath {
|
||||
value: parts
|
||||
.iter()
|
||||
.map(|x| DirRepoPathComponent {
|
||||
value: x.to_string(),
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait RepoPathJoin<T> {
|
||||
type Result;
|
||||
|
||||
|
@ -263,43 +259,63 @@ mod tests {
|
|||
#[test]
|
||||
fn test_is_root() {
|
||||
assert!(RepoPath::root().is_root());
|
||||
assert!(RepoPath::from("").is_root());
|
||||
assert!(!RepoPath::from("foo").is_root());
|
||||
assert!(RepoPath::from_internal_string("").is_root());
|
||||
assert!(!RepoPath::from_internal_string("foo").is_root());
|
||||
assert!(DirRepoPath::root().is_root());
|
||||
assert!(DirRepoPath::from("").is_root());
|
||||
assert!(!DirRepoPath::from("foo/").is_root());
|
||||
assert!(DirRepoPath::from_internal_dir_string("").is_root());
|
||||
assert!(!DirRepoPath::from_internal_dir_string("foo/").is_root());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_value() {
|
||||
fn test_to_internal_string() {
|
||||
assert_eq!(RepoPath::root().to_internal_file_string(), "");
|
||||
assert_eq!(RepoPath::from("dir").to_internal_file_string(), "dir");
|
||||
assert_eq!(RepoPath::from("file").to_internal_file_string(), "file");
|
||||
assert_eq!(
|
||||
RepoPath::from("dir/file").to_internal_file_string(),
|
||||
RepoPath::from_internal_string("dir").to_internal_file_string(),
|
||||
"dir"
|
||||
);
|
||||
assert_eq!(
|
||||
RepoPath::from_internal_string("file").to_internal_file_string(),
|
||||
"file"
|
||||
);
|
||||
assert_eq!(
|
||||
RepoPath::from_internal_string("dir/file").to_internal_file_string(),
|
||||
"dir/file"
|
||||
);
|
||||
assert_eq!(DirRepoPath::root().to_internal_dir_string(), "");
|
||||
assert_eq!(DirRepoPath::from("dir/").to_internal_dir_string(), "dir/");
|
||||
assert_eq!(
|
||||
DirRepoPath::from("dir/subdir/").to_internal_dir_string(),
|
||||
DirRepoPath::from_internal_dir_string("dir/").to_internal_dir_string(),
|
||||
"dir/"
|
||||
);
|
||||
assert_eq!(
|
||||
DirRepoPath::from_internal_dir_string("dir/subdir/").to_internal_dir_string(),
|
||||
"dir/subdir/"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_order() {
|
||||
assert!(DirRepoPath::root() < DirRepoPath::from("dir/"));
|
||||
assert!(DirRepoPath::from("dir/") < DirRepoPath::from("dirx/"));
|
||||
assert!(DirRepoPath::root() < DirRepoPath::from_internal_dir_string("dir/"));
|
||||
assert!(
|
||||
DirRepoPath::from_internal_dir_string("dir/")
|
||||
< DirRepoPath::from_internal_dir_string("dirx/")
|
||||
);
|
||||
// '#' < '/'
|
||||
assert!(DirRepoPath::from("dir/") < DirRepoPath::from("dir#/"));
|
||||
assert!(DirRepoPath::from("dir/") < DirRepoPath::from("dir/sub/"));
|
||||
assert!(
|
||||
DirRepoPath::from_internal_dir_string("dir/")
|
||||
< DirRepoPath::from_internal_dir_string("dir#/")
|
||||
);
|
||||
assert!(
|
||||
DirRepoPath::from_internal_dir_string("dir/")
|
||||
< DirRepoPath::from_internal_dir_string("dir/sub/")
|
||||
);
|
||||
|
||||
assert!(RepoPath::from("abc") < RepoPath::from("dir/file"));
|
||||
assert!(RepoPath::from("dir") < RepoPath::from("dir/file"));
|
||||
assert!(RepoPath::from("dis") < RepoPath::from("dir/file"));
|
||||
assert!(RepoPath::from("xyz") < RepoPath::from("dir/file"));
|
||||
assert!(RepoPath::from("dir1/xyz") < RepoPath::from("dir2/abc"));
|
||||
assert!(RepoPath::from_internal_string("abc") < RepoPath::from_internal_string("dir/file"));
|
||||
assert!(RepoPath::from_internal_string("dir") < RepoPath::from_internal_string("dir/file"));
|
||||
assert!(RepoPath::from_internal_string("dis") < RepoPath::from_internal_string("dir/file"));
|
||||
assert!(RepoPath::from_internal_string("xyz") < RepoPath::from_internal_string("dir/file"));
|
||||
assert!(
|
||||
RepoPath::from_internal_string("dir1/xyz") < RepoPath::from_internal_string("dir2/abc")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -308,15 +324,21 @@ mod tests {
|
|||
let dir_component = DirRepoPathComponent::from("dir");
|
||||
let subdir_component = DirRepoPathComponent::from("subdir");
|
||||
let file_component = RepoPathComponent::from("file");
|
||||
assert_eq!(root.join(&file_component), RepoPath::from("file"));
|
||||
assert_eq!(
|
||||
root.join(&file_component),
|
||||
RepoPath::from_internal_string("file")
|
||||
);
|
||||
let dir = root.join(&dir_component);
|
||||
assert_eq!(dir, DirRepoPath::from("dir/"));
|
||||
assert_eq!(dir.join(&file_component), RepoPath::from("dir/file"));
|
||||
assert_eq!(dir, DirRepoPath::from_internal_dir_string("dir/"));
|
||||
assert_eq!(
|
||||
dir.join(&file_component),
|
||||
RepoPath::from_internal_string("dir/file")
|
||||
);
|
||||
let subdir = dir.join(&subdir_component);
|
||||
assert_eq!(subdir, DirRepoPath::from("dir/subdir/"));
|
||||
assert_eq!(subdir, DirRepoPath::from_internal_dir_string("dir/subdir/"));
|
||||
assert_eq!(
|
||||
subdir.join(&file_component),
|
||||
RepoPath::from("dir/subdir/file")
|
||||
RepoPath::from_internal_string("dir/subdir/file")
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -382,11 +404,11 @@ mod tests {
|
|||
fn test_components() {
|
||||
assert_eq!(DirRepoPath::root().components(), &vec![]);
|
||||
assert_eq!(
|
||||
DirRepoPath::from("dir/").components(),
|
||||
DirRepoPath::from_internal_dir_string("dir/").components(),
|
||||
&vec![DirRepoPathComponent::from("dir")]
|
||||
);
|
||||
assert_eq!(
|
||||
DirRepoPath::from("dir/subdir/").components(),
|
||||
DirRepoPath::from_internal_dir_string("dir/subdir/").components(),
|
||||
&vec![
|
||||
DirRepoPathComponent::from("dir"),
|
||||
DirRepoPathComponent::from("subdir")
|
||||
|
@ -397,20 +419,23 @@ mod tests {
|
|||
#[test]
|
||||
fn test_to_fs_path() {
|
||||
assert_eq!(
|
||||
RepoPath::from("").to_fs_path(&Path::new("base/dir")),
|
||||
RepoPath::from_internal_string("").to_fs_path(&Path::new("base/dir")),
|
||||
Path::new("base/dir")
|
||||
);
|
||||
assert_eq!(RepoPath::from("").to_fs_path(&Path::new("")), Path::new(""));
|
||||
assert_eq!(
|
||||
RepoPath::from("file").to_fs_path(&Path::new("base/dir")),
|
||||
RepoPath::from_internal_string("").to_fs_path(&Path::new("")),
|
||||
Path::new("")
|
||||
);
|
||||
assert_eq!(
|
||||
RepoPath::from_internal_string("file").to_fs_path(&Path::new("base/dir")),
|
||||
Path::new("base/dir/file")
|
||||
);
|
||||
assert_eq!(
|
||||
RepoPath::from("some/deep/dir/file").to_fs_path(&Path::new("base/dir")),
|
||||
RepoPath::from_internal_string("some/deep/dir/file").to_fs_path(&Path::new("base/dir")),
|
||||
Path::new("base/dir/some/deep/dir/file")
|
||||
);
|
||||
assert_eq!(
|
||||
RepoPath::from("dir/file").to_fs_path(&Path::new("")),
|
||||
RepoPath::from_internal_string("dir/file").to_fs_path(&Path::new("")),
|
||||
Path::new("dir/file")
|
||||
);
|
||||
}
|
||||
|
@ -419,12 +444,12 @@ mod tests {
|
|||
fn test_convert() {
|
||||
assert_eq!(RepoPath::root().to_dir_repo_path(), DirRepoPath::root());
|
||||
assert_eq!(
|
||||
RepoPath::from("dir").to_dir_repo_path(),
|
||||
DirRepoPath::from("dir/")
|
||||
RepoPath::from_internal_string("dir").to_dir_repo_path(),
|
||||
DirRepoPath::from_internal_dir_string("dir/")
|
||||
);
|
||||
assert_eq!(
|
||||
RepoPath::from("dir/subdir").to_dir_repo_path(),
|
||||
DirRepoPath::from("dir/subdir/")
|
||||
RepoPath::from_internal_string("dir/subdir").to_dir_repo_path(),
|
||||
DirRepoPath::from_internal_dir_string("dir/subdir/")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ pub fn create_random_tree(repo: &ReadonlyRepo) -> TreeId {
|
|||
.store()
|
||||
.tree_builder(repo.store().empty_tree_id().clone());
|
||||
let number = rand::random::<u32>();
|
||||
let path = RepoPath::from(format!("file{}", number).as_str());
|
||||
let path = RepoPath::from_internal_string(format!("file{}", number).as_str());
|
||||
write_normal_file(&mut tree_builder, &path, "contents");
|
||||
tree_builder.write_tree()
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ fn file_states_from_proto(
|
|||
) -> BTreeMap<RepoPath, FileState> {
|
||||
let mut file_states = BTreeMap::new();
|
||||
for (path_str, proto_file_state) in &proto.file_states {
|
||||
let path = RepoPath::from(path_str.as_str());
|
||||
let path = RepoPath::from_internal_string(path_str.as_str());
|
||||
file_states.insert(path, file_state_from_proto(&proto_file_state));
|
||||
}
|
||||
file_states
|
||||
|
|
|
@ -26,8 +26,8 @@ fn test_initial(use_git: bool) {
|
|||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
let store = repo.store();
|
||||
|
||||
let root_file_path = RepoPath::from("file");
|
||||
let dir_file_path = RepoPath::from("dir/file");
|
||||
let root_file_path = RepoPath::from_internal_string("file");
|
||||
let dir_file_path = RepoPath::from_internal_string("dir/file");
|
||||
let tree = testutils::create_tree(
|
||||
&repo,
|
||||
&[
|
||||
|
@ -65,8 +65,8 @@ fn test_rewrite(use_git: bool) {
|
|||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
let store = repo.store().clone();
|
||||
|
||||
let root_file_path = RepoPath::from("file");
|
||||
let dir_file_path = RepoPath::from("dir/file");
|
||||
let root_file_path = RepoPath::from_internal_string("file");
|
||||
let dir_file_path = RepoPath::from_internal_string("dir/file");
|
||||
let initial_tree = testutils::create_tree(
|
||||
&repo,
|
||||
&[
|
||||
|
|
|
@ -23,10 +23,10 @@ fn test_types(use_git: bool) {
|
|||
let settings = testutils::user_settings();
|
||||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
|
||||
let clean_path = RepoPath::from("clean");
|
||||
let modified_path = RepoPath::from("modified");
|
||||
let added_path = RepoPath::from("added");
|
||||
let removed_path = RepoPath::from("removed");
|
||||
let clean_path = RepoPath::from_internal_string("clean");
|
||||
let modified_path = RepoPath::from_internal_string("modified");
|
||||
let added_path = RepoPath::from_internal_string("added");
|
||||
let removed_path = RepoPath::from_internal_string("removed");
|
||||
|
||||
let tree1 = testutils::create_tree(
|
||||
&repo,
|
||||
|
@ -62,8 +62,8 @@ fn test_tree_file_transition(use_git: bool) {
|
|||
let settings = testutils::user_settings();
|
||||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
|
||||
let dir_file_path = RepoPath::from("dir/file");
|
||||
let dir_path = RepoPath::from("dir");
|
||||
let dir_file_path = RepoPath::from_internal_string("dir/file");
|
||||
let dir_path = RepoPath::from_internal_string("dir");
|
||||
|
||||
let tree1 = testutils::create_tree(&repo, &[(&dir_file_path, "contents")]);
|
||||
let tree2 = testutils::create_tree(&repo, &[(&dir_path, "contents")]);
|
||||
|
@ -92,15 +92,15 @@ fn test_sorting(use_git: bool) {
|
|||
let settings = testutils::user_settings();
|
||||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
|
||||
let a_path = RepoPath::from("a");
|
||||
let b_path = RepoPath::from("b");
|
||||
let f_a_path = RepoPath::from("f/a");
|
||||
let f_b_path = RepoPath::from("f/b");
|
||||
let f_f_a_path = RepoPath::from("f/f/a");
|
||||
let f_f_b_path = RepoPath::from("f/f/b");
|
||||
let n_path = RepoPath::from("n");
|
||||
let s_b_path = RepoPath::from("s/b");
|
||||
let z_path = RepoPath::from("z");
|
||||
let a_path = RepoPath::from_internal_string("a");
|
||||
let b_path = RepoPath::from_internal_string("b");
|
||||
let f_a_path = RepoPath::from_internal_string("f/a");
|
||||
let f_b_path = RepoPath::from_internal_string("f/b");
|
||||
let f_f_a_path = RepoPath::from_internal_string("f/f/a");
|
||||
let f_f_b_path = RepoPath::from_internal_string("f/f/b");
|
||||
let n_path = RepoPath::from_internal_string("n");
|
||||
let s_b_path = RepoPath::from_internal_string("s/b");
|
||||
let z_path = RepoPath::from_internal_string("z");
|
||||
|
||||
let tree1 = testutils::create_tree(
|
||||
&repo,
|
||||
|
|
|
@ -668,10 +668,10 @@ fn test_evolve_divergent(use_git: bool) {
|
|||
// commit 6 has a later commit time than commit 4). It should have files C,
|
||||
// X, Y, Z.
|
||||
|
||||
let path_a = RepoPath::from("A");
|
||||
let path_x = RepoPath::from("X");
|
||||
let path_y = RepoPath::from("Y");
|
||||
let path_z = RepoPath::from("Z");
|
||||
let path_a = RepoPath::from_internal_string("A");
|
||||
let path_x = RepoPath::from_internal_string("X");
|
||||
let path_y = RepoPath::from_internal_string("Y");
|
||||
let path_z = RepoPath::from_internal_string("Z");
|
||||
let tree1 = testutils::create_tree(&repo, &[(&path_a, "A")]);
|
||||
let tree2 = testutils::create_tree(&repo, &[(&path_a, "A"), (&path_x, "X")]);
|
||||
let tree3 = testutils::create_tree(&repo, &[(&path_a, "B")]);
|
||||
|
|
|
@ -52,7 +52,11 @@ fn test_same_type(use_git: bool) {
|
|||
for path in &files {
|
||||
let contents = &path[index..index + 1];
|
||||
if contents != "_" {
|
||||
testutils::write_normal_file(&mut tree_builder, &RepoPath::from(*path), contents);
|
||||
testutils::write_normal_file(
|
||||
&mut tree_builder,
|
||||
&RepoPath::from_internal_string(*path),
|
||||
contents,
|
||||
);
|
||||
}
|
||||
}
|
||||
let tree_id = tree_builder.write_tree();
|
||||
|
@ -182,7 +186,7 @@ fn test_subtrees(use_git: bool) {
|
|||
for path in paths {
|
||||
testutils::write_normal_file(
|
||||
&mut tree_builder,
|
||||
&RepoPath::from(path),
|
||||
&RepoPath::from_internal_string(path),
|
||||
&format!("contents of {:?}", path),
|
||||
);
|
||||
}
|
||||
|
@ -240,7 +244,7 @@ fn test_subtree_becomes_empty(use_git: bool) {
|
|||
for path in paths {
|
||||
testutils::write_normal_file(
|
||||
&mut tree_builder,
|
||||
&RepoPath::from(path),
|
||||
&RepoPath::from_internal_string(path),
|
||||
&format!("contents of {:?}", path),
|
||||
);
|
||||
}
|
||||
|
@ -274,32 +278,32 @@ fn test_types(use_git: bool) {
|
|||
let mut side2_tree_builder = store.tree_builder(store.empty_tree_id().clone());
|
||||
testutils::write_normal_file(
|
||||
&mut base_tree_builder,
|
||||
&RepoPath::from("normal_executable_symlink"),
|
||||
&RepoPath::from_internal_string("normal_executable_symlink"),
|
||||
"contents",
|
||||
);
|
||||
testutils::write_executable_file(
|
||||
&mut side1_tree_builder,
|
||||
&RepoPath::from("normal_executable_symlink"),
|
||||
&RepoPath::from_internal_string("normal_executable_symlink"),
|
||||
"contents",
|
||||
);
|
||||
testutils::write_symlink(
|
||||
&mut side2_tree_builder,
|
||||
&RepoPath::from("normal_executable_symlink"),
|
||||
&RepoPath::from_internal_string("normal_executable_symlink"),
|
||||
"contents",
|
||||
);
|
||||
let tree_id = store.empty_tree_id().clone();
|
||||
base_tree_builder.set(
|
||||
RepoPath::from("tree_normal_symlink"),
|
||||
RepoPath::from_internal_string("tree_normal_symlink"),
|
||||
TreeValue::Tree(tree_id),
|
||||
);
|
||||
testutils::write_normal_file(
|
||||
&mut side1_tree_builder,
|
||||
&RepoPath::from("tree_normal_symlink"),
|
||||
&RepoPath::from_internal_string("tree_normal_symlink"),
|
||||
"contents",
|
||||
);
|
||||
testutils::write_symlink(
|
||||
&mut side2_tree_builder,
|
||||
&RepoPath::from("tree_normal_symlink"),
|
||||
&RepoPath::from_internal_string("tree_normal_symlink"),
|
||||
"contents",
|
||||
);
|
||||
let base_tree_id = base_tree_builder.write_tree();
|
||||
|
@ -385,7 +389,10 @@ fn test_simplify_conflict(use_git: bool) {
|
|||
let store = repo.store();
|
||||
|
||||
let write_tree = |contents: &str| -> Tree {
|
||||
testutils::create_tree(&repo, &[(&RepoPath::from("file"), contents)])
|
||||
testutils::create_tree(
|
||||
&repo,
|
||||
&[(&RepoPath::from_internal_string("file"), contents)],
|
||||
)
|
||||
};
|
||||
|
||||
let base_tree = write_tree("base contents");
|
||||
|
|
|
@ -77,7 +77,7 @@ fn test_checkout_open_with_conflict(use_git: bool) {
|
|||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
let store = repo.store();
|
||||
|
||||
let file_path = RepoPath::from("file");
|
||||
let file_path = RepoPath::from_internal_string("file");
|
||||
let conflict_id = write_conflict(store, &file_path);
|
||||
let mut tree_builder = repo
|
||||
.store()
|
||||
|
@ -116,7 +116,7 @@ fn test_checkout_closed_with_conflict(use_git: bool) {
|
|||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
let store = repo.store();
|
||||
|
||||
let file_path = RepoPath::from("file");
|
||||
let file_path = RepoPath::from_internal_string("file");
|
||||
let conflict_id = write_conflict(store, &file_path);
|
||||
let mut tree_builder = repo
|
||||
.store()
|
||||
|
|
|
@ -85,16 +85,22 @@ fn test_checkout_file_transitions(use_git: bool) {
|
|||
return;
|
||||
}
|
||||
Kind::Normal => {
|
||||
let id =
|
||||
testutils::write_file(store, &RepoPath::from(path), "normal file contents");
|
||||
let id = testutils::write_file(
|
||||
store,
|
||||
&RepoPath::from_internal_string(path),
|
||||
"normal file contents",
|
||||
);
|
||||
TreeValue::Normal {
|
||||
id,
|
||||
executable: false,
|
||||
}
|
||||
}
|
||||
Kind::Executable => {
|
||||
let id =
|
||||
testutils::write_file(store, &RepoPath::from(path), "executable file contents");
|
||||
let id = testutils::write_file(
|
||||
store,
|
||||
&RepoPath::from_internal_string(path),
|
||||
"executable file contents",
|
||||
);
|
||||
TreeValue::Normal {
|
||||
id,
|
||||
executable: true,
|
||||
|
@ -102,7 +108,7 @@ fn test_checkout_file_transitions(use_git: bool) {
|
|||
}
|
||||
Kind::Symlink => {
|
||||
let id = store
|
||||
.write_symlink(&RepoPath::from(path), "target")
|
||||
.write_symlink(&RepoPath::from_internal_string(path), "target")
|
||||
.unwrap();
|
||||
TreeValue::Symlink(id)
|
||||
}
|
||||
|
@ -127,7 +133,7 @@ fn test_checkout_file_transitions(use_git: bool) {
|
|||
TreeValue::GitSubmodule(id)
|
||||
}
|
||||
};
|
||||
tree_builder.set(RepoPath::from(path), value);
|
||||
tree_builder.set(RepoPath::from_internal_string(path), value);
|
||||
}
|
||||
|
||||
let mut kinds = vec![
|
||||
|
@ -276,13 +282,13 @@ fn test_gitignores(use_git: bool) {
|
|||
let settings = testutils::user_settings();
|
||||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
|
||||
let gitignore_path = RepoPath::from(".gitignore");
|
||||
let added_path = RepoPath::from("added");
|
||||
let modified_path = RepoPath::from("modified");
|
||||
let removed_path = RepoPath::from("removed");
|
||||
let ignored_path = RepoPath::from("ignored");
|
||||
let subdir_modified_path = RepoPath::from("dir/modified");
|
||||
let subdir_ignored_path = RepoPath::from("dir/ignored");
|
||||
let gitignore_path = RepoPath::from_internal_string(".gitignore");
|
||||
let added_path = RepoPath::from_internal_string("added");
|
||||
let modified_path = RepoPath::from_internal_string("modified");
|
||||
let removed_path = RepoPath::from_internal_string("removed");
|
||||
let ignored_path = RepoPath::from_internal_string("ignored");
|
||||
let subdir_modified_path = RepoPath::from_internal_string("dir/modified");
|
||||
let subdir_ignored_path = RepoPath::from_internal_string("dir/ignored");
|
||||
|
||||
testutils::write_working_copy_file(&repo, &gitignore_path, "ignored\n");
|
||||
testutils::write_working_copy_file(&repo, &modified_path, "1");
|
||||
|
@ -344,9 +350,9 @@ fn test_gitignores_checkout_overwrites_ignored(use_git: bool) {
|
|||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
|
||||
// Write an ignored file called "modified" to disk
|
||||
let gitignore_path = RepoPath::from(".gitignore");
|
||||
let gitignore_path = RepoPath::from_internal_string(".gitignore");
|
||||
testutils::write_working_copy_file(&repo, &gitignore_path, "modified\n");
|
||||
let modified_path = RepoPath::from("modified");
|
||||
let modified_path = RepoPath::from_internal_string("modified");
|
||||
testutils::write_working_copy_file(&repo, &modified_path, "garbage");
|
||||
|
||||
// Create a commit that adds the same file but with different contents
|
||||
|
@ -391,9 +397,9 @@ fn test_gitignores_ignored_directory_already_tracked(use_git: bool) {
|
|||
let (_temp_dir, repo) = testutils::init_repo(&settings, use_git);
|
||||
|
||||
// Add a .gitignore file saying to ignore the directory "ignored/"
|
||||
let gitignore_path = RepoPath::from(".gitignore");
|
||||
let gitignore_path = RepoPath::from_internal_string(".gitignore");
|
||||
testutils::write_working_copy_file(&repo, &gitignore_path, "/ignored/\n");
|
||||
let file_path = RepoPath::from("ignored/file");
|
||||
let file_path = RepoPath::from_internal_string("ignored/file");
|
||||
|
||||
// Create a commit that adds a file in the ignored directory
|
||||
let mut tx = repo.start_transaction("test");
|
||||
|
|
|
@ -82,7 +82,11 @@ fn test_concurrent_commit(use_git: bool) {
|
|||
|
||||
// Commit from another process (simulated by another repo instance)
|
||||
let repo2 = ReadonlyRepo::load(&settings, repo1.working_copy_path().clone()).unwrap();
|
||||
testutils::write_working_copy_file(&repo2, &RepoPath::from("file2"), "contents2");
|
||||
testutils::write_working_copy_file(
|
||||
&repo2,
|
||||
&RepoPath::from_internal_string("file2"),
|
||||
"contents2",
|
||||
);
|
||||
let owned_wc2 = repo2.working_copy().clone();
|
||||
let wc2 = owned_wc2.lock().unwrap();
|
||||
let commit2 = wc2.commit(&settings, repo2).1;
|
||||
|
@ -91,7 +95,11 @@ fn test_concurrent_commit(use_git: bool) {
|
|||
|
||||
// Creating another commit (via the first repo instance) should result in a
|
||||
// successor of the commit created from the other process.
|
||||
testutils::write_working_copy_file(&repo1, &RepoPath::from("file3"), "contents3");
|
||||
testutils::write_working_copy_file(
|
||||
&repo1,
|
||||
&RepoPath::from_internal_string("file3"),
|
||||
"contents3",
|
||||
);
|
||||
let commit3 = wc1.commit(&settings, repo1).1;
|
||||
assert_eq!(commit3.predecessors(), vec![commit2]);
|
||||
}
|
||||
|
@ -108,7 +116,7 @@ fn test_checkout_parallel(use_git: bool) {
|
|||
let num_threads = max(num_cpus::get(), 4);
|
||||
let mut commit_ids = vec![];
|
||||
for i in 0..num_threads {
|
||||
let path = RepoPath::from(format!("file{}", i).as_str());
|
||||
let path = RepoPath::from_internal_string(format!("file{}", i).as_str());
|
||||
let tree = testutils::create_tree(&repo, &[(&path, "contents")]);
|
||||
let commit = CommitBuilder::for_new_commit(&settings, store, tree.id().clone())
|
||||
.set_open(true)
|
||||
|
@ -118,7 +126,10 @@ fn test_checkout_parallel(use_git: bool) {
|
|||
|
||||
// Create another commit just so we can test the update stats reliably from the
|
||||
// first update
|
||||
let tree = testutils::create_tree(&repo, &[(&RepoPath::from("other file"), "contents")]);
|
||||
let tree = testutils::create_tree(
|
||||
&repo,
|
||||
&[(&RepoPath::from_internal_string("other file"), "contents")],
|
||||
);
|
||||
let mut tx = repo.start_transaction("test");
|
||||
let commit = CommitBuilder::for_new_commit(&settings, store, tree.id().clone())
|
||||
.set_open(true)
|
||||
|
|
|
@ -1690,7 +1690,7 @@ fn cmd_restore(
|
|||
let paths = sub_matches.values_of("paths").unwrap();
|
||||
let mut tree_builder = repo.store().tree_builder(to_commit.tree().id().clone());
|
||||
for path in paths {
|
||||
let repo_path = RepoPath::from(path);
|
||||
let repo_path = RepoPath::from_internal_string(path);
|
||||
match from_commit.tree().path_value(&repo_path) {
|
||||
Some(value) => {
|
||||
tree_builder.set(repo_path, value);
|
||||
|
|
Loading…
Reference in a new issue