Skip to content

Commit

Permalink
Try to use maybe async for the simplest of possibly blocking remote i…
Browse files Browse the repository at this point in the history
…nteractions (#450)

It's probably OK to just do that for the sake of simplicity instead of
going all in the way it's done in `pack-receive`.
  • Loading branch information
Byron committed Aug 21, 2022
1 parent f8f1249 commit db4df25
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 20 deletions.
17 changes: 17 additions & 0 deletions gitoxide-core/src/repository/remote.rs
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
#[cfg(any(feature = "blocking-client", feature = "async-client"))]
mod net {
use crate::OutputFormat;
use git_repository as git;

#[git::protocol::maybe_async::maybe_async]
pub async fn refs(
_repo: git::Repository,
_name: &str,
_format: OutputFormat,
_progress: impl git::Progress,
_out: impl std::io::Write,
) -> anyhow::Result<()> {
todo!()
}
}
#[cfg(any(feature = "blocking-client", feature = "async-client"))]
pub use net::refs;
59 changes: 39 additions & 20 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ pub mod async_util {
verbose: bool,
name: &str,
range: impl Into<Option<ProgressRange>>,
) -> (Option<prodash::render::line::JoinHandle>, Option<prodash::tree::Item>) {
) -> (
Option<prodash::render::line::JoinHandle>,
git_features::progress::DoOrDiscard<prodash::tree::Item>,
) {
use crate::shared::{self, STANDARD_RANGE};
shared::init_env_logger();

if verbose {
let progress = shared::progress_tree();
let sub_progress = progress.add_child(name);
let ui_handle = shared::setup_line_renderer_range(&progress, range.into().unwrap_or(STANDARD_RANGE));
(Some(ui_handle), Some(sub_progress))
(Some(ui_handle), Some(sub_progress).into())
} else {
(None, None)
(None, None.into())
}
}
}
Expand Down Expand Up @@ -88,18 +91,35 @@ pub fn main() -> Result<()> {
})?;

match cmd {
Subcommands::Remote(remote::Platform { name: _, cmd }) => match cmd {
remote::Subcommands::Refs => prepare_and_run(
"config-list",
verbose,
progress,
progress_keep_open,
None,
move |_progress, _out, _err| {
Ok(())
// core::repository::remote::refs(repository(Mode::Lenient)?, name, format, out)
},
),
Subcommands::Remote(remote::Platform { name, cmd }) => match cmd {
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
remote::Subcommands::Refs => {
#[cfg(feature = "gitoxide-core-blocking-client")]
{
prepare_and_run(
"config-list",
verbose,
progress,
progress_keep_open,
None,
move |progress, out, _err| {
core::repository::remote::refs(repository(Mode::Lenient)?, &name, format, progress, out)
},
)
}
#[cfg(feature = "gitoxide-core-async-client")]
{
let (_handle, progress) =
async_util::prepare(verbose, "remote-ref-list", Some(core::remote::refs::PROGRESS_RANGE));
futures_lite::future::block_on(core::repository::remote::refs(
repository(Mode::Lenient)?,
&name,
format,
progress,
std::io::stdout(),
))
}
}
}
.map(|_| ()),
Subcommands::Config(config::Platform { filter }) => prepare_and_run(
Expand All @@ -118,17 +138,16 @@ pub fn main() -> Result<()> {
free::remote::Subcommands::RefList { protocol, url } => {
let (_handle, progress) =
async_util::prepare(verbose, "remote-ref-list", Some(core::remote::refs::PROGRESS_RANGE));
let fut = core::remote::refs::list(
futures_lite::future::block_on(core::remote::refs::list(
protocol,
&url,
git_features::progress::DoOrDiscard::from(progress),
progress,
core::remote::refs::Context {
thread_limit,
format,
out: std::io::stdout(),
},
);
return futures_lite::future::block_on(fut);
))
}
#[cfg(feature = "gitoxide-core-blocking-client")]
free::remote::Subcommands::RefList { protocol, url } => prepare_and_run(
Expand Down Expand Up @@ -313,7 +332,7 @@ pub fn main() -> Result<()> {
directory,
refs_directory,
refs.into_iter().map(|s| s.into()).collect(),
git_features::progress::DoOrDiscard::from(progress),
progress,
core::pack::receive::Context {
thread_limit,
format,
Expand Down
1 change: 1 addition & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub mod remote {
#[clap(visible_alias = "remotes")]
pub enum Subcommands {
/// Print all references available on the remote
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
Refs,
}
}
Expand Down

0 comments on commit db4df25

Please sign in to comment.