Skip to content

Commit 777ba7f

Browse files
committed
A step closer to actually obtaining a validated ref-mapping. (#450)
Now the types have to be converted to refer to our remote's refspecs, possibly, even though maybe that's too much and a simple 1:1 conversion that degenerates information is enough for all the use-cases.
1 parent 91f193f commit 777ba7f

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

git-repository/src/remote/connection/list_refs.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ where
7070
}
7171

7272
///
73-
pub mod to_mapping {
73+
pub mod to_map {
7474
use crate::remote::{fetch, Connection};
7575
use git_features::progress::Progress;
7676
use git_protocol::transport::client::Transport;
@@ -81,6 +81,8 @@ pub mod to_mapping {
8181
pub enum Error {
8282
#[error(transparent)]
8383
ListRefs(#[from] crate::remote::list_refs::Error),
84+
#[error(transparent)]
85+
MappingValidation(#[from] git_refspec::match_group::validate::Error),
8486
}
8587

8688
impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P>
@@ -96,20 +98,32 @@ pub mod to_mapping {
9698
///
9799
/// Note that this doesn't fetch the objects mentioned in the tips nor does it make any change to underlying repository.
98100
#[git_protocol::maybe_async::maybe_async]
99-
pub async fn list_refs_to_mapping(mut self) -> Result<Vec<fetch::Mapping>, Error> {
100-
let mappings = self.ref_mapping().await?;
101+
pub async fn list_refs_to_map(mut self) -> Result<fetch::RefMap, Error> {
102+
let mappings = self.ref_map().await?;
101103
git_protocol::fetch::indicate_end_of_interaction(&mut self.transport)
102104
.await
103105
.map_err(|err| Error::ListRefs(crate::remote::list_refs::Error::Transport(err)))?;
104106
Ok(mappings)
105107
}
106108

107109
#[git_protocol::maybe_async::maybe_async]
108-
async fn ref_mapping(&mut self) -> Result<Vec<fetch::Mapping>, Error> {
109-
let _res = self.fetch_refs().await?;
110-
let _group = git_refspec::MatchGroup::from_fetch_specs(self.remote.fetch_specs.iter().map(|s| s.to_ref()));
111-
// group.match_remotes(res.refs.iter().map(|r| r.unpack()))
112-
Ok(Vec::new())
110+
async fn ref_map(&mut self) -> Result<fetch::RefMap, Error> {
111+
let res = self.fetch_refs().await?;
112+
let group = git_refspec::MatchGroup::from_fetch_specs(self.remote.fetch_specs.iter().map(|s| s.to_ref()));
113+
let (_res, fixes) = group
114+
.match_remotes(res.refs.iter().map(|r| {
115+
let (full_ref_name, target, object) = r.unpack();
116+
git_refspec::match_group::Item {
117+
full_ref_name,
118+
target,
119+
object,
120+
}
121+
}))
122+
.validated()?;
123+
Ok(fetch::RefMap {
124+
mappings: Vec::new(),
125+
fixes,
126+
})
113127
}
114128
}
115129
}

git-repository/src/remote/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ pub mod init;
3030
pub mod fetch {
3131
use crate::bstr::BString;
3232

33+
/// Information about the relationship between our refspecs, and remote references with their local counterparts.
34+
pub struct RefMap {
35+
/// A mapping between a remote reference and a local tracking branch.
36+
pub mappings: Vec<Mapping>,
37+
/// Information about the fixes applied to the `mapping` due to validation and sanitization.
38+
pub fixes: Vec<git_refspec::match_group::validate::Fix>,
39+
}
40+
3341
/// A mapping between a single remote reference and its advertised objects to a local destination which may or may not exist.
3442
pub struct Mapping {
3543
/// The reference on the remote side, along with information about the objects they point to as advertised by the server.

0 commit comments

Comments
 (0)