Skip to content

Commit

Permalink
repo_path: split RepoPath into owned and borrowed types
Browse files Browse the repository at this point in the history
This enables cheap str-to-RepoPath cast, which is useful when sorting and
filtering a large Vec<(String, _)> list by using matcher for example. It
will also eliminate temporary allocation by repo_path.parent().
  • Loading branch information
yuja committed Nov 27, 2023
1 parent c13d261 commit dc7c15d
Show file tree
Hide file tree
Showing 23 changed files with 432 additions and 351 deletions.
2 changes: 1 addition & 1 deletion cli/src/commands/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ fn cmd_git_submodule_print_gitmodules(
let repo = workspace_command.repo();
let commit = workspace_command.resolve_single_rev(&args.revisions, ui)?;
let tree = commit.tree()?;
let gitmodules_path = &RepoPath::from_internal_string(".gitmodules");
let gitmodules_path = RepoPath::from_internal_string(".gitmodules");
let mut gitmodules_file = match tree.path_value(gitmodules_path).into_resolved() {
Ok(None) => {
writeln!(ui.stderr(), "No submodules!")?;
Expand Down
10 changes: 5 additions & 5 deletions cli/src/merge_tools/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,10 +558,10 @@ mod tests {
let test_repo = TestRepo::init();
let store = test_repo.repo.store();

let unused_path = &RepoPath::from_internal_string("unused");
let unchanged = &RepoPath::from_internal_string("unchanged");
let changed_path = &RepoPath::from_internal_string("changed");
let added_path = &RepoPath::from_internal_string("added");
let unused_path = RepoPath::from_internal_string("unused");
let unchanged = RepoPath::from_internal_string("unchanged");
let changed_path = RepoPath::from_internal_string("changed");
let added_path = RepoPath::from_internal_string("added");
let left_tree = testutils::create_tree(
&test_repo.repo,
&[
Expand Down Expand Up @@ -716,7 +716,7 @@ mod tests {
let test_repo = TestRepo::init();
let store = test_repo.repo.store();

let path = &RepoPath::from_internal_string("file");
let path = RepoPath::from_internal_string("file");
let base_tree = testutils::create_tree(
&test_repo.repo,
&[(path, "base 1\nbase 2\nbase 3\nbase 4\nbase 5\n")],
Expand Down
2 changes: 1 addition & 1 deletion lib/src/default_revset_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ fn has_diff_from_parent(
if let [parent] = parents.as_slice() {
// Fast path: no need to load the root tree
let unchanged = commit.tree_id() == parent.tree_id();
if matcher.visit(&RepoPath::root()) == Visit::AllRecursively {
if matcher.visit(RepoPath::root()) == Visit::AllRecursively {
return !unchanged;
} else if unchanged {
return false;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/git_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ mod tests {

let root_tree = backend
.read_tree(
&RepoPath::root(),
RepoPath::root(),
&TreeId::from_bytes(root_tree_id.as_bytes()),
)
.block_on()
Expand All @@ -1248,7 +1248,7 @@ mod tests {

let dir_tree = backend
.read_tree(
&RepoPath::from_internal_string("dir"),
RepoPath::from_internal_string("dir"),
&TreeId::from_bytes(dir_tree_id.as_bytes()),
)
.block_on()
Expand Down
2 changes: 1 addition & 1 deletion lib/src/local_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl LocalBackend {
fs::create_dir(store_path.join("conflicts")).unwrap();
let backend = Self::load(store_path);
let empty_tree_id = backend
.write_tree(&RepoPath::root(), &Tree::default())
.write_tree(RepoPath::root(), &Tree::default())
.unwrap();
assert_eq!(empty_tree_id, backend.empty_tree_id);
backend
Expand Down
4 changes: 2 additions & 2 deletions lib/src/local_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ impl TreeState {
};

let matcher = IntersectionMatcher::new(sparse_matcher.as_ref(), fsmonitor_matcher);
if matcher.visit(&RepoPath::root()).is_nothing() {
if matcher.visit(RepoPath::root()).is_nothing() {
// No need to load file states
self.watchman_clock = watchman_clock;
return Ok(is_dirty);
Expand Down Expand Up @@ -796,7 +796,7 @@ impl TreeState {
// If the whole directory is ignored, visit only paths we're already
// tracking.
let tracked_paths = file_states
.range((Bound::Excluded(&path), Bound::Unbounded))
.range::<RepoPath, _>((Bound::Excluded(&*path), Bound::Unbounded))
.take_while(|(sub_path, _)| path.contains(sub_path))
.map(|(sub_path, file_state)| (sub_path.clone(), file_state.clone()))
.collect_vec();
Expand Down
Loading

0 comments on commit dc7c15d

Please sign in to comment.