From 6d9eb0ab86b9fb5612b81cb365561a20c8b7e30c Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 28 Jun 2024 20:40:34 +0100 Subject: [PATCH] refactor: remove dead code --- crates/git/src/repository/mod.rs | 34 ++++++++++--------------- crates/git/src/repository/open/mod.rs | 13 +--------- crates/git/src/repository/open/otest.rs | 18 ------------- crates/git/src/repository/open/tests.rs | 21 --------------- crates/git/src/repository/real.rs | 2 +- crates/git/src/repository/test.rs | 26 +++++-------------- crates/git/src/validation/positions.rs | 11 +++++++- 7 files changed, 31 insertions(+), 94 deletions(-) diff --git a/crates/git/src/repository/mod.rs b/crates/git/src/repository/mod.rs index 78f7711..c2ca874 100644 --- a/crates/git/src/repository/mod.rs +++ b/crates/git/src/repository/mod.rs @@ -34,20 +34,10 @@ pub enum Repository { Test(TestRepository), } -#[deprecated(note = "use git::repository::real()")] -pub const fn new() -> Repository { - Repository::Real -} - pub const fn test(fs: kxio::fs::FileSystem) -> TestRepository { - TestRepository::new(false, fs, vec![], vec![]) + TestRepository::new(fs, vec![], vec![]) } -// #[cfg(test)] -// pub const fn test_bare(fs: kxio::fs::FileSystem) -> TestRepository { -// TestRepository::new(true, fs, vec![], vec![]) -// } - /// Opens a repository, cloning if necessary #[tracing::instrument(skip_all)] #[cfg(not(tarpaulin_include))] // requires network access to either clone new and/or fetch. @@ -86,6 +76,8 @@ pub fn mock() -> Box { #[derive(Debug, Clone)] struct RealRepositoryFactory; + +#[cfg(not(tarpaulin_include))] // requires network access to either clone new and/or fetch. impl RepositoryFactory for RealRepositoryFactory { fn open(&self, gitdir: &GitDir) -> Result> { let gix_repo = gix::ThreadSafeRepository::open(gitdir.to_path_buf())?.to_thread_local(); @@ -115,16 +107,16 @@ pub trait RepositoryLike { fn open(&self, gitdir: &GitDir) -> Result; fn git_clone(&self, repo_details: &RepoDetails) -> Result; } -impl std::ops::Deref for Repository { - type Target = dyn RepositoryLike; - - fn deref(&self) -> &Self::Target { - match self { - Self::Real => &real::RealRepository, - Self::Test(test_repository) => test_repository, - } - } -} +// impl std::ops::Deref for Repository { +// type Target = dyn RepositoryLike; +// +// fn deref(&self) -> &Self::Target { +// match self { +// Self::Real => &real::RealRepository, +// Self::Test(test_repository) => test_repository, +// } +// } +// } #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum Direction { diff --git a/crates/git/src/repository/open/mod.rs b/crates/git/src/repository/open/mod.rs index fc63c96..fd5c9e2 100644 --- a/crates/git/src/repository/open/mod.rs +++ b/crates/git/src/repository/open/mod.rs @@ -1,10 +1,8 @@ // - #[cfg(test)] mod tests; pub mod oreal; - pub mod otest; #[cfg(test)] @@ -39,6 +37,7 @@ pub enum OpenRepository { Test(TestOpenRepository), } +#[cfg(not(tarpaulin_include))] pub fn real(gix_repo: gix::Repository) -> OpenRepository { OpenRepository::Real(oreal::RealOpenRepository::new(Arc::new(Mutex::new( gix_repo, @@ -55,16 +54,6 @@ pub fn test( OpenRepository::Test(TestOpenRepository::new(gitdir, fs, on_fetch, on_push)) } -#[cfg(not(tarpaulin_include))] // don't test mocks -pub fn test_bare( - gitdir: &config::GitDir, - fs: kxio::fs::FileSystem, - on_fetch: Vec, - on_push: Vec, -) -> OpenRepository { - OpenRepository::Test(TestOpenRepository::new_bare(gitdir, fs, on_fetch, on_push)) -} - #[mockall::automock] pub trait OpenRepositoryLike: std::fmt::Debug + Sync { fn duplicate(&self) -> Box; diff --git a/crates/git/src/repository/open/otest.rs b/crates/git/src/repository/open/otest.rs index e33d224..7fed767 100644 --- a/crates/git/src/repository/open/otest.rs +++ b/crates/git/src/repository/open/otest.rs @@ -156,24 +156,6 @@ impl TestOpenRepository { real: git::repository::RealOpenRepository::new(Arc::new(Mutex::new(gix))), } } - pub fn new_bare( - gitdir: &config::GitDir, - fs: kxio::fs::FileSystem, - on_fetch: Vec, - on_push: Vec, - ) -> Self { - let pathbuf = fs.base().join(gitdir.to_path_buf()); - #[allow(clippy::expect_used)] - let gix = gix::init_bare(pathbuf).expect("git init bare"); - Self::write_origin(gitdir, &fs); - Self { - on_fetch, - fetch_counter: Arc::new(RwLock::new(0)), - on_push, - push_counter: Arc::new(RwLock::new(0)), - real: git::repository::RealOpenRepository::new(Arc::new(Mutex::new(gix))), - } - } fn write_origin(gitdir: &config::GitDir, fs: &kxio::fs::FileSystem) { let config_file = fs.base().join(gitdir.to_path_buf()).join(".git/config"); diff --git a/crates/git/src/repository/open/tests.rs b/crates/git/src/repository/open/tests.rs index b9a331b..47ee376 100644 --- a/crates/git/src/repository/open/tests.rs +++ b/crates/git/src/repository/open/tests.rs @@ -287,27 +287,6 @@ mod forge_config { } } -// mod remote_branches { -// use super::*; -// #[test] -// // assumes running in the git-next repo which should have main, next and dev as remote branches -// fn should_return_remote_branches() -> TestResult { -// let_assert!(Ok(fs) = kxio::fs::temp()); -// let gitdir: config::GitDir = fs.base().to_path_buf().into(); -// let test_repository = git::repository::test(fs.clone()); -// let_assert!(Ok(open_repository) = test_repository.open(&gitdir)); -// let repo_config = &given::a_repo_config(); -// let branches = repo_config.branches(); -// then::create_a_commit_on_branch(&fs, &gitdir, &branches.main())?; -// then::create_a_commit_on_branch(&fs, &gitdir, &branches.next())?; -// then::create_a_commit_on_branch(&fs, &gitdir, &branches.dev())?; -// let_assert!(Ok(remote_branches) = open_repository.remote_branches()); -// assert!(remote_branches.contains(&branches.main())); -// assert!(remote_branches.contains(&branches.next())); -// assert!(remote_branches.contains(&branches.dev())); -// Ok(()) -// } -// } mod find_default_remote { use super::*; diff --git a/crates/git/src/repository/real.rs b/crates/git/src/repository/real.rs index f3109cb..788544d 100644 --- a/crates/git/src/repository/real.rs +++ b/crates/git/src/repository/real.rs @@ -1,4 +1,5 @@ // +#![cfg(not(tarpaulin_include))] use std::sync::atomic::AtomicBool; use crate as git; @@ -13,7 +14,6 @@ impl git::repository::RepositoryLike for RealRepository { } #[tracing::instrument(skip_all)] - #[cfg(not(tarpaulin_include))] // requires external server fn git_clone( &self, repo_details: &git::RepoDetails, diff --git a/crates/git/src/repository/test.rs b/crates/git/src/repository/test.rs index 7331f84..e9f0e5a 100644 --- a/crates/git/src/repository/test.rs +++ b/crates/git/src/repository/test.rs @@ -7,7 +7,6 @@ use git_next_config as config; #[derive(Clone, Debug, Constructor)] pub struct TestRepository { - is_bare: bool, fs: kxio::fs::FileSystem, on_fetch: Vec, on_push: Vec, @@ -20,28 +19,15 @@ impl TestRepository { pub fn on_push(&mut self, on_push: git::repository::OnPush) { self.on_push.push(on_push); } - - pub const fn fs(&self) -> &kxio::fs::FileSystem { - &self.fs - } } impl RepositoryLike for TestRepository { fn open(&self, gitdir: &config::GitDir) -> super::Result { - if self.is_bare { - Ok(git::repository::open::test_bare( - gitdir, - self.fs.clone(), - self.on_fetch.clone(), - self.on_push.clone(), - )) - } else { - Ok(git::repository::open::test( - gitdir, - self.fs.clone(), - self.on_fetch.clone(), - self.on_push.clone(), - )) - } + Ok(git::repository::open::test( + gitdir, + self.fs.clone(), + self.on_fetch.clone(), + self.on_push.clone(), + )) } fn git_clone( diff --git a/crates/git/src/validation/positions.rs b/crates/git/src/validation/positions.rs index 1a55959..6db32e7 100644 --- a/crates/git/src/validation/positions.rs +++ b/crates/git/src/validation/positions.rs @@ -51,7 +51,16 @@ pub fn validate_positions( }); } // verify that next is on main or at most one commit on top of main, else reset it back to main - if is_not_based_on(&commit_histories.next[0..=1], &main) { + if is_not_based_on( + commit_histories + .next + .iter() + .take(2) + .cloned() + .collect::>() + .as_slice(), + &main, + ) { tracing::info!("Main not on same commit as next, or it's parent - resetting next to main",); return reset_next_to_main(open_repository, repo_details, &main, &next, &next_branch); }