Skip to content

Commit

Permalink
Merge pull request #160 from alexcrichton/update-libgit2
Browse files Browse the repository at this point in the history
Update libgit2
  • Loading branch information
alexcrichton authored Oct 4, 2016
2 parents 9faefc2 + fb9a8e6 commit 3b61e8b
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 16 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ sudo: false
before_script:
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
script:
- export CARGO_TARGET_DIR=`pwd`/target
- cargo test --no-default-features
- cargo test
- cargo run --manifest-path systest/Cargo.toml --release
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ unstable = []
default = ["ssh", "https"]
ssh = ["libgit2-sys/ssh"]
https = ["libgit2-sys/https"]

[workspace]
members = ["systest", "git2-curl"]
29 changes: 27 additions & 2 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub const GIT_MERGE_OPTIONS_VERSION: c_uint = 1;
pub const GIT_REMOTE_CALLBACKS_VERSION: c_uint = 1;
pub const GIT_STATUS_OPTIONS_VERSION: c_uint = 1;
pub const GIT_BLAME_OPTIONS_VERSION: c_uint = 1;
pub const GIT_PROXY_OPTIONS_VERSION: c_uint = 1;

macro_rules! git_enum {
(pub enum $name:ident { $($variants:tt)* }) => {
Expand Down Expand Up @@ -329,6 +330,7 @@ pub struct git_fetch_options {
pub prune: git_fetch_prune_t,
pub update_fetchhead: c_int,
pub download_tags: git_remote_autotag_option_t,
pub proxy_opts: git_proxy_options,
pub custom_headers: git_strarray,
}

Expand Down Expand Up @@ -838,6 +840,7 @@ pub struct git_push_options {
pub version: c_uint,
pub pb_parallelism: c_uint,
pub callbacks: git_remote_callbacks,
pub proxy_opts: git_proxy_options,
pub custom_headers: git_strarray,
}

Expand Down Expand Up @@ -1119,6 +1122,7 @@ pub const GIT_DIFF_FIND_REMOVE_UNMODIFIED: u32 = 1 << 16;

#[repr(C)]
pub struct git_diff_binary {
pub contains_data: c_uint,
pub old_file: git_diff_binary_file,
pub new_file: git_diff_binary_file,
}
Expand Down Expand Up @@ -1147,6 +1151,7 @@ pub struct git_merge_options {
pub target_limit: c_uint,
pub metric: *mut git_diff_similarity_metric,
pub recursion_limit: c_uint,
pub default_driver: *const c_char,
pub file_favor: git_merge_file_favor_t,
pub file_flags: git_merge_file_flag_t,
}
Expand Down Expand Up @@ -1201,6 +1206,7 @@ pub struct git_transport {
*const c_char,
git_cred_acquire_cb,
*mut c_void,
*const git_proxy_options,
c_int, c_int) -> c_int,
pub ls: extern fn(*mut *mut *const git_remote_head,
*mut size_t,
Expand All @@ -1224,6 +1230,24 @@ pub struct git_transport {
pub free: extern fn(*mut git_transport),
}

#[repr(C)]
pub struct git_proxy_options {
pub version: c_uint,
pub kind: git_proxy_t,
pub url: *const c_char,
pub credentials: Option<git_cred_acquire_cb>,
pub certificate_check: Option<git_transport_certificate_check_cb>,
pub payload: *mut c_void,
}

git_enum! {
pub enum git_proxy_t {
GIT_PROXY_NONE = 0,
GIT_PROXY_AUTO = 1,
GIT_PROXY_SPECIFIED = 2,
}
}

git_enum! {
pub enum git_smart_service_t {
GIT_SERVICE_UPLOADPACK_LS = 1,
Expand Down Expand Up @@ -1547,6 +1571,7 @@ extern {
pub fn git_remote_connect(remote: *mut git_remote,
dir: git_direction,
callbacks: *const git_remote_callbacks,
proxy_opts: *const git_proxy_options,
custom_headers: *const git_strarray) -> c_int;
pub fn git_remote_connected(remote: *const git_remote) -> c_int;
pub fn git_remote_disconnect(remote: *mut git_remote);
Expand Down Expand Up @@ -2546,8 +2571,8 @@ extern {
pub fn git_packbuilder_foreach(pb: *mut git_packbuilder,
cb: git_packbuilder_foreach_cb,
payload: *mut c_void) -> c_int;
pub fn git_packbuilder_object_count(pb: *mut git_packbuilder) -> u32;
pub fn git_packbuilder_written(pb: *mut git_packbuilder) -> u32;
pub fn git_packbuilder_object_count(pb: *mut git_packbuilder) -> size_t;
pub fn git_packbuilder_written(pb: *mut git_packbuilder) -> size_t;
pub fn git_packbuilder_set_callbacks(pb: *mut git_packbuilder,
progress_cb: Option<git_packbuilder_progress>,
progress_cb_payload: *mut c_void) -> c_int;
Expand Down
2 changes: 1 addition & 1 deletion libgit2-sys/libgit2
Submodule libgit2 updated 524 files
12 changes: 11 additions & 1 deletion src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,16 @@ impl Drop for DiffStats {
}

impl<'a> DiffBinary<'a> {
/// Returns whether there is data in this binary structure or not.
///
/// If this is `true`, then this was produced and included binary content.
/// If this is `false` then this was generated knowing only that a binary
/// file changed but without providing the data, probably from a patch that
/// said `Binary files a/file.txt and b/file.txt differ`.
pub fn contains_data(&self) -> bool {
unsafe { (*self.raw).contains_data == 1 }
}

/// The contents of the old file.
pub fn old_file(&self) -> DiffBinaryFile<'a> {
unsafe { Binding::from_raw(&(*self.raw).old_file as *const _) }
Expand Down Expand Up @@ -1195,7 +1205,7 @@ mod tests {
t!(index.add_path(foo_path));
t!(index.add_path(bin_path));
let mut opts = DiffOptions::new();
opts.include_untracked(true);
opts.include_untracked(true).show_binary(true);
let diff = t!(repo.diff_tree_to_index(None, Some(&index),
Some(&mut opts)));
let mut bin_content = None;
Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,19 @@ pub use config::{Config, ConfigEntry, ConfigEntries};
pub use cred::{Cred, CredentialHelper};
pub use describe::{Describe, DescribeFormatOptions, DescribeOptions};
pub use diff::{Diff, DiffDelta, DiffFile, DiffOptions, Deltas};
pub use diff::{DiffLine, DiffHunk, DiffStats, DiffFindOptions};
pub use diff::{DiffBinary, DiffBinaryFile, DiffBinaryKind};
pub use merge::{AnnotatedCommit, MergeOptions};
pub use diff::{DiffLine, DiffHunk, DiffStats, DiffFindOptions};
pub use error::Error;
pub use index::{Index, IndexEntry, IndexEntries, IndexMatchedPath};
pub use merge::{AnnotatedCommit, MergeOptions};
pub use message::{message_prettify, DEFAULT_COMMENT_CHAR};
pub use note::{Note, Notes};
pub use object::Object;
pub use oid::Oid;
pub use packbuilder::{PackBuilder, PackBuilderStage};
pub use pathspec::{Pathspec, PathspecMatchList, PathspecFailedEntries};
pub use pathspec::{PathspecDiffEntries, PathspecEntries};
pub use proxy_options::ProxyOptions;
pub use reference::{Reference, References, ReferenceNames};
pub use reflog::{Reflog, ReflogEntry, ReflogIter};
pub use refspec::Refspec;
Expand Down Expand Up @@ -494,15 +495,16 @@ mod config;
mod cred;
mod describe;
mod diff;
mod merge;
mod error;
mod index;
mod merge;
mod message;
mod note;
mod object;
mod oid;
mod packbuilder;
mod pathspec;
mod proxy_options;
mod reference;
mod reflog;
mod refspec;
Expand Down
4 changes: 2 additions & 2 deletions src/packbuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ impl<'repo> PackBuilder<'repo> {

/// Get the total number of objects the packbuilder will write out.
pub fn object_count(&self) -> usize {
unsafe { raw::git_packbuilder_object_count(self.raw) as usize }
unsafe { raw::git_packbuilder_object_count(self.raw) }
}

/// Get the number of objects the packbuilder has already written out.
pub fn written(&self) -> usize {
unsafe { raw::git_packbuilder_written(self.raw) as usize }
unsafe { raw::git_packbuilder_written(self.raw) }
}

/// Get the packfile's hash. A packfile's name is derived from the sorted
Expand Down
58 changes: 58 additions & 0 deletions src/proxy_options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use std::ffi::CString;
use std::marker;

use raw;
use util::Binding;

/// Options which can be specified to various fetch operations.
pub struct ProxyOptions<'a> {
url: Option<CString>,
proxy_kind: raw::git_proxy_t,
_marker: marker::PhantomData<&'a i32>,
}

impl<'a> ProxyOptions<'a> {
/// Creates a new set of proxy options ready to be configured.
pub fn new() -> ProxyOptions<'a> {
ProxyOptions {
url: None,
proxy_kind: raw::GIT_PROXY_NONE,
_marker: marker::PhantomData,
}
}

/// Try to auto-detect the proxy from the git configuration.
///
/// Note that this will override `url` specified before.
pub fn auto(&mut self) -> &mut Self {
self.proxy_kind = raw::GIT_PROXY_AUTO;
self
}

/// Specify the exact URL of the proxy to use.
///
/// Note that this will override `auto` specified before.
pub fn url(&mut self, url: &str) -> &mut Self {
self.proxy_kind = raw::GIT_PROXY_SPECIFIED;
self.url = Some(CString::new(url).unwrap());
self
}
}

impl<'a> Binding for ProxyOptions<'a> {
type Raw = raw::git_proxy_options;
unsafe fn from_raw(_raw: raw::git_proxy_options) -> ProxyOptions<'a> {
panic!("can't create proxy from raw options")
}

fn raw(&self) -> raw::git_proxy_options {
raw::git_proxy_options {
version: raw::GIT_PROXY_OPTIONS_VERSION,
kind: self.proxy_kind,
url: self.url.as_ref().map(|s| s.as_ptr()).unwrap_or(0 as *const _),
credentials: None,
certificate_check: None,
payload: 0 as *mut _,
}
}
}
23 changes: 22 additions & 1 deletion src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::slice;
use std::str;
use libc;

use {raw, Direction, Error, Refspec, Oid, FetchPrune};
use {raw, Direction, Error, Refspec, Oid, FetchPrune, ProxyOptions};
use {RemoteCallbacks, Progress, Repository, AutotagOption};
use util::Binding;

Expand Down Expand Up @@ -37,6 +37,7 @@ pub struct RemoteHead<'remote> {
/// Options which can be specified to various fetch operations.
pub struct FetchOptions<'cb> {
callbacks: Option<RemoteCallbacks<'cb>>,
proxy: Option<ProxyOptions<'cb>>,
prune: FetchPrune,
update_fetchhead: bool,
download_tags: AutotagOption,
Expand All @@ -45,6 +46,7 @@ pub struct FetchOptions<'cb> {
/// Options to control the behavior of a git push.
pub struct PushOptions<'cb> {
callbacks: Option<RemoteCallbacks<'cb>>,
proxy: Option<ProxyOptions<'cb>>,
pb_parallelism: u32,
}

Expand Down Expand Up @@ -100,6 +102,7 @@ impl<'repo> Remote<'repo> {
// TODO: can callbacks be exposed safely?
unsafe {
try_call!(raw::git_remote_connect(self.raw, dir,
0 as *const _,
0 as *const _,
0 as *const _));
}
Expand Down Expand Up @@ -304,6 +307,7 @@ impl<'cb> FetchOptions<'cb> {
pub fn new() -> FetchOptions<'cb> {
FetchOptions {
callbacks: None,
proxy: None,
prune: FetchPrune::Unspecified,
update_fetchhead: true,
download_tags: AutotagOption::Unspecified,
Expand All @@ -316,6 +320,12 @@ impl<'cb> FetchOptions<'cb> {
self
}

/// Set the proxy options to use for the fetch operation.
pub fn proxy_options(&mut self, opts: ProxyOptions<'cb>) -> &mut Self {
self.proxy = Some(opts);
self
}

/// Set whether to perform a prune after the fetch.
pub fn prune(&mut self, prune: FetchPrune) -> &mut Self {
self.prune = prune;
Expand Down Expand Up @@ -351,6 +361,8 @@ impl<'cb> Binding for FetchOptions<'cb> {
version: 1,
callbacks: self.callbacks.as_ref().map(|m| m.raw())
.unwrap_or_else(|| RemoteCallbacks::new().raw()),
proxy_opts: self.proxy.as_ref().map(|m| m.raw())
.unwrap_or_else(|| ProxyOptions::new().raw()),
prune: ::call::convert(&self.prune),
update_fetchhead: ::call::convert(&self.update_fetchhead),
download_tags: ::call::convert(&self.download_tags),
Expand All @@ -368,6 +380,7 @@ impl<'cb> PushOptions<'cb> {
pub fn new() -> PushOptions<'cb> {
PushOptions {
callbacks: None,
proxy: None,
pb_parallelism: 1,
}
}
Expand All @@ -378,6 +391,12 @@ impl<'cb> PushOptions<'cb> {
self
}

/// Set the proxy options to use for the fetch operation.
pub fn proxy_options(&mut self, opts: ProxyOptions<'cb>) -> &mut Self {
self.proxy = Some(opts);
self
}

/// If the transport being used to push to the remote requires the creation
/// of a pack file, this controls the number of worker threads used by the
/// packbuilder when creating that pack file to be sent to the remote.
Expand All @@ -401,6 +420,8 @@ impl<'cb> Binding for PushOptions<'cb> {
version: 1,
callbacks: self.callbacks.as_ref().map(|m| m.raw())
.unwrap_or(RemoteCallbacks::new().raw()),
proxy_opts: self.proxy.as_ref().map(|m| m.raw())
.unwrap_or_else(|| ProxyOptions::new().raw()),
pb_parallelism: self.pb_parallelism as libc::c_uint,
// TODO: expose this as a builder option
custom_headers: raw::git_strarray {
Expand Down
14 changes: 9 additions & 5 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ impl Repository {
pub fn open_ext<P, O, I>(path: P,
flags: RepositoryOpenFlags,
ceiling_dirs: I)
-> Result<Repository, Error>
where P: AsRef<Path>, O: AsRef<OsStr>, I: IntoIterator<Item=O> {
-> Result<Repository, Error>
where P: AsRef<Path>, O: AsRef<OsStr>, I: IntoIterator<Item=O>
{
init();
let path = try!(path.as_ref().into_c_string());
let ceiling_dirs_os = try!(env::join_paths(ceiling_dirs));
Expand Down Expand Up @@ -1967,8 +1968,9 @@ mod tests {
let err = Repository::open_ext(&subdir, ::REPOSITORY_OPEN_NO_SEARCH, &[] as &[&OsStr]).err().unwrap();
assert_eq!(err.code(), ::ErrorCode::NotFound);

let err = Repository::open_ext(&subdir, ::RepositoryOpenFlags::empty(), &[&subdir]).err().unwrap();
assert_eq!(err.code(), ::ErrorCode::NotFound);
assert!(Repository::open_ext(&subdir,
::RepositoryOpenFlags::empty(),
&[&subdir]).is_ok());
}

fn graph_repo_init() -> (TempDir, Repository) {
Expand Down Expand Up @@ -2086,6 +2088,8 @@ mod tests {
let commit2 = repo.find_commit(oid2).unwrap();
println!("created oid2 {:?}", oid2);

t!(repo.reset(commit1.as_object(), ResetType::Hard, None));

// create commit oid3 on branchB
let mut index = repo.index().unwrap();
let p = Path::new(repo.workdir().unwrap()).join("file_b");
Expand Down Expand Up @@ -2134,7 +2138,7 @@ mod tests {
}
assert!(found_oid2);
assert!(found_oid3);
assert_eq!(merge_bases.len(), 2);
assert_eq!(merge_bases.len(), 2);
}

#[test]
Expand Down

0 comments on commit 3b61e8b

Please sign in to comment.