Skip to content

Commit 11851f3

Browse files
committed
refactor (#450)
1 parent 4720666 commit 11851f3

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

gitoxide-core/src/repository/remote.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ mod refs_impl {
1616

1717
pub enum Kind {
1818
Remote,
19-
Tracking { ref_specs: Vec<BString>, server_info: bool },
19+
Tracking { ref_specs: Vec<BString> },
2020
}
2121

2222
pub struct Context {
2323
pub format: OutputFormat,
2424
pub name: Option<String>,
2525
pub url: Option<git_repository::Url>,
26+
pub handshake_info: bool,
2627
}
2728

2829
pub(crate) use super::print;
@@ -33,9 +34,14 @@ mod refs_impl {
3334
repo: git::Repository,
3435
kind: refs::Kind,
3536
mut progress: impl git::Progress,
36-
out: impl std::io::Write,
37+
mut out: impl std::io::Write,
3738
err: impl std::io::Write,
38-
refs::Context { format, name, url }: refs::Context,
39+
refs::Context {
40+
format,
41+
name,
42+
url,
43+
handshake_info,
44+
}: refs::Context,
3945
) -> anyhow::Result<()> {
4046
use anyhow::Context;
4147
let mut remote = match (name, url) {
@@ -68,15 +74,14 @@ mod refs_impl {
6874
.ref_map()
6975
.await?;
7076

77+
if handshake_info {
78+
writeln!(out, "Handshake Information")?;
79+
writeln!(out, "\t{:?}", map.handshake)?;
80+
}
7181
match kind {
72-
refs::Kind::Tracking { server_info, .. } => print_refmap(
73-
&repo,
74-
remote.refspecs(git::remote::Direction::Fetch),
75-
map,
76-
server_info,
77-
out,
78-
err,
79-
),
82+
refs::Kind::Tracking { .. } => {
83+
print_refmap(&repo, remote.refspecs(git::remote::Direction::Fetch), map, out, err)
84+
}
8085
refs::Kind::Remote => {
8186
match format {
8287
OutputFormat::Human => drop(print(out, &map.remote_refs)),
@@ -95,7 +100,6 @@ mod refs_impl {
95100
repo: &git::Repository,
96101
refspecs: &[RefSpec],
97102
mut map: git::remote::fetch::RefMap<'_>,
98-
server_info: bool,
99103
mut out: impl std::io::Write,
100104
mut err: impl std::io::Write,
101105
) -> anyhow::Result<()> {
@@ -158,10 +162,6 @@ mod refs_impl {
158162
}
159163
}
160164
}
161-
if server_info {
162-
writeln!(out, "Additional Information")?;
163-
writeln!(out, "{:?}", map.handshake)?;
164-
}
165165
Ok(())
166166
}
167167

src/plumbing/main.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,25 @@ pub fn main() -> Result<()> {
120120
},
121121
),
122122
#[cfg_attr(feature = "small", allow(unused_variables))]
123-
Subcommands::Remote(remote::Platform { name, url, cmd }) => match cmd {
123+
Subcommands::Remote(remote::Platform {
124+
name,
125+
url,
126+
cmd,
127+
handshake_info,
128+
}) => match cmd {
124129
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
125130
remote::Subcommands::Refs | remote::Subcommands::RefMap { .. } => {
126131
let kind = match cmd {
127132
remote::Subcommands::Refs => core::repository::remote::refs::Kind::Remote,
128-
remote::Subcommands::RefMap {
129-
ref_spec,
130-
connection_info,
131-
} => core::repository::remote::refs::Kind::Tracking {
132-
ref_specs: ref_spec,
133-
server_info: connection_info,
134-
},
133+
remote::Subcommands::RefMap { ref_spec } => {
134+
core::repository::remote::refs::Kind::Tracking { ref_specs: ref_spec }
135+
}
136+
};
137+
let context = core::repository::remote::refs::Context {
138+
name,
139+
url,
140+
format,
141+
handshake_info,
135142
};
136143
#[cfg(feature = "gitoxide-core-blocking-client")]
137144
{
@@ -148,7 +155,7 @@ pub fn main() -> Result<()> {
148155
progress,
149156
out,
150157
err,
151-
core::repository::remote::refs::Context { name, url, format },
158+
context,
152159
)
153160
},
154161
)
@@ -166,7 +173,7 @@ pub fn main() -> Result<()> {
166173
progress,
167174
std::io::stdout(),
168175
std::io::stderr(),
169-
core::repository::remote::refs::Context { name, url, format },
176+
context,
170177
))
171178
}
172179
}

src/plumbing/options.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ pub mod remote {
123123
#[clap(long, short = 'u', conflicts_with("name"), parse(try_from_os_str = std::convert::TryFrom::try_from))]
124124
pub url: Option<git::Url>,
125125

126+
/// Output additional typically information provided by the server as part of the connection handshake.
127+
#[clap(long)]
128+
pub handshake_info: bool,
129+
126130
/// Subcommands
127131
#[clap(subcommand)]
128132
pub cmd: Subcommands,
@@ -137,9 +141,6 @@ pub mod remote {
137141
/// Print all references available on the remote as filtered through ref-specs.
138142
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
139143
RefMap {
140-
/// Output additional typically internal information provided by the server.
141-
#[clap(long)]
142-
connection_info: bool,
143144
/// Override the built-in and configured ref-specs with one or more of the given ones.
144145
#[clap(parse(try_from_os_str = git::env::os_str_to_bstring))]
145146
ref_spec: Vec<git_repository::bstr::BString>,

0 commit comments

Comments
 (0)