Skip to content

Commit eaa1b8f

Browse files
committed
feat: gix fetch --negotiation-info to provide additional information about the negotiation phase.
1 parent 68580d1 commit eaa1b8f

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

gitoxide-core/src/repository/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub(crate) mod function {
101101
let ref_specs = remote.refspecs(gix::remote::Direction::Fetch);
102102
print_updates(
103103
&repo,
104-
negotiate,
104+
&negotiate,
105105
update_refs,
106106
ref_specs,
107107
fetch_outcome.ref_map,

gitoxide-core/src/repository/fetch.rs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Options {
1010
pub ref_specs: Vec<BString>,
1111
pub shallow: gix::remote::fetch::Shallow,
1212
pub handshake_info: bool,
13+
pub negotiation_info: bool,
1314
}
1415

1516
pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=3;
@@ -31,6 +32,7 @@ pub(crate) mod function {
3132
dry_run,
3233
remote,
3334
handshake_info,
35+
negotiation_info,
3436
shallow,
3537
ref_specs,
3638
}: Options,
@@ -66,27 +68,37 @@ pub(crate) mod function {
6668
update_refs,
6769
negotiate,
6870
dry_run: _,
69-
} => print_updates(
70-
&repo,
71-
negotiate.unwrap_or_default(),
72-
update_refs,
73-
ref_specs,
74-
res.ref_map,
75-
&mut out,
76-
err,
77-
),
71+
} => {
72+
let negotiate_default = Default::default();
73+
print_updates(
74+
&repo,
75+
negotiate.as_ref().unwrap_or(&negotiate_default),
76+
update_refs,
77+
ref_specs,
78+
res.ref_map,
79+
&mut out,
80+
err,
81+
)?;
82+
if negotiation_info {
83+
print_negotiate_info(&mut out, negotiate.as_ref())?;
84+
}
85+
Ok::<_, anyhow::Error>(())
86+
}
7887
Status::Change {
7988
update_refs,
8089
write_pack_bundle,
8190
negotiate,
8291
} => {
83-
print_updates(&repo, negotiate, update_refs, ref_specs, res.ref_map, &mut out, err)?;
92+
print_updates(&repo, &negotiate, update_refs, ref_specs, res.ref_map, &mut out, err)?;
8493
if let Some(data_path) = write_pack_bundle.data_path {
8594
writeln!(out, "pack file: \"{}\"", data_path.display()).ok();
8695
}
8796
if let Some(index_path) = write_pack_bundle.index_path {
8897
writeln!(out, "index file: \"{}\"", index_path.display()).ok();
8998
}
99+
if negotiation_info {
100+
print_negotiate_info(&mut out, Some(&negotiate))?;
101+
}
90102
Ok(())
91103
}
92104
}?;
@@ -96,9 +108,23 @@ pub(crate) mod function {
96108
Ok(())
97109
}
98110

111+
fn print_negotiate_info(
112+
mut out: impl std::io::Write,
113+
negotiate: Option<&gix::remote::fetch::outcome::Negotiate>,
114+
) -> std::io::Result<()> {
115+
writeln!(out, "Negotiation Phase Information")?;
116+
match negotiate {
117+
Some(negotiate) => {
118+
writeln!(out, "\t{:?}", negotiate.rounds)?;
119+
writeln!(out, "\tnum commits traversed in graph: {}", negotiate.graph.len())
120+
}
121+
None => writeln!(out, "\tno negotiation performed"),
122+
}
123+
}
124+
99125
pub(crate) fn print_updates(
100126
repo: &gix::Repository,
101-
negotiate: gix::remote::fetch::outcome::Negotiate,
127+
negotiate: &gix::remote::fetch::outcome::Negotiate,
102128
update_refs: gix::remote::fetch::refs::update::Outcome,
103129
refspecs: &[gix::refspec::RefSpec],
104130
mut map: gix::remote::fetch::RefMap,

src/plumbing/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ pub fn main() -> Result<()> {
189189
Subcommands::Fetch(crate::plumbing::options::fetch::Platform {
190190
dry_run,
191191
handshake_info,
192+
negotiation_info,
192193
remote,
193194
shallow,
194195
ref_spec,
@@ -198,6 +199,7 @@ pub fn main() -> Result<()> {
198199
dry_run,
199200
remote,
200201
handshake_info,
202+
negotiation_info,
201203
shallow: shallow.into(),
202204
ref_specs: ref_spec,
203205
};

src/plumbing/options/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ pub mod fetch {
155155
#[clap(long, short = 'H')]
156156
pub handshake_info: bool,
157157

158+
/// Print statistics about negotiation phase.
159+
#[clap(long, short = 's')]
160+
pub negotiation_info: bool,
161+
158162
#[clap(flatten)]
159163
pub shallow: ShallowOptions,
160164

0 commit comments

Comments
 (0)