|
1 | 1 | use git_features::progress::Progress;
|
2 | 2 | use git_protocol::transport::client::Transport;
|
3 | 3 |
|
4 |
| -use crate::remote::{connection::HandshakeWithRefs, fetch, Connection, Direction}; |
| 4 | +use crate::remote::{connection::HandshakeWithRefs, Connection, Direction}; |
5 | 5 |
|
6 |
| -mod error { |
7 |
| - #[derive(Debug, thiserror::Error)] |
8 |
| - pub enum Error { |
9 |
| - #[error(transparent)] |
10 |
| - Handshake(#[from] git_protocol::fetch::handshake::Error), |
11 |
| - #[error(transparent)] |
12 |
| - ListRefs(#[from] git_protocol::fetch::refs::Error), |
13 |
| - #[error(transparent)] |
14 |
| - Transport(#[from] git_protocol::transport::client::Error), |
15 |
| - #[error(transparent)] |
16 |
| - ConfigureCredentials(#[from] crate::config::credential_helpers::Error), |
17 |
| - } |
| 6 | +/// The error returned by [`Connection::list_refs()`]. |
| 7 | +#[derive(Debug, thiserror::Error)] |
| 8 | +#[allow(missing_docs)] |
| 9 | +pub enum Error { |
| 10 | + #[error(transparent)] |
| 11 | + Handshake(#[from] git_protocol::fetch::handshake::Error), |
| 12 | + #[error(transparent)] |
| 13 | + ListRefs(#[from] git_protocol::fetch::refs::Error), |
| 14 | + #[error(transparent)] |
| 15 | + Transport(#[from] git_protocol::transport::client::Error), |
| 16 | + #[error(transparent)] |
| 17 | + ConfigureCredentials(#[from] crate::config::credential_helpers::Error), |
18 | 18 | }
|
19 |
| -pub use error::Error; |
20 | 19 |
|
21 | 20 | impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P>
|
22 | 21 | where
|
|
33 | 32 | Ok(res.refs)
|
34 | 33 | }
|
35 | 34 |
|
36 |
| - /// A mapping showing the objects available in refs matching our ref-specs on the remote side, along with their destination |
37 |
| - /// ref locally, if set and if there are no conflicts. |
38 |
| - #[git_protocol::maybe_async::maybe_async] |
39 |
| - pub async fn ref_mapping(self) -> Result<Vec<fetch::Mapping>, Error> { |
40 |
| - todo!() |
41 |
| - } |
42 |
| - |
43 | 35 | #[git_protocol::maybe_async::maybe_async]
|
44 | 36 | async fn fetch_refs(&mut self) -> Result<HandshakeWithRefs, Error> {
|
45 | 37 | let mut credentials_storage;
|
@@ -75,15 +67,49 @@ where
|
75 | 67 | };
|
76 | 68 | Ok(HandshakeWithRefs { outcome, refs })
|
77 | 69 | }
|
| 70 | +} |
78 | 71 |
|
79 |
| - /// List all references on the remote that have been filtered through our remote's [`refspecs`][crate::Remote::refspecs()] |
80 |
| - /// for _fetching_ or _pushing_ depending on `direction`. |
81 |
| - /// |
82 |
| - /// This comes in the form of information of all matching tips on the remote and the object they point to, along with |
83 |
| - /// with the local tracking branch of these tips (if available). |
84 |
| - /// |
85 |
| - /// Note that this doesn't fetch the objects mentioned in the tips nor does it make any change to underlying repository. |
86 |
| - pub fn list_refs_by_refspec(&mut self, _direction: Direction) -> ! { |
87 |
| - todo!() |
| 72 | +/// |
| 73 | +pub mod to_mapping { |
| 74 | + use crate::remote::{fetch, Connection}; |
| 75 | + use git_features::progress::Progress; |
| 76 | + use git_protocol::transport::client::Transport; |
| 77 | + |
| 78 | + /// The error returned by [`Connection::list_refs_to_mapping()`]. |
| 79 | + #[derive(Debug, thiserror::Error)] |
| 80 | + #[allow(missing_docs)] |
| 81 | + pub enum Error { |
| 82 | + #[error(transparent)] |
| 83 | + ListRefs(#[from] crate::remote::list_refs::Error), |
| 84 | + } |
| 85 | + |
| 86 | + impl<'a, 'repo, T, P> Connection<'a, 'repo, T, P> |
| 87 | + where |
| 88 | + T: Transport, |
| 89 | + P: Progress, |
| 90 | + { |
| 91 | + /// List all references on the remote that have been filtered through our remote's [`refspecs`][crate::Remote::refspecs()] |
| 92 | + /// for _fetching_. |
| 93 | + /// |
| 94 | + /// This comes in the form of all matching tips on the remote and the object they point to, along with |
| 95 | + /// with the local tracking branch of these tips (if available). |
| 96 | + /// |
| 97 | + /// Note that this doesn't fetch the objects mentioned in the tips nor does it make any change to underlying repository. |
| 98 | + #[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 | + git_protocol::fetch::indicate_end_of_interaction(&mut self.transport) |
| 102 | + .await |
| 103 | + .map_err(|err| Error::ListRefs(crate::remote::list_refs::Error::Transport(err)))?; |
| 104 | + Ok(mappings) |
| 105 | + } |
| 106 | + |
| 107 | + #[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()) |
| 113 | + } |
88 | 114 | }
|
89 | 115 | }
|
0 commit comments