summaryrefslogtreecommitdiffstats
path: root/vendor/git2-curl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:35 +0000
commit7e5d7eea9c580ef4b41a765bde624af431942b96 (patch)
tree2c0d9ca12878fc4525650aa4e54d77a81a07cc09 /vendor/git2-curl
parentAdding debian version 1.70.0+dfsg1-9. (diff)
downloadrustc-7e5d7eea9c580ef4b41a765bde624af431942b96.tar.xz
rustc-7e5d7eea9c580ef4b41a765bde624af431942b96.zip
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/git2-curl')
-rw-r--r--vendor/git2-curl/.cargo-checksum.json1
-rw-r--r--vendor/git2-curl/CHANGELOG.md21
-rw-r--r--vendor/git2-curl/Cargo.toml62
-rw-r--r--vendor/git2-curl/LICENSE-APACHE201
-rw-r--r--vendor/git2-curl/LICENSE-MIT25
-rw-r--r--vendor/git2-curl/src/lib.rs291
-rw-r--r--vendor/git2-curl/tests/all.rs74
7 files changed, 675 insertions, 0 deletions
diff --git a/vendor/git2-curl/.cargo-checksum.json b/vendor/git2-curl/.cargo-checksum.json
new file mode 100644
index 000000000..890201873
--- /dev/null
+++ b/vendor/git2-curl/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"CHANGELOG.md":"f6f84d652ab203ceab1d7b2bbd74b3377ab0f6427953e351ef913a6c1ec4341e","Cargo.toml":"72640f80cabc15e50db969c34e33cd46137d20e5b9affc05922030598fc661ac","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","src/lib.rs":"ceba74be9bcb8644b372693bea460ae869411a6036fd49b52f99d130dfc18180","tests/all.rs":"5b48bca5608c533f4763f850a9b838cffe09e73e529261f16c331e10296f8e14"},"package":"f8f8b7432b72928cff76f69e59ed5327f94a52763731e71274960dee72fe5f8c"} \ No newline at end of file
diff --git a/vendor/git2-curl/CHANGELOG.md b/vendor/git2-curl/CHANGELOG.md
new file mode 100644
index 000000000..f20930568
--- /dev/null
+++ b/vendor/git2-curl/CHANGELOG.md
@@ -0,0 +1,21 @@
+# Changelog
+
+## 0.18.0 - 2023-04-02
+[0.17.0...0.18.0](https://github.com/rust-lang/git2-rs/compare/git2-curl-0.17.0...git2-curl-0.18.0)
+
+- Updated to [git2 0.17.0](../CHANGELOG.md#0170---2023-04-02)
+
+## 0.17.0 - 2023-01-10
+[0.16.0...0.17.0](https://github.com/rust-lang/git2-rs/compare/git2-curl-0.16.0...git2-curl-0.17.0)
+
+- Updated to [git2 0.16.0](../CHANGELOG.md#0160---2023-01-10)
+
+## 0.16.0 - 2022-07-28
+[0.15.0...0.16.0](https://github.com/rust-lang/git2-rs/compare/git2-curl-0.15.0...git2-curl-0.16.0)
+
+- Updated to [git2 0.15.0](../CHANGELOG.md#0150---2022-07-28)
+
+## 0.15.0 - 2022-02-28
+[0.14.1...0.15.0](https://github.com/rust-lang/git2-rs/compare/git2-curl-0.14.1...git2-curl-0.15.0)
+
+- Updated to [git2 0.14.0](../CHANGELOG.md#0140---2022-02-24)
diff --git a/vendor/git2-curl/Cargo.toml b/vendor/git2-curl/Cargo.toml
new file mode 100644
index 000000000..e60ea6e63
--- /dev/null
+++ b/vendor/git2-curl/Cargo.toml
@@ -0,0 +1,62 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies.
+#
+# If you are reading this file be aware that the original Cargo.toml
+# will likely look very different (and much more reasonable).
+# See Cargo.toml.orig for the original contents.
+
+[package]
+edition = "2018"
+name = "git2-curl"
+version = "0.18.0"
+authors = [
+ "Josh Triplett <josh@joshtriplett.org>",
+ "Alex Crichton <alex@alexcrichton.com>",
+]
+description = """
+Backend for an HTTP transport in libgit2 powered by libcurl.
+
+Intended to be used with the git2 crate.
+"""
+documentation = "https://docs.rs/git2-curl"
+license = "MIT OR Apache-2.0"
+repository = "https://github.com/rust-lang/git2-rs"
+
+[[test]]
+name = "all"
+harness = false
+
+[dependencies.curl]
+version = "0.4.33"
+
+[dependencies.git2]
+version = "0.17"
+default-features = false
+
+[dependencies.log]
+version = "0.4"
+
+[dependencies.url]
+version = "2.0"
+
+[dev-dependencies.civet]
+version = "0.11"
+
+[dev-dependencies.conduit]
+version = "0.8"
+
+[dev-dependencies.conduit-git-http-backend]
+version = "0.8"
+
+[dev-dependencies.tempfile]
+version = "3.0"
+
+[features]
+zlib-ng-compat = [
+ "git2/zlib-ng-compat",
+ "curl/zlib-ng-compat",
+]
diff --git a/vendor/git2-curl/LICENSE-APACHE b/vendor/git2-curl/LICENSE-APACHE
new file mode 100644
index 000000000..16fe87b06
--- /dev/null
+++ b/vendor/git2-curl/LICENSE-APACHE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/vendor/git2-curl/LICENSE-MIT b/vendor/git2-curl/LICENSE-MIT
new file mode 100644
index 000000000..39e0ed660
--- /dev/null
+++ b/vendor/git2-curl/LICENSE-MIT
@@ -0,0 +1,25 @@
+Copyright (c) 2014 Alex Crichton
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/vendor/git2-curl/src/lib.rs b/vendor/git2-curl/src/lib.rs
new file mode 100644
index 000000000..a0a6c9871
--- /dev/null
+++ b/vendor/git2-curl/src/lib.rs
@@ -0,0 +1,291 @@
+//! A crate for using libcurl as a backend for HTTP git requests with git2-rs.
+//!
+//! This crate provides one public function, `register`, which will register
+//! a custom HTTP transport with libcurl for any HTTP requests made by libgit2.
+//! At this time the `register` function is unsafe for the same reasons that
+//! `git2::transport::register` is also unsafe.
+//!
+//! It is not recommended to use this crate wherever possible. The current
+//! libcurl backend used, `curl-rust`, only supports executing a request in one
+//! method call implying no streaming support. This consequently means that
+//! when a repository is cloned the entire contents of the repo are downloaded
+//! into memory, and *then* written off to disk by libgit2 afterwards. It
+//! should be possible to alleviate this problem in the future.
+//!
+//! > **NOTE**: At this time this crate likely does not support a `git push`
+//! > operation, only clones.
+
+#![doc(html_root_url = "https://docs.rs/git2-curl/0.18")]
+#![deny(missing_docs)]
+#![warn(rust_2018_idioms)]
+#![cfg_attr(test, deny(warnings))]
+
+use std::error;
+use std::io::prelude::*;
+use std::io::{self, Cursor};
+use std::str;
+use std::sync::{Arc, Mutex, Once};
+
+use curl::easy::{Easy, List};
+use git2::transport::SmartSubtransportStream;
+use git2::transport::{Service, SmartSubtransport, Transport};
+use git2::Error;
+use log::{debug, info};
+use url::Url;
+
+struct CurlTransport {
+ handle: Arc<Mutex<Easy>>,
+ /// The URL of the remote server, e.g. "https://github.com/user/repo"
+ ///
+ /// This is an empty string until the first action is performed.
+ /// If there is an HTTP redirect, this will be updated with the new URL.
+ base_url: Arc<Mutex<String>>,
+}
+
+struct CurlSubtransport {
+ handle: Arc<Mutex<Easy>>,
+ service: &'static str,
+ url_path: &'static str,
+ base_url: Arc<Mutex<String>>,
+ method: &'static str,
+ reader: Option<Cursor<Vec<u8>>>,
+ sent_request: bool,
+}
+
+/// Register the libcurl backend for HTTP requests made by libgit2.
+///
+/// This function takes one parameter, a `handle`, which is used to perform all
+/// future HTTP requests. The handle can be previously configured with
+/// information such as proxies, SSL information, etc.
+///
+/// This function is unsafe largely for the same reasons as
+/// `git2::transport::register`:
+///
+/// * The function needs to be synchronized against all other creations of
+/// transport (any API calls to libgit2).
+/// * The function will leak `handle` as once registered it is not currently
+/// possible to unregister the backend.
+///
+/// This function may be called concurrently, but only the first `handle` will
+/// be used. All others will be discarded.
+pub unsafe fn register(handle: Easy) {
+ static INIT: Once = Once::new();
+
+ let handle = Arc::new(Mutex::new(handle));
+ let handle2 = handle.clone();
+ INIT.call_once(move || {
+ git2::transport::register("http", move |remote| factory(remote, handle.clone())).unwrap();
+ git2::transport::register("https", move |remote| factory(remote, handle2.clone())).unwrap();
+ });
+}
+
+fn factory(remote: &git2::Remote<'_>, handle: Arc<Mutex<Easy>>) -> Result<Transport, Error> {
+ Transport::smart(
+ remote,
+ true,
+ CurlTransport {
+ handle: handle,
+ base_url: Arc::new(Mutex::new(String::new())),
+ },
+ )
+}
+
+impl SmartSubtransport for CurlTransport {
+ fn action(
+ &self,
+ url: &str,
+ action: Service,
+ ) -> Result<Box<dyn SmartSubtransportStream>, Error> {
+ let mut base_url = self.base_url.lock().unwrap();
+ if base_url.len() == 0 {
+ *base_url = url.to_string();
+ }
+ let (service, path, method) = match action {
+ Service::UploadPackLs => ("upload-pack", "/info/refs?service=git-upload-pack", "GET"),
+ Service::UploadPack => ("upload-pack", "/git-upload-pack", "POST"),
+ Service::ReceivePackLs => {
+ ("receive-pack", "/info/refs?service=git-receive-pack", "GET")
+ }
+ Service::ReceivePack => ("receive-pack", "/git-receive-pack", "POST"),
+ };
+ info!("action {} {}", service, path);
+ Ok(Box::new(CurlSubtransport {
+ handle: self.handle.clone(),
+ service: service,
+ url_path: path,
+ base_url: self.base_url.clone(),
+ method: method,
+ reader: None,
+ sent_request: false,
+ }))
+ }
+
+ fn close(&self) -> Result<(), Error> {
+ Ok(()) // ...
+ }
+}
+
+impl CurlSubtransport {
+ fn err<E: Into<Box<dyn error::Error + Send + Sync>>>(&self, err: E) -> io::Error {
+ io::Error::new(io::ErrorKind::Other, err)
+ }
+
+ fn execute(&mut self, data: &[u8]) -> io::Result<()> {
+ if self.sent_request {
+ return Err(self.err("already sent HTTP request"));
+ }
+ let agent = format!("git/1.0 (git2-curl {})", env!("CARGO_PKG_VERSION"));
+
+ // Parse our input URL to figure out the host
+ let url = format!("{}{}", self.base_url.lock().unwrap(), self.url_path);
+ let parsed = Url::parse(&url).map_err(|_| self.err("invalid url, failed to parse"))?;
+ let host = match parsed.host_str() {
+ Some(host) => host,
+ None => return Err(self.err("invalid url, did not have a host")),
+ };
+
+ // Prep the request
+ debug!("request to {}", url);
+ let mut h = self.handle.lock().unwrap();
+ h.url(&url)?;
+ h.useragent(&agent)?;
+ h.follow_location(true)?;
+ match self.method {
+ "GET" => h.get(true)?,
+ "PUT" => h.put(true)?,
+ "POST" => h.post(true)?,
+ other => h.custom_request(other)?,
+ }
+
+ let mut headers = List::new();
+ headers.append(&format!("Host: {}", host))?;
+ if data.len() > 0 {
+ h.post_fields_copy(data)?;
+ headers.append(&format!(
+ "Accept: application/x-git-{}-result",
+ self.service
+ ))?;
+ headers.append(&format!(
+ "Content-Type: \
+ application/x-git-{}-request",
+ self.service
+ ))?;
+ } else {
+ headers.append("Accept: */*")?;
+ }
+ headers.append("Expect:")?;
+ h.http_headers(headers)?;
+
+ let mut content_type = None;
+ let mut data = Vec::new();
+ {
+ let mut h = h.transfer();
+
+ // Look for the Content-Type header
+ h.header_function(|header| {
+ let header = match str::from_utf8(header) {
+ Ok(s) => s,
+ Err(..) => return true,
+ };
+ let mut parts = header.splitn(2, ": ");
+ let name = parts.next().unwrap();
+ let value = match parts.next() {
+ Some(value) => value,
+ None => return true,
+ };
+ if name.eq_ignore_ascii_case("Content-Type") {
+ content_type = Some(value.trim().to_string());
+ }
+
+ true
+ })?;
+
+ // Collect the request's response in-memory
+ h.write_function(|buf| {
+ data.extend_from_slice(buf);
+ Ok(buf.len())
+ })?;
+
+ // Send the request
+ h.perform()?;
+ }
+
+ let code = h.response_code()?;
+ if code != 200 {
+ return Err(self.err(
+ &format!(
+ "failed to receive HTTP 200 response: \
+ got {}",
+ code
+ )[..],
+ ));
+ }
+
+ // Check returned headers
+ let expected = match self.method {
+ "GET" => format!("application/x-git-{}-advertisement", self.service),
+ _ => format!("application/x-git-{}-result", self.service),
+ };
+ match content_type {
+ Some(ref content_type) if *content_type != expected => {
+ return Err(self.err(
+ &format!(
+ "expected a Content-Type header \
+ with `{}` but found `{}`",
+ expected, content_type
+ )[..],
+ ))
+ }
+ Some(..) => {}
+ None => {
+ return Err(self.err(
+ &format!(
+ "expected a Content-Type header \
+ with `{}` but didn't find one",
+ expected
+ )[..],
+ ))
+ }
+ }
+
+ // Ok, time to read off some data.
+ let rdr = Cursor::new(data);
+ self.reader = Some(rdr);
+
+ // If there was a redirect, update the `CurlTransport` with the new base.
+ if let Ok(Some(effective_url)) = h.effective_url() {
+ let new_base = if effective_url.ends_with(self.url_path) {
+ // Strip the action from the end.
+ &effective_url[..effective_url.len() - self.url_path.len()]
+ } else {
+ // I'm not sure if this code path makes sense, but it's what
+ // libgit does.
+ effective_url
+ };
+ *self.base_url.lock().unwrap() = new_base.to_string();
+ }
+
+ Ok(())
+ }
+}
+
+impl Read for CurlSubtransport {
+ fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
+ if self.reader.is_none() {
+ self.execute(&[])?;
+ }
+ self.reader.as_mut().unwrap().read(buf)
+ }
+}
+
+impl Write for CurlSubtransport {
+ fn write(&mut self, data: &[u8]) -> io::Result<usize> {
+ if self.reader.is_none() {
+ self.execute(data)?;
+ }
+ Ok(data.len())
+ }
+ fn flush(&mut self) -> io::Result<()> {
+ Ok(())
+ }
+}
diff --git a/vendor/git2-curl/tests/all.rs b/vendor/git2-curl/tests/all.rs
new file mode 100644
index 000000000..c7f09dd40
--- /dev/null
+++ b/vendor/git2-curl/tests/all.rs
@@ -0,0 +1,74 @@
+use civet::{Config, Server};
+use conduit_git_http_backend as git_backend;
+use std::fs::File;
+use std::path::Path;
+use tempfile::TempDir;
+
+const PORT: u16 = 7848;
+
+fn main() {
+ unsafe {
+ git2_curl::register(curl::easy::Easy::new());
+ }
+
+ // Spin up a server for git-http-backend
+ let td = TempDir::new().unwrap();
+ let mut cfg = Config::new();
+ cfg.port(PORT).threads(1);
+ let _a = Server::start(cfg, git_backend::Serve(td.path().to_path_buf()));
+
+ // Prep a repo with one file called `foo`
+ let sig = git2::Signature::now("foo", "bar").unwrap();
+ let r1 = git2::Repository::init(td.path()).unwrap();
+ File::create(&td.path().join(".git").join("git-daemon-export-ok")).unwrap();
+ {
+ let mut index = r1.index().unwrap();
+ File::create(&td.path().join("foo")).unwrap();
+ index.add_path(Path::new("foo")).unwrap();
+ index.write().unwrap();
+ let tree_id = index.write_tree().unwrap();
+ r1.commit(
+ Some("HEAD"),
+ &sig,
+ &sig,
+ "test",
+ &r1.find_tree(tree_id).unwrap(),
+ &[],
+ )
+ .unwrap();
+ }
+
+ // Clone through the git-http-backend
+ let td2 = TempDir::new().unwrap();
+ let r = git2::Repository::clone(&format!("http://localhost:{}", PORT), td2.path()).unwrap();
+ assert!(File::open(&td2.path().join("foo")).is_ok());
+ {
+ File::create(&td.path().join("bar")).unwrap();
+ let mut index = r1.index().unwrap();
+ index.add_path(&Path::new("bar")).unwrap();
+ index.write().unwrap();
+ let tree_id = index.write_tree().unwrap();
+ let parent = r1.head().ok().and_then(|h| h.target()).unwrap();
+ let parent = r1.find_commit(parent).unwrap();
+ r1.commit(
+ Some("HEAD"),
+ &sig,
+ &sig,
+ "test",
+ &r1.find_tree(tree_id).unwrap(),
+ &[&parent],
+ )
+ .unwrap();
+ }
+
+ let mut remote = r.find_remote("origin").unwrap();
+ remote
+ .fetch(&["refs/heads/*:refs/heads/*"], None, None)
+ .unwrap();
+ let b = r.find_branch("master", git2::BranchType::Local).unwrap();
+ let id = b.get().target().unwrap();
+ let obj = r.find_object(id, None).unwrap();
+ r.reset(&obj, git2::ResetType::Hard, None).unwrap();
+
+ assert!(File::open(&td2.path().join("bar")).is_ok());
+}