Skip to content

Commit 3b61e8b

Browse files
authored
Merge pull request #160 from alexcrichton/update-libgit2
Update libgit2
2 parents 9faefc2 + fb9a8e6 commit 3b61e8b

File tree

10 files changed

+138
-16
lines changed

10 files changed

+138
-16
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ sudo: false
77
before_script:
88
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
99
script:
10-
- export CARGO_TARGET_DIR=`pwd`/target
1110
- cargo test --no-default-features
1211
- cargo test
1312
- cargo run --manifest-path systest/Cargo.toml --release

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ unstable = []
3232
default = ["ssh", "https"]
3333
ssh = ["libgit2-sys/ssh"]
3434
https = ["libgit2-sys/https"]
35+
36+
[workspace]
37+
members = ["systest", "git2-curl"]

libgit2-sys/lib.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub const GIT_MERGE_OPTIONS_VERSION: c_uint = 1;
1818
pub const GIT_REMOTE_CALLBACKS_VERSION: c_uint = 1;
1919
pub const GIT_STATUS_OPTIONS_VERSION: c_uint = 1;
2020
pub const GIT_BLAME_OPTIONS_VERSION: c_uint = 1;
21+
pub const GIT_PROXY_OPTIONS_VERSION: c_uint = 1;
2122

2223
macro_rules! git_enum {
2324
(pub enum $name:ident { $($variants:tt)* }) => {
@@ -329,6 +330,7 @@ pub struct git_fetch_options {
329330
pub prune: git_fetch_prune_t,
330331
pub update_fetchhead: c_int,
331332
pub download_tags: git_remote_autotag_option_t,
333+
pub proxy_opts: git_proxy_options,
332334
pub custom_headers: git_strarray,
333335
}
334336

@@ -838,6 +840,7 @@ pub struct git_push_options {
838840
pub version: c_uint,
839841
pub pb_parallelism: c_uint,
840842
pub callbacks: git_remote_callbacks,
843+
pub proxy_opts: git_proxy_options,
841844
pub custom_headers: git_strarray,
842845
}
843846

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

11201123
#[repr(C)]
11211124
pub struct git_diff_binary {
1125+
pub contains_data: c_uint,
11221126
pub old_file: git_diff_binary_file,
11231127
pub new_file: git_diff_binary_file,
11241128
}
@@ -1147,6 +1151,7 @@ pub struct git_merge_options {
11471151
pub target_limit: c_uint,
11481152
pub metric: *mut git_diff_similarity_metric,
11491153
pub recursion_limit: c_uint,
1154+
pub default_driver: *const c_char,
11501155
pub file_favor: git_merge_file_favor_t,
11511156
pub file_flags: git_merge_file_flag_t,
11521157
}
@@ -1201,6 +1206,7 @@ pub struct git_transport {
12011206
*const c_char,
12021207
git_cred_acquire_cb,
12031208
*mut c_void,
1209+
*const git_proxy_options,
12041210
c_int, c_int) -> c_int,
12051211
pub ls: extern fn(*mut *mut *const git_remote_head,
12061212
*mut size_t,
@@ -1224,6 +1230,24 @@ pub struct git_transport {
12241230
pub free: extern fn(*mut git_transport),
12251231
}
12261232

1233+
#[repr(C)]
1234+
pub struct git_proxy_options {
1235+
pub version: c_uint,
1236+
pub kind: git_proxy_t,
1237+
pub url: *const c_char,
1238+
pub credentials: Option<git_cred_acquire_cb>,
1239+
pub certificate_check: Option<git_transport_certificate_check_cb>,
1240+
pub payload: *mut c_void,
1241+
}
1242+
1243+
git_enum! {
1244+
pub enum git_proxy_t {
1245+
GIT_PROXY_NONE = 0,
1246+
GIT_PROXY_AUTO = 1,
1247+
GIT_PROXY_SPECIFIED = 2,
1248+
}
1249+
}
1250+
12271251
git_enum! {
12281252
pub enum git_smart_service_t {
12291253
GIT_SERVICE_UPLOADPACK_LS = 1,
@@ -1547,6 +1571,7 @@ extern {
15471571
pub fn git_remote_connect(remote: *mut git_remote,
15481572
dir: git_direction,
15491573
callbacks: *const git_remote_callbacks,
1574+
proxy_opts: *const git_proxy_options,
15501575
custom_headers: *const git_strarray) -> c_int;
15511576
pub fn git_remote_connected(remote: *const git_remote) -> c_int;
15521577
pub fn git_remote_disconnect(remote: *mut git_remote);
@@ -2546,8 +2571,8 @@ extern {
25462571
pub fn git_packbuilder_foreach(pb: *mut git_packbuilder,
25472572
cb: git_packbuilder_foreach_cb,
25482573
payload: *mut c_void) -> c_int;
2549-
pub fn git_packbuilder_object_count(pb: *mut git_packbuilder) -> u32;
2550-
pub fn git_packbuilder_written(pb: *mut git_packbuilder) -> u32;
2574+
pub fn git_packbuilder_object_count(pb: *mut git_packbuilder) -> size_t;
2575+
pub fn git_packbuilder_written(pb: *mut git_packbuilder) -> size_t;
25512576
pub fn git_packbuilder_set_callbacks(pb: *mut git_packbuilder,
25522577
progress_cb: Option<git_packbuilder_progress>,
25532578
progress_cb_payload: *mut c_void) -> c_int;

libgit2-sys/libgit2

Submodule libgit2 updated 524 files

src/diff.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,16 @@ impl Drop for DiffStats {
873873
}
874874

875875
impl<'a> DiffBinary<'a> {
876+
/// Returns whether there is data in this binary structure or not.
877+
///
878+
/// If this is `true`, then this was produced and included binary content.
879+
/// If this is `false` then this was generated knowing only that a binary
880+
/// file changed but without providing the data, probably from a patch that
881+
/// said `Binary files a/file.txt and b/file.txt differ`.
882+
pub fn contains_data(&self) -> bool {
883+
unsafe { (*self.raw).contains_data == 1 }
884+
}
885+
876886
/// The contents of the old file.
877887
pub fn old_file(&self) -> DiffBinaryFile<'a> {
878888
unsafe { Binding::from_raw(&(*self.raw).old_file as *const _) }
@@ -1195,7 +1205,7 @@ mod tests {
11951205
t!(index.add_path(foo_path));
11961206
t!(index.add_path(bin_path));
11971207
let mut opts = DiffOptions::new();
1198-
opts.include_untracked(true);
1208+
opts.include_untracked(true).show_binary(true);
11991209
let diff = t!(repo.diff_tree_to_index(None, Some(&index),
12001210
Some(&mut opts)));
12011211
let mut bin_content = None;

src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,19 @@ pub use config::{Config, ConfigEntry, ConfigEntries};
8888
pub use cred::{Cred, CredentialHelper};
8989
pub use describe::{Describe, DescribeFormatOptions, DescribeOptions};
9090
pub use diff::{Diff, DiffDelta, DiffFile, DiffOptions, Deltas};
91-
pub use diff::{DiffLine, DiffHunk, DiffStats, DiffFindOptions};
9291
pub use diff::{DiffBinary, DiffBinaryFile, DiffBinaryKind};
93-
pub use merge::{AnnotatedCommit, MergeOptions};
92+
pub use diff::{DiffLine, DiffHunk, DiffStats, DiffFindOptions};
9493
pub use error::Error;
9594
pub use index::{Index, IndexEntry, IndexEntries, IndexMatchedPath};
95+
pub use merge::{AnnotatedCommit, MergeOptions};
9696
pub use message::{message_prettify, DEFAULT_COMMENT_CHAR};
9797
pub use note::{Note, Notes};
9898
pub use object::Object;
9999
pub use oid::Oid;
100100
pub use packbuilder::{PackBuilder, PackBuilderStage};
101101
pub use pathspec::{Pathspec, PathspecMatchList, PathspecFailedEntries};
102102
pub use pathspec::{PathspecDiffEntries, PathspecEntries};
103+
pub use proxy_options::ProxyOptions;
103104
pub use reference::{Reference, References, ReferenceNames};
104105
pub use reflog::{Reflog, ReflogEntry, ReflogIter};
105106
pub use refspec::Refspec;
@@ -494,15 +495,16 @@ mod config;
494495
mod cred;
495496
mod describe;
496497
mod diff;
497-
mod merge;
498498
mod error;
499499
mod index;
500+
mod merge;
500501
mod message;
501502
mod note;
502503
mod object;
503504
mod oid;
504505
mod packbuilder;
505506
mod pathspec;
507+
mod proxy_options;
506508
mod reference;
507509
mod reflog;
508510
mod refspec;

src/packbuilder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,12 @@ impl<'repo> PackBuilder<'repo> {
136136

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

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

147147
/// Get the packfile's hash. A packfile's name is derived from the sorted

src/proxy_options.rs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
use std::ffi::CString;
2+
use std::marker;
3+
4+
use raw;
5+
use util::Binding;
6+
7+
/// Options which can be specified to various fetch operations.
8+
pub struct ProxyOptions<'a> {
9+
url: Option<CString>,
10+
proxy_kind: raw::git_proxy_t,
11+
_marker: marker::PhantomData<&'a i32>,
12+
}
13+
14+
impl<'a> ProxyOptions<'a> {
15+
/// Creates a new set of proxy options ready to be configured.
16+
pub fn new() -> ProxyOptions<'a> {
17+
ProxyOptions {
18+
url: None,
19+
proxy_kind: raw::GIT_PROXY_NONE,
20+
_marker: marker::PhantomData,
21+
}
22+
}
23+
24+
/// Try to auto-detect the proxy from the git configuration.
25+
///
26+
/// Note that this will override `url` specified before.
27+
pub fn auto(&mut self) -> &mut Self {
28+
self.proxy_kind = raw::GIT_PROXY_AUTO;
29+
self
30+
}
31+
32+
/// Specify the exact URL of the proxy to use.
33+
///
34+
/// Note that this will override `auto` specified before.
35+
pub fn url(&mut self, url: &str) -> &mut Self {
36+
self.proxy_kind = raw::GIT_PROXY_SPECIFIED;
37+
self.url = Some(CString::new(url).unwrap());
38+
self
39+
}
40+
}
41+
42+
impl<'a> Binding for ProxyOptions<'a> {
43+
type Raw = raw::git_proxy_options;
44+
unsafe fn from_raw(_raw: raw::git_proxy_options) -> ProxyOptions<'a> {
45+
panic!("can't create proxy from raw options")
46+
}
47+
48+
fn raw(&self) -> raw::git_proxy_options {
49+
raw::git_proxy_options {
50+
version: raw::GIT_PROXY_OPTIONS_VERSION,
51+
kind: self.proxy_kind,
52+
url: self.url.as_ref().map(|s| s.as_ptr()).unwrap_or(0 as *const _),
53+
credentials: None,
54+
certificate_check: None,
55+
payload: 0 as *mut _,
56+
}
57+
}
58+
}

src/remote.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::slice;
66
use std::str;
77
use libc;
88

9-
use {raw, Direction, Error, Refspec, Oid, FetchPrune};
9+
use {raw, Direction, Error, Refspec, Oid, FetchPrune, ProxyOptions};
1010
use {RemoteCallbacks, Progress, Repository, AutotagOption};
1111
use util::Binding;
1212

@@ -37,6 +37,7 @@ pub struct RemoteHead<'remote> {
3737
/// Options which can be specified to various fetch operations.
3838
pub struct FetchOptions<'cb> {
3939
callbacks: Option<RemoteCallbacks<'cb>>,
40+
proxy: Option<ProxyOptions<'cb>>,
4041
prune: FetchPrune,
4142
update_fetchhead: bool,
4243
download_tags: AutotagOption,
@@ -45,6 +46,7 @@ pub struct FetchOptions<'cb> {
4546
/// Options to control the behavior of a git push.
4647
pub struct PushOptions<'cb> {
4748
callbacks: Option<RemoteCallbacks<'cb>>,
49+
proxy: Option<ProxyOptions<'cb>>,
4850
pb_parallelism: u32,
4951
}
5052

@@ -100,6 +102,7 @@ impl<'repo> Remote<'repo> {
100102
// TODO: can callbacks be exposed safely?
101103
unsafe {
102104
try_call!(raw::git_remote_connect(self.raw, dir,
105+
0 as *const _,
103106
0 as *const _,
104107
0 as *const _));
105108
}
@@ -304,6 +307,7 @@ impl<'cb> FetchOptions<'cb> {
304307
pub fn new() -> FetchOptions<'cb> {
305308
FetchOptions {
306309
callbacks: None,
310+
proxy: None,
307311
prune: FetchPrune::Unspecified,
308312
update_fetchhead: true,
309313
download_tags: AutotagOption::Unspecified,
@@ -316,6 +320,12 @@ impl<'cb> FetchOptions<'cb> {
316320
self
317321
}
318322

323+
/// Set the proxy options to use for the fetch operation.
324+
pub fn proxy_options(&mut self, opts: ProxyOptions<'cb>) -> &mut Self {
325+
self.proxy = Some(opts);
326+
self
327+
}
328+
319329
/// Set whether to perform a prune after the fetch.
320330
pub fn prune(&mut self, prune: FetchPrune) -> &mut Self {
321331
self.prune = prune;
@@ -351,6 +361,8 @@ impl<'cb> Binding for FetchOptions<'cb> {
351361
version: 1,
352362
callbacks: self.callbacks.as_ref().map(|m| m.raw())
353363
.unwrap_or_else(|| RemoteCallbacks::new().raw()),
364+
proxy_opts: self.proxy.as_ref().map(|m| m.raw())
365+
.unwrap_or_else(|| ProxyOptions::new().raw()),
354366
prune: ::call::convert(&self.prune),
355367
update_fetchhead: ::call::convert(&self.update_fetchhead),
356368
download_tags: ::call::convert(&self.download_tags),
@@ -368,6 +380,7 @@ impl<'cb> PushOptions<'cb> {
368380
pub fn new() -> PushOptions<'cb> {
369381
PushOptions {
370382
callbacks: None,
383+
proxy: None,
371384
pb_parallelism: 1,
372385
}
373386
}
@@ -378,6 +391,12 @@ impl<'cb> PushOptions<'cb> {
378391
self
379392
}
380393

394+
/// Set the proxy options to use for the fetch operation.
395+
pub fn proxy_options(&mut self, opts: ProxyOptions<'cb>) -> &mut Self {
396+
self.proxy = Some(opts);
397+
self
398+
}
399+
381400
/// If the transport being used to push to the remote requires the creation
382401
/// of a pack file, this controls the number of worker threads used by the
383402
/// packbuilder when creating that pack file to be sent to the remote.
@@ -401,6 +420,8 @@ impl<'cb> Binding for PushOptions<'cb> {
401420
version: 1,
402421
callbacks: self.callbacks.as_ref().map(|m| m.raw())
403422
.unwrap_or(RemoteCallbacks::new().raw()),
423+
proxy_opts: self.proxy.as_ref().map(|m| m.raw())
424+
.unwrap_or_else(|| ProxyOptions::new().raw()),
404425
pb_parallelism: self.pb_parallelism as libc::c_uint,
405426
// TODO: expose this as a builder option
406427
custom_headers: raw::git_strarray {

src/repo.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ impl Repository {
8181
pub fn open_ext<P, O, I>(path: P,
8282
flags: RepositoryOpenFlags,
8383
ceiling_dirs: I)
84-
-> Result<Repository, Error>
85-
where P: AsRef<Path>, O: AsRef<OsStr>, I: IntoIterator<Item=O> {
84+
-> Result<Repository, Error>
85+
where P: AsRef<Path>, O: AsRef<OsStr>, I: IntoIterator<Item=O>
86+
{
8687
init();
8788
let path = try!(path.as_ref().into_c_string());
8889
let ceiling_dirs_os = try!(env::join_paths(ceiling_dirs));
@@ -1967,8 +1968,9 @@ mod tests {
19671968
let err = Repository::open_ext(&subdir, ::REPOSITORY_OPEN_NO_SEARCH, &[] as &[&OsStr]).err().unwrap();
19681969
assert_eq!(err.code(), ::ErrorCode::NotFound);
19691970

1970-
let err = Repository::open_ext(&subdir, ::RepositoryOpenFlags::empty(), &[&subdir]).err().unwrap();
1971-
assert_eq!(err.code(), ::ErrorCode::NotFound);
1971+
assert!(Repository::open_ext(&subdir,
1972+
::RepositoryOpenFlags::empty(),
1973+
&[&subdir]).is_ok());
19721974
}
19731975

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

2091+
t!(repo.reset(commit1.as_object(), ResetType::Hard, None));
2092+
20892093
// create commit oid3 on branchB
20902094
let mut index = repo.index().unwrap();
20912095
let p = Path::new(repo.workdir().unwrap()).join("file_b");
@@ -2134,7 +2138,7 @@ mod tests {
21342138
}
21352139
assert!(found_oid2);
21362140
assert!(found_oid3);
2137-
assert_eq!(merge_bases.len(), 2);
2141+
assert_eq!(merge_bases.len(), 2);
21382142
}
21392143

21402144
#[test]

0 commit comments

Comments
 (0)