use auto proxy option

This commit is contained in:
Stephan Dilly 2022-01-25 21:16:59 +01:00
parent bfba218fb4
commit 53e855e488
3 changed files with 22 additions and 6 deletions

View file

@ -13,7 +13,7 @@ use crate::{
ProgressPercent, ProgressPercent,
}; };
use crossbeam_channel::Sender; use crossbeam_channel::Sender;
use git2::{BranchType, FetchOptions, Repository}; use git2::{BranchType, FetchOptions, ProxyOptions, Repository};
use scopetime::scope_time; use scopetime::scope_time;
use utils::bytes2string; use utils::bytes2string;
@ -25,6 +25,13 @@ use super::RepoPath;
/// origin /// origin
pub const DEFAULT_REMOTE_NAME: &str = "origin"; pub const DEFAULT_REMOTE_NAME: &str = "origin";
///
pub fn proxy_auto<'a>() -> ProxyOptions<'a> {
let mut proxy = ProxyOptions::new();
proxy.auto();
proxy
}
/// ///
pub fn get_remotes(repo_path: &RepoPath) -> Result<Vec<String>> { pub fn get_remotes(repo_path: &RepoPath) -> Result<Vec<String>> {
scope_time!("get_remotes"); scope_time!("get_remotes");
@ -92,6 +99,7 @@ fn fetch_from_remote(
let mut options = FetchOptions::new(); let mut options = FetchOptions::new();
let callbacks = Callbacks::new(progress_sender, basic_credential); let callbacks = Callbacks::new(progress_sender, basic_credential);
options.prune(git2::FetchPrune::On); options.prune(git2::FetchPrune::On);
options.proxy_options(proxy_auto());
options.download_tags(git2::AutotagOption::All); options.download_tags(git2::AutotagOption::All);
options.remote_callbacks(callbacks.callbacks()); options.remote_callbacks(callbacks.callbacks());
remote.fetch(&[] as &[&str], Some(&mut options), None)?; remote.fetch(&[] as &[&str], Some(&mut options), None)?;
@ -161,6 +169,7 @@ pub(crate) fn fetch(
options.download_tags(git2::AutotagOption::All); options.download_tags(git2::AutotagOption::All);
let callbacks = Callbacks::new(progress_sender, basic_credential); let callbacks = Callbacks::new(progress_sender, basic_credential);
options.remote_callbacks(callbacks.callbacks()); options.remote_callbacks(callbacks.callbacks());
options.proxy_options(proxy_auto());
remote.fetch(&[branch], Some(&mut options), None)?; remote.fetch(&[branch], Some(&mut options), None)?;

View file

@ -2,8 +2,11 @@ use crate::{
error::{Error, Result}, error::{Error, Result},
progress::ProgressPercent, progress::ProgressPercent,
sync::{ sync::{
branch::branch_set_upstream, cred::BasicAuthCredential, branch::branch_set_upstream,
remotes::Callbacks, repository::repo, CommitId, RepoPath, cred::BasicAuthCredential,
remotes::{proxy_auto, Callbacks},
repository::repo,
CommitId, RepoPath,
}, },
}; };
use crossbeam_channel::Sender; use crossbeam_channel::Sender;
@ -143,6 +146,7 @@ pub fn push_raw(
let mut remote = repo.find_remote(remote)?; let mut remote = repo.find_remote(remote)?;
let mut options = PushOptions::new(); let mut options = PushOptions::new();
options.proxy_options(proxy_auto());
let callbacks = Callbacks::new(progress_sender, basic_credential); let callbacks = Callbacks::new(progress_sender, basic_credential);
options.remote_callbacks(callbacks.callbacks()); options.remote_callbacks(callbacks.callbacks());

View file

@ -5,8 +5,10 @@ use crate::{
error::Result, error::Result,
progress::ProgressPercent, progress::ProgressPercent,
sync::{ sync::{
cred::BasicAuthCredential, remotes::Callbacks, cred::BasicAuthCredential,
repository::repo, RepoPath, remotes::{proxy_auto, Callbacks},
repository::repo,
RepoPath,
}, },
}; };
use crossbeam_channel::Sender; use crossbeam_channel::Sender;
@ -59,7 +61,7 @@ fn remote_tag_refs(
let conn = remote.connect_auth( let conn = remote.connect_auth(
Direction::Fetch, Direction::Fetch,
Some(callbacks.callbacks()), Some(callbacks.callbacks()),
None, Some(proxy_auto()),
)?; )?;
let remote_heads = conn.list()?; let remote_heads = conn.list()?;
@ -133,6 +135,7 @@ pub fn push_tags(
Callbacks::new(None, basic_credential.clone()); Callbacks::new(None, basic_credential.clone());
options.remote_callbacks(callbacks.callbacks()); options.remote_callbacks(callbacks.callbacks());
options.packbuilder_parallelism(0); options.packbuilder_parallelism(0);
options.proxy_options(proxy_auto());
remote.push(&[tag.as_str()], Some(&mut options))?; remote.push(&[tag.as_str()], Some(&mut options))?;
progress_sender.as_ref().map(|sender| { progress_sender.as_ref().map(|sender| {