Skip to content

Commit e59fc09

Browse files
committed
feat!: move all possible code from gix to gix-protocol.
For now, just move the code down and immediately re-integrate in `gix` to be able to use its tests to validate it. This is a breaking change as some types move and change the layout.
1 parent 6367c7d commit e59fc09

File tree

39 files changed

+1590
-1001
lines changed

39 files changed

+1590
-1001
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitoxide-core/src/repository/fetch.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub(crate) mod function {
210210
mut out: impl std::io::Write,
211211
mut err: impl std::io::Write,
212212
) -> anyhow::Result<()> {
213-
let mut last_spec_index = gix::remote::fetch::SpecIndex::ExplicitInRemote(usize::MAX);
213+
let mut last_spec_index = gix::remote::fetch::refmap::SpecIndex::ExplicitInRemote(usize::MAX);
214214
let mut updates = update_refs
215215
.iter_mapping_updates(&map.mappings, refspecs, &map.extra_refspecs)
216216
.filter_map(|(update, mapping, spec, edit)| spec.map(|spec| (update, mapping, spec, edit)))
@@ -258,10 +258,10 @@ pub(crate) mod function {
258258

259259
write!(out, "\t")?;
260260
match &mapping.remote {
261-
gix::remote::fetch::Source::ObjectId(id) => {
261+
gix::remote::fetch::refmap::Source::ObjectId(id) => {
262262
write!(out, "{}", id.attach(repo).shorten_or_id())?;
263263
}
264-
gix::remote::fetch::Source::Ref(r) => {
264+
gix::remote::fetch::refmap::Source::Ref(r) => {
265265
crate::repository::remote::refs::print_ref(&mut out, r)?;
266266
}
267267
};

gitoxide-core/src/repository/remote.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod refs_impl {
44
use gix::{
55
protocol::handshake,
66
refspec::{match_group::validate::Fix, RefSpec},
7-
remote::fetch::Source,
7+
remote::fetch::refmap::Source,
88
};
99

1010
use super::by_name_or_url;
@@ -119,7 +119,7 @@ mod refs_impl {
119119
mut out: impl std::io::Write,
120120
mut err: impl std::io::Write,
121121
) -> anyhow::Result<()> {
122-
let mut last_spec_index = gix::remote::fetch::SpecIndex::ExplicitInRemote(usize::MAX);
122+
let mut last_spec_index = gix::remote::fetch::refmap::SpecIndex::ExplicitInRemote(usize::MAX);
123123
map.mappings.sort_by_key(|m| m.spec_index);
124124
for mapping in &map.mappings {
125125
if mapping.spec_index != last_spec_index {
@@ -146,11 +146,11 @@ mod refs_impl {
146146

147147
write!(out, "\t")?;
148148
let target_id = match &mapping.remote {
149-
gix::remote::fetch::Source::ObjectId(id) => {
149+
gix::remote::fetch::refmap::Source::ObjectId(id) => {
150150
write!(out, "{id}")?;
151151
id
152152
}
153-
gix::remote::fetch::Source::Ref(r) => print_ref(&mut out, r)?,
153+
gix::remote::fetch::refmap::Source::Ref(r) => print_ref(&mut out, r)?,
154154
};
155155
match &mapping.local {
156156
Some(local) => {

gix-protocol/Cargo.toml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,38 @@ doctest = false
2323
#! Specifying both causes a compile error, preventing the use of `--all-features`.
2424

2525
## If set, blocking command implementations are available and will use the blocking version of the `gix-transport` crate.
26-
blocking-client = ["gix-transport/blocking-client", "maybe-async/is_sync"]
26+
blocking-client = [
27+
"gix-transport/blocking-client",
28+
"maybe-async/is_sync",
29+
"handshake",
30+
"fetch"
31+
]
2732
## As above, but provides async implementations instead.
2833
async-client = [
2934
"gix-transport/async-client",
30-
"async-trait",
31-
"futures-io",
32-
"futures-lite",
35+
"dep:async-trait",
36+
"dep:futures-io",
37+
"dep:futures-lite",
38+
"handshake",
39+
"fetch"
40+
]
41+
42+
## Add implementations for performing a `handshake` along with the dependencies needed for it.
43+
handshake = ["dep:gix-credentials"]
44+
45+
## Add implementations for performing a `fetch` (for packs) along with the dependencies needed for it.
46+
fetch = [
47+
"dep:gix-negotiate",
48+
"dep:gix-object",
49+
"dep:gix-revwalk",
50+
"dep:gix-lock",
51+
"dep:gix-refspec",
52+
"dep:gix-trace",
3353
]
3454

3555
#! ### Other
3656
## Data structures implement `serde::Serialize` and `serde::Deserialize`.
37-
serde = ["dep:serde", "bstr/serde", "gix-transport/serde", "gix-hash/serde"]
57+
serde = ["dep:serde", "bstr/serde", "gix-transport/serde", "gix-hash/serde", "gix-shallow/serde"]
3858

3959
[[test]]
4060
name = "blocking"
@@ -54,8 +74,16 @@ gix-transport = { version = "^0.43.1", path = "../gix-transport" }
5474
gix-hash = { version = "^0.15.1", path = "../gix-hash" }
5575
gix-shallow = { version = "^0.1.0", path = "../gix-shallow" }
5676
gix-date = { version = "^0.9.2", path = "../gix-date" }
57-
gix-credentials = { version = "^0.25.1", path = "../gix-credentials" }
5877
gix-utils = { version = "^0.1.13", path = "../gix-utils" }
78+
gix-ref = { version = "^0.49.0", path = "../gix-ref" }
79+
80+
gix-trace = { version = "^0.1.11", path = "../gix-trace", optional = true }
81+
gix-negotiate = { version = "^0.17.0", path = "../gix-negotiate", optional = true }
82+
gix-object = { version = "^0.46.0", path = "../gix-object", optional = true }
83+
gix-revwalk = { version = "^0.17.0", path = "../gix-revwalk", optional = true }
84+
gix-credentials = { version = "^0.25.1", path = "../gix-credentials", optional = true }
85+
gix-refspec = { version = "^0.27.0", path = "../gix-refspec", optional = true }
86+
gix-lock = { version = "^15.0.0", path = "../gix-lock", optional = true }
5987

6088
thiserror = "2.0.0"
6189
serde = { version = "1.0.114", optional = true, default-features = false, features = [

gix-protocol/src/fetch/arguments/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub struct Arguments {
2424
#[cfg(any(feature = "async-client", feature = "blocking-client"))]
2525
version: gix_transport::Protocol,
2626

27+
#[cfg(any(feature = "async-client", feature = "blocking-client"))]
2728
trace: bool,
2829
}
2930

@@ -164,6 +165,7 @@ impl Arguments {
164165
/// Permanently allow the server to include tags that point to commits or objects it would return.
165166
///
166167
/// Needs to only be called once.
168+
#[cfg(any(feature = "async-client", feature = "blocking-client"))]
167169
pub fn use_include_tag(&mut self) {
168170
debug_assert!(self.supports_include_tag, "'include-tag' feature required");
169171
if self.supports_include_tag {
@@ -176,6 +178,7 @@ impl Arguments {
176178
/// Note that sending an unknown or unsupported feature may cause the remote to terminate
177179
/// the connection. Use this method if you know what you are doing *and* there is no specialized
178180
/// method for this, e.g. [`Self::use_include_tag()`].
181+
#[cfg(any(feature = "async-client", feature = "blocking-client"))]
179182
pub fn add_feature(&mut self, feature: &str) {
180183
match self.version {
181184
gix_transport::Protocol::V0 | gix_transport::Protocol::V1 => {

gix-protocol/src/fetch/error.rs

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
1-
use std::io;
2-
3-
use gix_transport::client;
4-
5-
use crate::{fetch::response, handshake, ls_refs};
6-
7-
/// The error used in [`fetch()`][crate::fetch()].
1+
/// The error returned by [`fetch()`](crate::fetch()).
82
#[derive(Debug, thiserror::Error)]
93
#[allow(missing_docs)]
104
pub enum Error {
5+
#[error("Could not decode server reply")]
6+
FetchResponse(#[from] crate::fetch::response::Error),
7+
#[error("Cannot fetch from a remote that uses {remote} while local repository uses {local} for object hashes")]
8+
IncompatibleObjectHash {
9+
local: gix_hash::Kind,
10+
remote: gix_hash::Kind,
11+
},
1112
#[error(transparent)]
12-
Handshake(#[from] handshake::Error),
13-
#[error("Could not access repository or failed to read streaming pack file")]
14-
Io(#[from] io::Error),
15-
#[error(transparent)]
16-
Transport(#[from] client::Error),
13+
Negotiate(#[from] crate::fetch::negotiate::Error),
1714
#[error(transparent)]
18-
LsRefs(#[from] ls_refs::Error),
19-
#[error(transparent)]
20-
Response(#[from] response::Error),
15+
Client(#[from] crate::transport::client::Error),
16+
#[error("Server lack feature {feature:?}: {description}")]
17+
MissingServerFeature {
18+
feature: &'static str,
19+
description: &'static str,
20+
},
21+
#[error("Could not write 'shallow' file to incorporate remote updates after fetching")]
22+
WriteShallowFile(#[from] gix_shallow::write::Error),
23+
#[error("Could not read 'shallow' file to send current shallow boundary")]
24+
ReadShallowFile(#[from] gix_shallow::read::Error),
25+
#[error("'shallow' file could not be locked in preparation for writing changes")]
26+
LockShallowFile(#[from] gix_lock::acquire::Error),
27+
#[error("Receiving objects from shallow remotes is prohibited due to the value of `clone.rejectShallow`")]
28+
RejectShallowRemote,
29+
#[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(", "))]
30+
NoMapping {
31+
refspecs: Vec<gix_refspec::RefSpec>,
32+
num_remote_refs: usize,
33+
},
34+
#[error("Failed to consume the pack sent by the remove")]
35+
ConsumePack(Box<dyn std::error::Error + Send + Sync + 'static>),
36+
#[error("Failed to read remaining bytes in stream")]
37+
ReadRemainingBytes(#[source] std::io::Error),
38+
}
39+
40+
impl crate::transport::IsSpuriousError for Error {
41+
fn is_spurious(&self) -> bool {
42+
match self {
43+
Error::FetchResponse(err) => err.is_spurious(),
44+
Error::Client(err) => err.is_spurious(),
45+
_ => false,
46+
}
47+
}
2148
}

0 commit comments

Comments
 (0)