From 8c97fdf5d6493e670fecc7d946e530798c9e832d Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Mon, 17 Jan 2022 17:41:47 -0800 Subject: [PATCH] working_copy: remove `untrack()` now that we have more flexible `reset()` --- lib/src/working_copy.rs | 34 +----------------- lib/tests/test_working_copy.rs | 64 ---------------------------------- 2 files changed, 1 insertion(+), 97 deletions(-) diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index 340043264..0a93be9f0 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -38,7 +38,7 @@ use crate::commit::Commit; use crate::conflicts::{materialize_conflict, update_conflict_from_content}; use crate::gitignore::GitIgnoreFile; use crate::lock::FileLock; -use crate::matchers::{EverythingMatcher, Matcher}; +use crate::matchers::EverythingMatcher; use crate::repo_path::{RepoPath, RepoPathComponent, RepoPathJoin}; use crate::store::Store; use crate::tree::{Diff, Tree}; @@ -199,16 +199,6 @@ pub enum ResetError { InternalBackendError(BackendError), } -#[derive(Debug, Error, PartialEq, Eq)] -pub enum UntrackError { - // The current checkout was deleted, maybe by an overly aggressive GC that happened while - // the current process was running. - #[error("Current checkout not found")] - SourceNotFound, - #[error("Internal error: {0:?}")] - InternalBackendError(BackendError), -} - impl TreeState { pub fn current_tree_id(&self) -> &TreeId { &self.tree_id @@ -721,24 +711,6 @@ impl TreeState { self.tree_id = new_tree.id().clone(); Ok(()) } - - pub fn untrack(&mut self, matcher: &dyn Matcher) -> Result { - let tree = self - .store - .get_tree(&RepoPath::root(), &self.tree_id) - .map_err(|err| match err { - BackendError::NotFound => UntrackError::SourceNotFound, - other => UntrackError::InternalBackendError(other), - })?; - - let mut tree_builder = self.store.tree_builder(self.tree_id.clone()); - for (path, _value) in tree.entries_matching(matcher) { - self.file_states.remove(&path); - tree_builder.remove(path); - } - self.tree_id = tree_builder.write_tree(); - Ok(self.tree_id.clone()) - } } pub struct WorkingCopy { @@ -921,10 +893,6 @@ impl LockedWorkingCopy<'_> { self.wc.tree_state().as_mut().unwrap().reset(new_tree) } - pub fn untrack(&mut self, matcher: &dyn Matcher) -> Result { - self.wc.tree_state().as_mut().unwrap().untrack(matcher) - } - pub fn finish(mut self, commit_id: CommitId) { self.wc.tree_state().as_mut().unwrap().save(); self.wc.commit_id.replace(Some(commit_id)); diff --git a/lib/tests/test_working_copy.rs b/lib/tests/test_working_copy.rs index fa6ccaf7c..a60cafea0 100644 --- a/lib/tests/test_working_copy.rs +++ b/lib/tests/test_working_copy.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::collections::HashSet; use std::fs::{File, OpenOptions}; use std::io::{Read, Write}; #[cfg(unix)] @@ -22,7 +21,6 @@ use std::sync::Arc; use itertools::Itertools; use jujutsu_lib::backend::{Conflict, ConflictPart, TreeValue}; use jujutsu_lib::commit_builder::CommitBuilder; -use jujutsu_lib::matchers::FilesMatcher; use jujutsu_lib::repo::ReadonlyRepo; use jujutsu_lib::repo_path::{RepoPath, RepoPathComponent}; use jujutsu_lib::settings::UserSettings; @@ -371,68 +369,6 @@ fn test_reset() { locked_wc.discard(); } -#[test] -fn test_untrack() { - let settings = testutils::user_settings(); - let mut test_workspace = testutils::init_repo(&settings, false); - let repo = &test_workspace.repo; - let workspace_root = test_workspace.workspace.workspace_root().clone(); - - let wanted_path = RepoPath::from_internal_string("wanted"); - let unwanted_path = RepoPath::from_internal_string("unwanted"); - let gitignore_path = RepoPath::from_internal_string(".gitignore"); - - // First create a commit where one of the files is unwanted. - let initial_tree = testutils::create_tree( - repo, - &[ - (&wanted_path, "code"), - (&unwanted_path, "garbage"), - (&gitignore_path, "unwanted\n"), - ], - ); - let mut tx = repo.start_transaction("test"); - let initial_commit = CommitBuilder::for_open_commit( - &settings, - repo.store(), - repo.store().root_commit_id().clone(), - initial_tree.id().clone(), - ) - .write_to_repo(tx.mut_repo()); - let repo = tx.commit(); - let wc = test_workspace.workspace.working_copy_mut(); - wc.check_out(initial_commit.clone()).unwrap(); - - // Now we untrack the file called "unwanted" - let mut tx = repo.start_transaction("test"); - let matcher = FilesMatcher::new(HashSet::from([unwanted_path.clone()])); - let mut locked_wc = wc.start_mutation(); - let new_tree_id = locked_wc.untrack(&matcher).unwrap(); - let new_commit = CommitBuilder::for_rewrite_from(&settings, repo.store(), &initial_commit) - .set_tree(new_tree_id) - .write_to_repo(tx.mut_repo()); - locked_wc.finish(new_commit.id().clone()); - tx.commit(); - - // The file should still exist in the working copy. - assert!(unwanted_path.to_fs_path(&workspace_root).is_file()); - - // It should not be in the new tree. - let tracked_paths = new_commit - .tree() - .entries() - .map(|(path, _)| path) - .collect_vec(); - assert_eq!(tracked_paths, vec![gitignore_path, wanted_path]); - - // It should not get re-added if we write a new tree since we also added it - // to the .gitignore file. - let mut locked_wc = wc.start_mutation(); - let new_tree_id = locked_wc.write_tree(); - assert_eq!(new_tree_id, *new_commit.tree().id()); - locked_wc.discard(); -} - #[test_case(false ; "local backend")] #[test_case(true ; "git backend")] fn test_commit_racy_timestamps(use_git: bool) {