Unified · Split
| @@ -2,6 +2,9 @@ · 1 unmodified line | ||
| 2 | 2 | pub struct Prepare { |
| 3 | 3 | /// A freshly initialized repository which is owned by us, or `None` if it was handed to the user |
| 4 | 4 | repo: Option<crate::Repository>, |
| 5 | + /// A function to configure a remote prior to fetching a pack. | |
| 6 | + configure_remote: | |
| 7 | + Option<Box<dyn FnOnce(crate::Remote<'_>) -> Result<crate::Remote<'_>, crate::remote::init::Error>>>, | |
| 5 | 8 | /// The url to clone from |
| 6 | 9 | #[allow(dead_code)] |
| 7 | 10 | url: git_url::Url, |
| @@ -42,7 +45,27 @@ pub mod prepare { · 34 unmodified lines | ||
| 42 | 45 | { |
| 43 | 46 | let url = url.try_into().map_err(git_url::parse::Error::from)?; |
| 44 | 47 | let repo = crate::ThreadSafeRepository::init_opts(path, create_opts, open_opts)?.to_thread_local(); |
| 45 | − Ok(Prepare { url, repo: Some(repo) }) | |
| 48 | + Ok(Prepare { | |
| 49 | + url, | |
| 50 | + repo: Some(repo), | |
| 51 | + configure_remote: None, | |
| 52 | + }) | |
| 53 | + } | |
| 54 | + } | |
| 55 | + | |
| 56 | + /// Builder | |
| 57 | + impl Prepare { | |
| 58 | + /// Use `f` to apply arbitrary changes to the remote that is about to be used to fetch a pack. | |
| 59 | + /// | |
| 60 | + /// The passed in `remote` will be anonymous and pre-configured to be a default remote as we know it from git-clone. | |
| 61 | + /// It is not yet present in the configuration of the repository, | |
| 62 | + /// but each change it will eventually be written to the configuration prior to performing a the fetch operation. | |
| 63 | + pub fn configure_remote( | |
| 64 | + mut self, | |
| 65 | + f: impl FnOnce(crate::Remote<'_>) -> Result<crate::Remote<'_>, crate::remote::init::Error> + 'static, | |
| 66 | + ) -> Self { | |
| 67 | + self.configure_remote = Some(Box::new(f)); | |
| 68 | + self | |
| 46 | 69 | } |
| 47 | 70 | } |
| 48 | 71 | |