|
1 | 1 | #![feature(collections, core, io, path, env)]
|
2 | 2 |
|
| 3 | +extern crate "git2-curl" as git2_curl; |
3 | 4 | extern crate "rustc-serialize" as rustc_serialize;
|
4 | 5 | extern crate cargo;
|
5 | 6 | extern crate env_logger;
|
@@ -88,6 +89,8 @@ macro_rules! each_subcommand{ ($mac:ident) => ({
|
88 | 89 | fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
|
89 | 90 | config.shell().set_verbose(flags.flag_verbose);
|
90 | 91 |
|
| 92 | + init_git_transports(config); |
| 93 | + |
91 | 94 | if flags.flag_list {
|
92 | 95 | println!("Installed Commands:");
|
93 | 96 | for command in list_commands().into_iter() {
|
@@ -247,3 +250,32 @@ fn list_command_directory() -> Vec<Path> {
|
247 | 250 | }
|
248 | 251 | dirs
|
249 | 252 | }
|
| 253 | + |
| 254 | +fn init_git_transports(config: &Config) { |
| 255 | + // Only use a custom transport if a proxy is configured, right now libgit2 |
| 256 | + // doesn't support proxies and we have to use a custom transport in this |
| 257 | + // case. The custom transport, however, is not as well battle-tested. |
| 258 | + match cargo::ops::http_proxy(config) { |
| 259 | + Ok(Some(..)) => {} |
| 260 | + _ => return |
| 261 | + } |
| 262 | + |
| 263 | + let handle = match cargo::ops::http_handle(config) { |
| 264 | + Ok(handle) => handle, |
| 265 | + Err(..) => return, |
| 266 | + }; |
| 267 | + |
| 268 | + // The unsafety of the registration function derives from two aspects: |
| 269 | + // |
| 270 | + // 1. This call must be synchronized with all other registration calls as |
| 271 | + // well as construction of new transports. |
| 272 | + // 2. The argument is leaked. |
| 273 | + // |
| 274 | + // We're clear on point (1) because this is only called at the start of this |
| 275 | + // binary (we know what the state of the world looks like) and we're mostly |
| 276 | + // clear on point (2) because we'd only free it after everything is done |
| 277 | + // anyway |
| 278 | + unsafe { |
| 279 | + git2_curl::register(handle); |
| 280 | + } |
| 281 | +} |
0 commit comments