Skip to content

Commit

Permalink
feat: gix fetch --negotiation-info to provide additional informatio…
Browse files Browse the repository at this point in the history
…n about the negotiation phase.
  • Loading branch information
Byron committed Jun 12, 2023
1 parent 47c7b0d commit 096838f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gitoxide-core/src/repository/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub(crate) mod function {
let ref_specs = remote.refspecs(gix::remote::Direction::Fetch);
print_updates(
&repo,
negotiate,
&negotiate,
update_refs,
ref_specs,
fetch_outcome.ref_map,
Expand Down
48 changes: 37 additions & 11 deletions gitoxide-core/src/repository/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Options {
pub ref_specs: Vec<BString>,
pub shallow: gix::remote::fetch::Shallow,
pub handshake_info: bool,
pub negotiation_info: bool,
}

pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=3;
Expand All @@ -31,6 +32,7 @@ pub(crate) mod function {
dry_run,
remote,
handshake_info,
negotiation_info,
shallow,
ref_specs,
}: Options,
Expand Down Expand Up @@ -66,27 +68,37 @@ pub(crate) mod function {
update_refs,
negotiate,
dry_run: _,
} => print_updates(
&repo,
negotiate.unwrap_or_default(),
update_refs,
ref_specs,
res.ref_map,
&mut out,
err,
),
} => {
let negotiate_default = Default::default();
print_updates(
&repo,
negotiate.as_ref().unwrap_or(&negotiate_default),
update_refs,
ref_specs,
res.ref_map,
&mut out,
err,
)?;
if negotiation_info {
print_negotiate_info(&mut out, negotiate.as_ref())?;
}
Ok::<_, anyhow::Error>(())
}
Status::Change {
update_refs,
write_pack_bundle,
negotiate,
} => {
print_updates(&repo, negotiate, update_refs, ref_specs, res.ref_map, &mut out, err)?;
print_updates(&repo, &negotiate, update_refs, ref_specs, res.ref_map, &mut out, err)?;
if let Some(data_path) = write_pack_bundle.data_path {
writeln!(out, "pack file: \"{}\"", data_path.display()).ok();
}
if let Some(index_path) = write_pack_bundle.index_path {
writeln!(out, "index file: \"{}\"", index_path.display()).ok();
}
if negotiation_info {
print_negotiate_info(&mut out, Some(&negotiate))?;
}
Ok(())
}
}?;
Expand All @@ -96,9 +108,23 @@ pub(crate) mod function {
Ok(())
}

fn print_negotiate_info(
mut out: impl std::io::Write,
negotiate: Option<&gix::remote::fetch::outcome::Negotiate>,
) -> std::io::Result<()> {
writeln!(out, "Negotiation Phase Information")?;
match negotiate {
Some(negotiate) => {
writeln!(out, "\t{:?}", negotiate.rounds)?;
writeln!(out, "\tnum commits traversed in graph: {}", negotiate.graph.len())
}
None => writeln!(out, "\tno negotiation performed"),
}
}

pub(crate) fn print_updates(
repo: &gix::Repository,
negotiate: gix::remote::fetch::outcome::Negotiate,
negotiate: &gix::remote::fetch::outcome::Negotiate,
update_refs: gix::remote::fetch::refs::update::Outcome,
refspecs: &[gix::refspec::RefSpec],
mut map: gix::remote::fetch::RefMap,
Expand Down
2 changes: 2 additions & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ pub fn main() -> Result<()> {
Subcommands::Fetch(crate::plumbing::options::fetch::Platform {
dry_run,
handshake_info,
negotiation_info,
remote,
shallow,
ref_spec,
Expand All @@ -198,6 +199,7 @@ pub fn main() -> Result<()> {
dry_run,
remote,
handshake_info,
negotiation_info,
shallow: shallow.into(),
ref_specs: ref_spec,
};
Expand Down
4 changes: 4 additions & 0 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ pub mod fetch {
#[clap(long, short = 'H')]
pub handshake_info: bool,

/// Print statistics about negotiation phase.
#[clap(long, short = 's')]
pub negotiation_info: bool,

#[clap(flatten)]
pub shallow: ShallowOptions,

Expand Down

0 comments on commit 096838f

Please sign in to comment.