promote src/git/ files to src/

Signed-off-by: Han Xu <keepsimple@gmail.com>
This commit is contained in:
Han Xu
2023-01-05 19:19:14 -08:00
parent 575d44e8b4
commit 60596232da
30 changed files with 133 additions and 133 deletions
+1 -1
View File
@@ -26,7 +26,7 @@
use radicle_surf::{
fs::{self, Directory},
git::Repository,
Repository,
};
use std::{env, time::Instant};
+3 -3
View File
@@ -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);
@@ -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::<RefString>())))
} 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)]
+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -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;
@@ -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 {
@@ -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`.
+34 -2
View File
@@ -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;
+9 -12
View File
@@ -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<git::Commit> for Header {
fn from(commit: git::Commit) -> Self {
impl From<crate::Commit> for Header {
fn from(commit: crate::Commit) -> Self {
Self::from(&commit)
}
}
@@ -124,7 +121,7 @@ pub struct Commits {
/// The commit headers
pub headers: Vec<Header>,
/// 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<R: git::Revision>(repo: &Repository, rev: R) -> Result<Commit, Error> {
pub fn commit<R: Revision>(repo: &Repository, rev: R) -> Result<Commit, Error> {
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<Header, Error> {
/// fails.
pub fn commits<R>(repo: &Repository, revision: &R) -> Result<Commits, Error>
where
R: git::Revision,
R: Revision,
{
let stats = repo.stats_from(revision)?;
let commits = repo.history(revision)?.collect::<Result<Vec<_>, _>>()?;
@@ -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),
@@ -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::<RefString>()
}
@@ -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<dyn std::error::Error + Send + Sync + 'static>),
#[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<P, R>(&self, rev: &R, path: &P) -> Result<FileContent, crate::git::Error>
pub fn get_commit_file<P, R>(&self, rev: &R, path: &P) -> Result<FileContent, crate::Error>
where
P: AsRef<Path>,
R: Revision,
@@ -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<R: Revision> 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::<RefString>()
}
@@ -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)]
@@ -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]
@@ -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;
@@ -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! {
@@ -17,7 +17,9 @@ use radicle_surf::{
Moved,
Stats,
},
git::{Branch, Error, Repository},
Branch,
Error,
Repository,
};
use std::{path::Path, str::FromStr};
+2 -1
View File
@@ -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;
-27
View File
@@ -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;
@@ -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;
+31 -1
View File
@@ -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;
@@ -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;
@@ -1,5 +1,5 @@
use git_ref_format::refspec;
use radicle_surf::git::{Glob, Repository};
use radicle_surf::{Glob, Repository};
use super::GIT_PLATINUM;
@@ -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;
+1 -1
View File
@@ -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";
@@ -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();
@@ -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;