Skip to content

Commit 7b267b6

Browse files
committed
squash me
1 parent f1afc38 commit 7b267b6

File tree

5 files changed

+174
-292
lines changed

5 files changed

+174
-292
lines changed

gix-protocol/src/fetch/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub enum Error {
3333
},
3434
#[error("Failed to consume the pack sent by the remove")]
3535
ConsumePack(Box<dyn std::error::Error + Send + Sync + 'static>),
36+
#[error("Failed to read remaining bytes in stream")]
37+
ReadRemainingBytes(#[source] std::io::Error),
3638
}
3739

3840
impl crate::transport::IsSpuriousError for Error {

gix-protocol/src/fetch/function.rs

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::{fetch::Arguments, transport::packetline::read::ProgressAction};
2-
use std::path::Path;
3-
use std::sync::atomic::{AtomicBool, Ordering};
4-
51
use crate::fetch::{
62
negotiate, Context, Error, Negotiate, NegotiateOutcome, Options, Outcome, ProgressId, RefMap, Shallow, Tags,
73
};
4+
use crate::{fetch::Arguments, transport::packetline::read::ProgressAction};
5+
use gix_features::progress::DynNestedProgress;
6+
use std::path::Path;
7+
use std::sync::atomic::{AtomicBool, Ordering};
88

99
/// Perform one fetch operation, relying on a `transport`, right after a [`ref_map`](RefMap::new()) was created so
1010
/// it's clear what the remote has.
@@ -32,7 +32,7 @@ use crate::fetch::{
3232
pub async fn fetch<P, T, E>(
3333
ref_map: &RefMap,
3434
negotiate: &mut impl Negotiate,
35-
consume_pack: impl FnOnce(&mut dyn std::io::BufRead, &mut P, &AtomicBool) -> Result<(), E>,
35+
consume_pack: impl FnOnce(&mut dyn std::io::BufRead, &mut dyn DynNestedProgress, &AtomicBool) -> Result<(), E>,
3636
mut progress: P,
3737
should_interrupt: &AtomicBool,
3838
Context {
@@ -114,7 +114,7 @@ where
114114
let mut rounds = Vec::new();
115115
let is_stateless = arguments.is_stateless(!transport.connection_persists_across_multiple_requests());
116116
let mut state = negotiate::one_round::State::new(is_stateless);
117-
let reader = 'negotiation: loop {
117+
let mut reader = 'negotiation: loop {
118118
let _round = gix_trace::detail!("negotiate round", round = rounds.len() + 1);
119119
progress.step();
120120
progress.set_name(format!("negotiate (round {})", rounds.len() + 1));
@@ -157,11 +157,37 @@ where
157157
}
158158

159159
#[cfg(feature = "async-client")]
160-
let mut reader = crate::futures_lite::io::BlockOn::new(reader);
160+
let mut rd = crate::futures_lite::io::BlockOn::new(reader);
161+
#[cfg(not(feature = "async-client"))]
162+
let mut rd = reader;
163+
consume_pack(&mut rd, &mut progress, should_interrupt).map_err(|err| Error::ConsumePack(err.into()))?;
164+
#[cfg(feature = "async-client")]
165+
{
166+
reader = rd.into_inner();
167+
}
161168
#[cfg(not(feature = "async-client"))]
162-
let mut reader = reader;
163-
consume_pack(&mut reader, &mut progress, should_interrupt).map_err(|err| Error::ConsumePack(err.into()))?;
169+
{
170+
reader = rd;
171+
}
172+
173+
// Assure the final flush packet is consumed.
174+
let has_read_to_end = reader.stopped_at().is_some();
175+
#[cfg(feature = "async-client")]
176+
{
177+
if !has_read_to_end {
178+
futures_lite::io::copy(&mut reader, &mut futures_lite::io::sink())
179+
.await
180+
.map_err(Error::ReadRemainingBytes)?;
181+
}
182+
}
183+
#[cfg(not(feature = "async-client"))]
184+
{
185+
if !has_read_to_end {
186+
std::io::copy(&mut reader, &mut std::io::sink()).map_err(Error::ReadRemainingBytes)?;
187+
}
188+
}
164189
drop(reader);
190+
165191
if let Some(shallow_lock) = shallow_lock {
166192
if !previous_response.shallow_updates().is_empty() {
167193
gix_shallow::write(shallow_lock, shallow_commits, previous_response.shallow_updates())?;

gix/src/remote/connection/fetch/error.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use crate::config;
22

33
/// The error returned by [`receive()`](super::Prepare::receive()).
4+
// TODO: remove unused variants
45
#[derive(Debug, thiserror::Error)]
56
#[allow(missing_docs)]
67
pub enum Error {
8+
#[error(transparent)]
9+
Fetch(#[from] gix_protocol::fetch::Error),
710
#[error("The value to configure pack threads should be 0 to auto-configure or the amount of threads to use")]
811
PackThreads(#[from] config::unsigned_integer::Error),
912
#[error("The value to configure the pack index version should be 1 or 2")]
@@ -49,11 +52,6 @@ pub enum Error {
4952
NegotiationAlgorithmConfig(#[from] config::key::GenericErrorWithValue),
5053
#[error("Failed to read remaining bytes in stream")]
5154
ReadRemainingBytes(#[source] std::io::Error),
52-
#[error("None of the refspec(s) {} matched any of the {num_remote_refs} refs on the remote", refspecs.iter().map(|r| r.to_ref().instruction().to_bstring().to_string()).collect::<Vec<_>>().join(", "))]
53-
NoMapping {
54-
refspecs: Vec<gix_refspec::RefSpec>,
55-
num_remote_refs: usize,
56-
},
5755
}
5856

5957
impl gix_protocol::transport::IsSpuriousError for Error {

0 commit comments

Comments
 (0)