Skip to content

Commit

Permalink
Add git2-curl as a dependency
Browse files Browse the repository at this point in the history
Due to libgit2 not supporting HTTP proxies, the custom transport API of the
library must be used to reimplement the HTTP transport with proxy support. The
git2-curl crate implements this transport on top of the curl-rust crate. By
using libcurl we gain all sorts of proxy support for free.

This transport is not used by default, however, as it is not well battle tested
and the architecture is not currently ideal (download the entire repo into
memory on a clone). Only when an HTTP proxy is present is the new transport
used.

The other drawback of git2-curl is that it does not currently support
authentication. If a private git repository is cloned or authentication is
required then it will generate an error instead of correctly asking for
credentials.

Closes rust-lang#636
  • Loading branch information
alexcrichton committed Feb 10, 2015
1 parent 9404539 commit b20b0f6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ curl = "0.1"
tar = "0.1"
flate2 = "0.1"
git2 = "0.1"
git2-curl = "0.1"
glob = "0.1"
time = "0.1"
log = "0.2"
Expand Down
32 changes: 32 additions & 0 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(collections, core, io, path, env)]

extern crate "git2-curl" as git2_curl;
extern crate "rustc-serialize" as rustc_serialize;
extern crate cargo;
extern crate env_logger;
Expand Down Expand Up @@ -88,6 +89,8 @@ macro_rules! each_subcommand{ ($mac:ident) => ({
fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
config.shell().set_verbose(flags.flag_verbose);

init_git_transports(config);

if flags.flag_list {
println!("Installed Commands:");
for command in list_commands().into_iter() {
Expand Down Expand Up @@ -247,3 +250,32 @@ fn list_command_directory() -> Vec<Path> {
}
dirs
}

fn init_git_transports(config: &Config) {
// Only use a custom transport if a proxy is configured, right now libgit2
// doesn't support proxies and we have to use a custom transport in this
// case. The custom transport, however, is not as well battle-tested.
match cargo::ops::http_proxy(config) {
Ok(Some(..)) => {}
_ => return
}

let handle = match cargo::ops::http_handle(config) {
Ok(handle) => handle,
Err(..) => return,
};

// The unsafety of the registration function derives from two aspects:
//
// 1. This call must be synchronized with all other registration calls as
// well as construction of new transports.
// 2. The argument is leaked.
//
// We're clear on point (1) because this is only called at the start of this
// binary (we know what the state of the world looks like) and we're mostly
// clear on point (2) because we'd only free it after everything is done
// anyway
unsafe {
git2_curl::register(handle);
}
}

0 comments on commit b20b0f6

Please sign in to comment.