Skip to content

Commit

Permalink
refactor (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 18, 2022
1 parent 4720666 commit 11851f3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
32 changes: 16 additions & 16 deletions gitoxide-core/src/repository/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ mod refs_impl {

pub enum Kind {
Remote,
Tracking { ref_specs: Vec<BString>, server_info: bool },
Tracking { ref_specs: Vec<BString> },
}

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

pub(crate) use super::print;
Expand All @@ -33,9 +34,14 @@ mod refs_impl {
repo: git::Repository,
kind: refs::Kind,
mut progress: impl git::Progress,
out: impl std::io::Write,
mut out: impl std::io::Write,
err: impl std::io::Write,
refs::Context { format, name, url }: refs::Context,
refs::Context {
format,
name,
url,
handshake_info,
}: refs::Context,
) -> anyhow::Result<()> {
use anyhow::Context;
let mut remote = match (name, url) {
Expand Down Expand Up @@ -68,15 +74,14 @@ mod refs_impl {
.ref_map()
.await?;

if handshake_info {
writeln!(out, "Handshake Information")?;
writeln!(out, "\t{:?}", map.handshake)?;
}
match kind {
refs::Kind::Tracking { server_info, .. } => print_refmap(
&repo,
remote.refspecs(git::remote::Direction::Fetch),
map,
server_info,
out,
err,
),
refs::Kind::Tracking { .. } => {
print_refmap(&repo, remote.refspecs(git::remote::Direction::Fetch), map, out, err)
}
refs::Kind::Remote => {
match format {
OutputFormat::Human => drop(print(out, &map.remote_refs)),
Expand All @@ -95,7 +100,6 @@ mod refs_impl {
repo: &git::Repository,
refspecs: &[RefSpec],
mut map: git::remote::fetch::RefMap<'_>,
server_info: bool,
mut out: impl std::io::Write,
mut err: impl std::io::Write,
) -> anyhow::Result<()> {
Expand Down Expand Up @@ -158,10 +162,6 @@ mod refs_impl {
}
}
}
if server_info {
writeln!(out, "Additional Information")?;
writeln!(out, "{:?}", map.handshake)?;
}
Ok(())
}

Expand Down
27 changes: 17 additions & 10 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,25 @@ pub fn main() -> Result<()> {
},
),
#[cfg_attr(feature = "small", allow(unused_variables))]
Subcommands::Remote(remote::Platform { name, url, cmd }) => match cmd {
Subcommands::Remote(remote::Platform {
name,
url,
cmd,
handshake_info,
}) => match cmd {
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
remote::Subcommands::Refs | remote::Subcommands::RefMap { .. } => {
let kind = match cmd {
remote::Subcommands::Refs => core::repository::remote::refs::Kind::Remote,
remote::Subcommands::RefMap {
ref_spec,
connection_info,
} => core::repository::remote::refs::Kind::Tracking {
ref_specs: ref_spec,
server_info: connection_info,
},
remote::Subcommands::RefMap { ref_spec } => {
core::repository::remote::refs::Kind::Tracking { ref_specs: ref_spec }
}
};
let context = core::repository::remote::refs::Context {
name,
url,
format,
handshake_info,
};
#[cfg(feature = "gitoxide-core-blocking-client")]
{
Expand All @@ -148,7 +155,7 @@ pub fn main() -> Result<()> {
progress,
out,
err,
core::repository::remote::refs::Context { name, url, format },
context,
)
},
)
Expand All @@ -166,7 +173,7 @@ pub fn main() -> Result<()> {
progress,
std::io::stdout(),
std::io::stderr(),
core::repository::remote::refs::Context { name, url, format },
context,
))
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ pub mod remote {
#[clap(long, short = 'u', conflicts_with("name"), parse(try_from_os_str = std::convert::TryFrom::try_from))]
pub url: Option<git::Url>,

/// Output additional typically information provided by the server as part of the connection handshake.
#[clap(long)]
pub handshake_info: bool,

/// Subcommands
#[clap(subcommand)]
pub cmd: Subcommands,
Expand All @@ -137,9 +141,6 @@ pub mod remote {
/// Print all references available on the remote as filtered through ref-specs.
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
RefMap {
/// Output additional typically internal information provided by the server.
#[clap(long)]
connection_info: bool,
/// Override the built-in and configured ref-specs with one or more of the given ones.
#[clap(parse(try_from_os_str = git::env::os_str_to_bstring))]
ref_spec: Vec<git_repository::bstr::BString>,
Expand Down

0 comments on commit 11851f3

Please sign in to comment.