diff --git a/radicle-surf/examples/browsing.rs b/radicle-surf/examples/browsing.rs index 5461c2a..faead9b 100644 --- a/radicle-surf/examples/browsing.rs +++ b/radicle-surf/examples/browsing.rs @@ -26,7 +26,7 @@ use radicle_surf::{ fs::{self, Directory}, - git::Repository, + Repository, }; use std::{env, time::Instant}; diff --git a/radicle-surf/examples/diff.rs b/radicle-surf/examples/diff.rs index a885804..c15f7b2 100644 --- a/radicle-surf/examples/diff.rs +++ b/radicle-surf/examples/diff.rs @@ -20,7 +20,7 @@ extern crate radicle_surf; use std::{env::Args, str::FromStr, time::Instant}; use radicle_git_ext::Oid; -use radicle_surf::{diff::Diff, git}; +use radicle_surf::{diff::Diff, Repository}; fn main() { let options = get_options_or_exit(); @@ -46,8 +46,8 @@ fn get_options_or_exit() -> Options { } } -fn init_repository_or_exit(path_to_repo: &str) -> git::Repository { - match git::Repository::open(path_to_repo) { +fn init_repository_or_exit(path_to_repo: &str) -> Repository { + match Repository::open(path_to_repo) { Ok(repo) => repo, Err(e) => { println!("Failed to create repository: {:?}", e); diff --git a/radicle-surf/src/git/branch.rs b/radicle-surf/src/branch.rs similarity index 98% rename from radicle-surf/src/git/branch.rs rename to radicle-surf/src/branch.rs index c6f3a65..25001ab 100644 --- a/radicle-surf/src/git/branch.rs +++ b/radicle-surf/src/branch.rs @@ -3,9 +3,10 @@ use std::{ str::{self, FromStr}, }; -use crate::git::refstr_join; use git_ref_format::{component, lit, Component, Qualified, RefStr, RefString}; +use crate::refs::refstr_join; + /// A `Branch` represents any git branch. This can either be a reference /// that is under the `refs/heads` or `refs/remotes` namespace. /// @@ -93,7 +94,7 @@ impl FromStr for Branch { } else if category == component::REMOTES { Ok(Self::Remote(Remote::new(c, cs.collect::()))) } else { - Err(error::Branch::NotBranch(name.into())) + Err(error::Branch::InvalidName(name.into())) } } } @@ -301,7 +302,7 @@ pub mod error { #[derive(Debug, Error)] pub enum Branch { #[error("the refname '{0}' did not begin with 'refs/heads' or 'refs/remotes'")] - NotBranch(RefString), + InvalidName(RefString), #[error("the refname '{0}' did not begin with 'refs/heads' or 'refs/remotes'")] NotQualified(String), #[error(transparent)] diff --git a/radicle-surf/src/git/commit.rs b/radicle-surf/src/commit.rs similarity index 100% rename from radicle-surf/src/git/commit.rs rename to radicle-surf/src/commit.rs diff --git a/radicle-surf/src/diff.rs b/radicle-surf/src/diff.rs index 802abc6..b315fc5 100644 --- a/radicle-surf/src/diff.rs +++ b/radicle-surf/src/diff.rs @@ -29,8 +29,8 @@ pub mod git; /// The serializable representation of a `git diff`. /// /// A [`Diff`] can be retrieved by the following functions: -/// * [`crate::git::Repository::diff`] -/// * [`crate::git::Repository::diff_commit`] +/// * [`crate::Repository::diff`] +/// * [`crate::Repository::diff_commit`] #[cfg_attr(feature = "serde", derive(Serialize), serde(rename_all = "camelCase"))] #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct Diff { diff --git a/radicle-surf/src/fs.rs b/radicle-surf/src/fs.rs index f930c07..c0020a6 100644 --- a/radicle-surf/src/fs.rs +++ b/radicle-surf/src/fs.rs @@ -31,7 +31,7 @@ use git2::Blob; use radicle_git_ext::{is_not_found_err, Oid}; use radicle_std_ext::result::ResultExt as _; -use crate::git::{Commit, Repository, Revision}; +use crate::{Commit, Repository, Revision}; pub mod error { use thiserror::Error; diff --git a/radicle-surf/src/git/glob.rs b/radicle-surf/src/glob.rs similarity index 99% rename from radicle-surf/src/git/glob.rs rename to radicle-surf/src/glob.rs index 9536cc8..c474e5a 100644 --- a/radicle-surf/src/git/glob.rs +++ b/radicle-surf/src/glob.rs @@ -26,7 +26,7 @@ use git_ref_format::{ }; use thiserror::Error; -use crate::git::{Branch, Local, Namespace, Remote, Tag}; +use crate::{Branch, Local, Namespace, Remote, Tag}; #[derive(Debug, Error)] pub enum Error { diff --git a/radicle-surf/src/git/history.rs b/radicle-surf/src/history.rs similarity index 98% rename from radicle-surf/src/git/history.rs rename to radicle-surf/src/history.rs index db23f9b..0f9befe 100644 --- a/radicle-surf/src/git/history.rs +++ b/radicle-surf/src/history.rs @@ -20,7 +20,7 @@ use std::{ path::{Path, PathBuf}, }; -use crate::git::{Commit, Error, Repository, ToCommit}; +use crate::{Commit, Error, Repository, ToCommit}; /// An iterator that produces the history of commits for a given `head`, /// in the `repo`. diff --git a/radicle-surf/src/lib.rs b/radicle-surf/src/lib.rs index d553770..7829974 100644 --- a/radicle-surf/src/lib.rs +++ b/radicle-surf/src/lib.rs @@ -20,7 +20,7 @@ //! of files and directories for any given revision. It also allows the user to //! diff any two different revisions. //! -//! The main entry point of the API is [git::Repository]. +//! The main entry point of the API is [Repository]. //! //! Let's start surfing! @@ -30,5 +30,37 @@ extern crate radicle_git_ext as git_ext; pub mod diff; pub mod fs; -pub mod git; pub mod object; + +// Re-export git2 as sub-module +pub use git2::{self, Error as Git2Error, Time}; +pub use radicle_git_ext::Oid; + +mod repo; +pub use repo::{Error, Repository}; + +mod glob; +pub use glob::Glob; + +mod history; +pub use history::History; + +mod branch; +pub use branch::{Branch, Local, Remote}; + +mod tag; +pub use tag::Tag; + +mod commit; +pub use commit::{Author, Commit}; + +mod namespace; +pub use namespace::Namespace; + +mod stats; +pub use stats::Stats; + +mod revision; +pub use revision::{Revision, Signature, ToCommit}; + +mod refs; diff --git a/radicle-surf/src/git/namespace.rs b/radicle-surf/src/namespace.rs similarity index 100% rename from radicle-surf/src/git/namespace.rs rename to radicle-surf/src/namespace.rs diff --git a/radicle-surf/src/object/commit.rs b/radicle-surf/src/object/commit.rs index 6082d70..1253ad3 100644 --- a/radicle-surf/src/object/commit.rs +++ b/radicle-surf/src/object/commit.rs @@ -26,10 +26,7 @@ use serde::{ Serialize, }; -use crate::{ - diff, - git::{self, glob, Glob, Repository}, -}; +use crate::{diff, glob, Glob, Repository, Revision}; use radicle_git_ext::Oid; @@ -76,8 +73,8 @@ impl Header { } } -impl From<&git::Commit> for Header { - fn from(commit: &git::Commit) -> Self { +impl From<&crate::Commit> for Header { + fn from(commit: &crate::Commit) -> Self { Self { sha1: commit.id, author: Person { @@ -95,8 +92,8 @@ impl From<&git::Commit> for Header { } } -impl From for Header { - fn from(commit: git::Commit) -> Self { +impl From for Header { + fn from(commit: crate::Commit) -> Self { Self::from(&commit) } } @@ -124,7 +121,7 @@ pub struct Commits { /// The commit headers pub headers: Vec
, /// The statistics for the commit headers - pub stats: git::Stats, + pub stats: crate::Stats, } /// Retrieves a [`Commit`]. @@ -133,7 +130,7 @@ pub struct Commits { /// /// Will return [`Error`] if the project doesn't exist or the surf interaction /// fails. -pub fn commit(repo: &Repository, rev: R) -> Result { +pub fn commit(repo: &Repository, rev: R) -> Result { let commit = repo.commit(rev)?; let sha1 = commit.id; let header = Header::from(&commit); @@ -171,7 +168,7 @@ pub fn header(repo: &Repository, sha1: Oid) -> Result { /// fails. pub fn commits(repo: &Repository, revision: &R) -> Result where - R: git::Revision, + R: Revision, { let stats = repo.stats_from(revision)?; let commits = repo.history(revision)?.collect::, _>>()?; @@ -184,7 +181,7 @@ where pub enum Error { /// An error occurred during a git operation. #[error(transparent)] - Git(#[from] git::Error), + Git(#[from] crate::Error), #[error(transparent)] Glob(#[from] glob::Error), diff --git a/radicle-surf/src/git/repo/iter.rs b/radicle-surf/src/refs.rs similarity index 95% rename from radicle-surf/src/git/repo/iter.rs rename to radicle-surf/src/refs.rs index 33ec758..2f9f9f8 100644 --- a/radicle-surf/src/git/repo/iter.rs +++ b/radicle-surf/src/refs.rs @@ -6,9 +6,9 @@ use std::{ convert::TryFrom as _, }; -use git_ref_format::{lit, Qualified, RefString}; +use git_ref_format::{lit, name::Components, Component, Qualified, RefString}; -use crate::git::{refstr_join, tag, Branch, Namespace, Tag}; +use crate::{tag, Branch, Namespace, Tag}; /// Iterator over [`Tag`]s. #[derive(Default)] @@ -210,7 +210,7 @@ pub mod error { use git_ref_format::RefString; use thiserror::Error; - use crate::git::{branch, tag}; + use crate::{branch, tag}; #[derive(Debug, Error)] pub enum Branch { @@ -240,3 +240,7 @@ pub mod error { Tag(#[from] tag::error::FromReference), } } + +pub(crate) fn refstr_join<'a>(c: Component<'a>, cs: Components<'a>) -> RefString { + std::iter::once(c).chain(cs).collect::() +} diff --git a/radicle-surf/src/git/repo.rs b/radicle-surf/src/repo.rs similarity index 97% rename from radicle-surf/src/git/repo.rs rename to radicle-surf/src/repo.rs index 730d1fd..dc70466 100644 --- a/radicle-surf/src/git/repo.rs +++ b/radicle-surf/src/repo.rs @@ -27,39 +27,33 @@ use radicle_git_ext::Oid; use thiserror::Error; use crate::{ + commit, diff::{self, *}, fs::{self, Directory, File, FileContent}, - git::{ - commit, - glob, - namespace, - Branch, - Commit, - Glob, - History, - Namespace, - Revision, - Signature, - Stats, - Tag, - ToCommit, - }, + glob, + namespace, object::{commit::Header, Blob, Tree, TreeEntry}, + refs::{self, BranchNames, Branches, Categories, Namespaces, TagNames, Tags}, + Branch, + Commit, + Glob, + History, + Namespace, + Revision, + Signature, + Stats, + Tag, + ToCommit, }; -pub mod iter; -pub use iter::{Branches, Categories, Namespaces, Tags}; - -use self::iter::{BranchNames, TagNames}; - -/// Enumeration of errors that can occur in operations from [`crate::git`]. +/// Enumeration of errors that can occur in repo operations. #[derive(Debug, Error)] #[non_exhaustive] pub enum Error { #[error(transparent)] - Branches(#[from] iter::error::Branch), + Branches(#[from] refs::error::Branch), #[error(transparent)] - Categories(#[from] iter::error::Category), + Categories(#[from] refs::error::Category), #[error(transparent)] Commit(#[from] commit::Error), /// An error that comes from performing a *diff* operations. @@ -95,7 +89,7 @@ pub enum Error { #[error(transparent)] ToCommit(Box), #[error(transparent)] - Tags(#[from] iter::error::Tag), + Tags(#[from] refs::error::Tag), } /// Wrapper around the `git2`'s `git2::Repository` type. @@ -365,7 +359,7 @@ impl Repository { // TODO(finto): I think this can be removed in favour of using // `source::Blob::new` /// Retrieves the file with `path` in this commit. - pub fn get_commit_file(&self, rev: &R, path: &P) -> Result + pub fn get_commit_file(&self, rev: &R, path: &P) -> Result where P: AsRef, R: Revision, diff --git a/radicle-surf/src/git.rs b/radicle-surf/src/revision.rs similarity index 85% rename from radicle-surf/src/git.rs rename to radicle-surf/src/revision.rs index b7ca64d..1dac0dc 100644 --- a/radicle-surf/src/git.rs +++ b/radicle-surf/src/revision.rs @@ -65,41 +65,10 @@ use std::{convert::Infallible, str::FromStr}; -// Re-export git2 as sub-module -pub use git2::{self, Error as Git2Error, Time}; -use git_ref_format::{name::Components, Component, Qualified, RefString}; -pub use radicle_git_ext::Oid; +use git_ref_format::{Qualified, RefString}; +use radicle_git_ext::Oid; -mod repo; -pub use repo::{Error, Repository}; - -pub mod glob; -pub use glob::Glob; - -mod history; -pub use history::History; - -/// Provides the data for talking about branches. -pub mod branch; -pub use branch::{Branch, Local, Remote}; - -/// Provides the data for talking about tags. -pub mod tag; -pub use tag::Tag; - -/// Provides the data for talking about commits. -pub mod commit; -pub use commit::{Author, Commit}; - -/// Provides the data for talking about namespaces. -pub mod namespace; -pub use namespace::Namespace; - -/// Provides the data for talking about repository statistics. -pub mod stats; -pub use stats::Stats; - -pub use crate::diff::Diff; +use crate::{Branch, Commit, Error, Repository, Tag}; /// The signature of a commit #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] @@ -217,7 +186,3 @@ impl ToCommit for R { Ok(Commit::try_from(commit)?) } } - -pub(crate) fn refstr_join<'a>(c: Component<'a>, cs: Components<'a>) -> RefString { - std::iter::once(c).chain(cs).collect::() -} diff --git a/radicle-surf/src/git/stats.rs b/radicle-surf/src/stats.rs similarity index 100% rename from radicle-surf/src/git/stats.rs rename to radicle-surf/src/stats.rs diff --git a/radicle-surf/src/git/tag.rs b/radicle-surf/src/tag.rs similarity index 99% rename from radicle-surf/src/git/tag.rs rename to radicle-surf/src/tag.rs index 274c750..c402b79 100644 --- a/radicle-surf/src/git/tag.rs +++ b/radicle-surf/src/tag.rs @@ -3,7 +3,7 @@ use std::{convert::TryFrom, str}; use git_ext::Oid; use git_ref_format::{component, lit, Qualified, RefStr, RefString}; -use crate::git::{refstr_join, Author}; +use crate::{refs::refstr_join, Author}; /// The static information of a [`git2::Tag`]. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] diff --git a/radicle-surf/t/src/git/branch.rs b/radicle-surf/t/src/branch.rs similarity index 96% rename from radicle-surf/t/src/git/branch.rs rename to radicle-surf/t/src/branch.rs index 28dd4f4..f1feef2 100644 --- a/radicle-surf/t/src/git/branch.rs +++ b/radicle-surf/t/src/branch.rs @@ -3,7 +3,7 @@ use git_ref_format_test::gen; use proptest::prelude::*; use test_helpers::roundtrip; -use radicle_surf::git::Branch; +use radicle_surf::Branch; proptest! { #[test] diff --git a/radicle-surf/t/src/git/code_browsing.rs b/radicle-surf/t/src/code_browsing.rs similarity index 98% rename from radicle-surf/t/src/git/code_browsing.rs rename to radicle-surf/t/src/code_browsing.rs index 3f06f64..60e1f23 100644 --- a/radicle-surf/t/src/git/code_browsing.rs +++ b/radicle-surf/t/src/code_browsing.rs @@ -3,7 +3,8 @@ use std::path::Path; use git_ref_format::refname; use radicle_surf::{ fs::{self, Directory}, - git::{Branch, Repository}, + Branch, + Repository, }; use super::GIT_PLATINUM; diff --git a/radicle-surf/t/src/git/commit.rs b/radicle-surf/t/src/commit.rs similarity index 95% rename from radicle-surf/t/src/git/commit.rs rename to radicle-surf/t/src/commit.rs index 5ad1bed..4519d77 100644 --- a/radicle-surf/t/src/git/commit.rs +++ b/radicle-surf/t/src/commit.rs @@ -2,7 +2,7 @@ use std::str::FromStr; use proptest::prelude::*; use radicle_git_ext::Oid; -use radicle_surf::git::{Author, Commit}; +use radicle_surf::{Author, Commit}; use test_helpers::roundtrip; proptest! { diff --git a/radicle-surf/t/src/git/diff.rs b/radicle-surf/t/src/diff.rs similarity index 99% rename from radicle-surf/t/src/git/diff.rs rename to radicle-surf/t/src/diff.rs index 4efe938..8c153cd 100644 --- a/radicle-surf/t/src/git/diff.rs +++ b/radicle-surf/t/src/diff.rs @@ -17,7 +17,9 @@ use radicle_surf::{ Moved, Stats, }, - git::{Branch, Error, Repository}, + Branch, + Error, + Repository, }; use std::{path::Path, str::FromStr}; diff --git a/radicle-surf/t/src/file_system.rs b/radicle-surf/t/src/file_system.rs index a0a8438..5a86c52 100644 --- a/radicle-surf/t/src/file_system.rs +++ b/radicle-surf/t/src/file_system.rs @@ -7,7 +7,8 @@ mod directory { use git_ref_format::refname; use radicle_surf::{ fs::{self, Entry}, - git::{Branch, Repository}, + Branch, + Repository, }; use std::path::Path; diff --git a/radicle-surf/t/src/git.rs b/radicle-surf/t/src/git.rs deleted file mode 100644 index 1c989d1..0000000 --- a/radicle-surf/t/src/git.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright © 2022 The Radicle Git Contributors -// SPDX-License-Identifier: GPL-3.0-or-later - -//! Unit tests for radicle_surf::git and its submodules. - -const GIT_PLATINUM: &str = "../data/git-platinum"; - -#[cfg(test)] -mod branch; -#[cfg(test)] -mod code_browsing; -#[cfg(test)] -mod commit; -#[cfg(test)] -mod diff; -#[cfg(test)] -mod last_commit; -#[cfg(test)] -mod namespace; -#[cfg(test)] -mod reference; -#[cfg(test)] -mod rev; -#[cfg(test)] -mod submodule; -#[cfg(test)] -mod threading; diff --git a/radicle-surf/t/src/git/last_commit.rs b/radicle-surf/t/src/last_commit.rs similarity index 98% rename from radicle-surf/t/src/git/last_commit.rs rename to radicle-surf/t/src/last_commit.rs index 22ee5e9..835b956 100644 --- a/radicle-surf/t/src/git/last_commit.rs +++ b/radicle-surf/t/src/last_commit.rs @@ -2,7 +2,7 @@ use std::{path::PathBuf, str::FromStr}; use git_ref_format::refname; use radicle_git_ext::Oid; -use radicle_surf::git::{Branch, Repository}; +use radicle_surf::{Branch, Repository}; use super::GIT_PLATINUM; diff --git a/radicle-surf/t/src/lib.rs b/radicle-surf/t/src/lib.rs index c46d568..e733003 100644 --- a/radicle-surf/t/src/lib.rs +++ b/radicle-surf/t/src/lib.rs @@ -2,10 +2,40 @@ // SPDX-License-Identifier: GPL-3.0-or-later #[cfg(test)] -mod git; +const GIT_PLATINUM: &str = "../data/git-platinum"; #[cfg(test)] mod file_system; #[cfg(test)] mod source; + +#[cfg(test)] +mod branch; + +#[cfg(test)] +mod code_browsing; + +#[cfg(test)] +mod commit; + +#[cfg(test)] +mod diff; + +#[cfg(test)] +mod last_commit; + +#[cfg(test)] +mod namespace; + +#[cfg(test)] +mod reference; + +#[cfg(test)] +mod rev; + +#[cfg(test)] +mod submodule; + +#[cfg(test)] +mod threading; diff --git a/radicle-surf/t/src/git/namespace.rs b/radicle-surf/t/src/namespace.rs similarity index 98% rename from radicle-surf/t/src/git/namespace.rs rename to radicle-surf/t/src/namespace.rs index 2fead75..0fb8969 100644 --- a/radicle-surf/t/src/git/namespace.rs +++ b/radicle-surf/t/src/namespace.rs @@ -1,6 +1,6 @@ use git_ref_format::{name::component, refname, refspec}; use pretty_assertions::{assert_eq, assert_ne}; -use radicle_surf::git::{Branch, Error, Glob, Repository}; +use radicle_surf::{Branch, Error, Glob, Repository}; use super::GIT_PLATINUM; diff --git a/radicle-surf/t/src/git/reference.rs b/radicle-surf/t/src/reference.rs similarity index 97% rename from radicle-surf/t/src/git/reference.rs rename to radicle-surf/t/src/reference.rs index 2a1b91a..c4dfcd4 100644 --- a/radicle-surf/t/src/git/reference.rs +++ b/radicle-surf/t/src/reference.rs @@ -1,5 +1,5 @@ use git_ref_format::refspec; -use radicle_surf::git::{Glob, Repository}; +use radicle_surf::{Glob, Repository}; use super::GIT_PLATINUM; diff --git a/radicle-surf/t/src/git/rev.rs b/radicle-surf/t/src/rev.rs similarity index 97% rename from radicle-surf/t/src/git/rev.rs rename to radicle-surf/t/src/rev.rs index 2b7d1b8..37d0bd3 100644 --- a/radicle-surf/t/src/git/rev.rs +++ b/radicle-surf/t/src/rev.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use git_ref_format::{name::component, refname}; -use radicle_surf::git::{Branch, Error, Oid, Repository}; +use radicle_surf::{Branch, Error, Oid, Repository}; use super::GIT_PLATINUM; diff --git a/radicle-surf/t/src/source.rs b/radicle-surf/t/src/source.rs index 7fb75e2..3380f23 100644 --- a/radicle-surf/t/src/source.rs +++ b/radicle-surf/t/src/source.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use git_ref_format::refname; -use radicle_surf::git::Repository; +use radicle_surf::Repository; use serde_json::json; const GIT_PLATINUM: &str = "../data/git-platinum"; diff --git a/radicle-surf/t/src/git/submodule.rs b/radicle-surf/t/src/submodule.rs similarity index 86% rename from radicle-surf/t/src/git/submodule.rs rename to radicle-surf/t/src/submodule.rs index d2a931b..5cfbbb7 100644 --- a/radicle-surf/t/src/git/submodule.rs +++ b/radicle-surf/t/src/submodule.rs @@ -3,7 +3,7 @@ // An issue with submodules, see: https://github.com/radicle-dev/radicle-surf/issues/54 fn test_submodule_failure() { use git_ref_format::refname; - use radicle_surf::git::{Branch, Repository}; + use radicle_surf::{Branch, Repository}; let repo = Repository::discover(".").unwrap(); repo.root_dir(Branch::local(refname!("main"))).unwrap(); diff --git a/radicle-surf/t/src/git/threading.rs b/radicle-surf/t/src/threading.rs similarity index 94% rename from radicle-surf/t/src/git/threading.rs rename to radicle-surf/t/src/threading.rs index 8392a92..cf8899f 100644 --- a/radicle-surf/t/src/git/threading.rs +++ b/radicle-surf/t/src/threading.rs @@ -1,7 +1,7 @@ use std::sync::{Mutex, MutexGuard}; use git_ref_format::{name::component, refname}; -use radicle_surf::git::{Branch, Error, Glob, Repository}; +use radicle_surf::{Branch, Error, Glob, Repository}; use super::GIT_PLATINUM;