Skip to content

Commit

Permalink
refactor (#450)
Browse files Browse the repository at this point in the history
Prepare for `protocol` configuration.
  • Loading branch information
Byron committed Aug 22, 2022
1 parent df3cf18 commit e0be6e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
23 changes: 16 additions & 7 deletions gitoxide-core/src/repository/remote.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
#[cfg(any(feature = "blocking-client", feature = "async-client"))]
mod net {
use crate::OutputFormat;
use anyhow::{bail, Context};
use anyhow::bail;
use git_repository as git;
use git_repository::protocol::fetch;

pub mod refs {
use crate::OutputFormat;

pub struct Context {
pub format: OutputFormat,
pub name: Option<String>,
pub url: Option<git_repository::Url>,
}
}

#[git::protocol::maybe_async::maybe_async]
pub async fn refs(
pub async fn refs_fn(
repo: git::Repository,
name: Option<&str>,
url: Option<git::Url>,
format: OutputFormat,
mut progress: impl git::Progress,
out: impl std::io::Write,
refs::Context { format, name, url }: refs::Context,
) -> anyhow::Result<()> {
use anyhow::Context;
let remote = match (name, url) {
(Some(name), None) => repo.find_remote(name)?,
(Some(name), None) => repo.find_remote(&name)?,
(None, None) => repo
.head()?
.into_remote(git::remote::Direction::Fetch)
Expand Down Expand Up @@ -101,4 +110,4 @@ mod net {
}
}
#[cfg(any(feature = "blocking-client", feature = "async-client"))]
pub use net::refs;
pub use net::{refs, refs_fn as refs};
8 changes: 2 additions & 6 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,9 @@ pub fn main() -> Result<()> {
move |progress, out, _err| {
core::repository::remote::refs(
repository(Mode::Lenient)?,
name.as_deref(),
url,
format,
progress,
out,
core::repository::remote::refs::Context { name, url, format },
)
},
)
Expand All @@ -121,11 +119,9 @@ pub fn main() -> Result<()> {
async_util::prepare(verbose, "remote-refs", Some(core::remote::refs::PROGRESS_RANGE));
futures_lite::future::block_on(core::repository::remote::refs(
repository(Mode::Lenient)?,
name.as_deref(),
url,
format,
progress,
std::io::stdout(),
core::repository::remote::refs::Context { name, url, format },
))
}
}
Expand Down

0 comments on commit e0be6e9

Please sign in to comment.