diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 30d91e4456..97ba7a8d47 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,6 +28,8 @@ jobs: rust: stable steps: - uses: actions/checkout@master + with: + submodules: true - name: Install Rust (rustup) run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }} shell: bash diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a8fa16637d..eb3b578f1a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,6 +24,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master + with: + submodules: true - name: Publish env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cc0d7396c..efdcfcace5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## 0.18.1 - 2023-09-20 +[0.18.0...0.18.1](https://github.com/rust-lang/git2-rs/compare/git2-0.18.0...git2-0.18.1) + +### Added + +- Added `FetchOptions::depth` to set the depth of a fetch or clone, adding support for shallow clones. + [#979](https://github.com/rust-lang/git2-rs/pull/979) + +### Fixed + +- Fixed an internal data type (`TreeWalkCbData`) to not assume it is a transparent type while casting. + [#989](https://github.com/rust-lang/git2-rs/pull/989) +- Fixed so that `DiffPatchidOptions` and `StashSaveOptions` are publicly exported allowing the corresponding APIs to actually be used. + [#988](https://github.com/rust-lang/git2-rs/pull/988) + ## 0.18.0 - 2023-08-28 [0.17.2...0.18.0](https://github.com/rust-lang/git2-rs/compare/0.17.2...git2-0.18.0) diff --git a/Cargo.toml b/Cargo.toml index 3cd87eb69d..316e28b0fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "git2" -version = "0.18.0" +version = "0.18.1" authors = ["Josh Triplett ", "Alex Crichton "] license = "MIT OR Apache-2.0" readme = "README.md" diff --git a/README.md b/README.md index e10fbcbdb4..ba75127acc 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ libgit2 bindings for Rust. ```toml [dependencies] -git2 = "0.18.0" +git2 = "0.18.1" ``` ## Rust version requirements diff --git a/libgit2-sys/CHANGELOG.md b/libgit2-sys/CHANGELOG.md index 3b653bf6a4..5f159825f5 100644 --- a/libgit2-sys/CHANGELOG.md +++ b/libgit2-sys/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 0.16.1+1.7.1 - 2023-08-28 +[0.16.0...0.16.1](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.16.0+1.7.1...libgit2-sys-0.16.1+1.7.1) + +### Fixed + +- Fixed publish of 0.16.0 missing the libgit2 submodule. + ## 0.16.0+1.7.1 - 2023-08-28 [0.15.2...0.16.0](https://github.com/rust-lang/git2-rs/compare/libgit2-sys-0.15.2+1.6.4...libgit2-sys-0.16.0+1.7.1) diff --git a/libgit2-sys/Cargo.toml b/libgit2-sys/Cargo.toml index fd2eacc84d..78888b9ee6 100644 --- a/libgit2-sys/Cargo.toml +++ b/libgit2-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libgit2-sys" -version = "0.16.0+1.7.1" +version = "0.16.1+1.7.1" authors = ["Josh Triplett ", "Alex Crichton "] links = "git2" build = "build.rs" diff --git a/src/lib.rs b/src/lib.rs index 6dd75093b9..3dd6fe92ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,7 +91,7 @@ pub use crate::config::{Config, ConfigEntries, ConfigEntry}; pub use crate::cred::{Cred, CredentialHelper}; pub use crate::describe::{Describe, DescribeFormatOptions, DescribeOptions}; pub use crate::diff::{Deltas, Diff, DiffDelta, DiffFile, DiffOptions}; -pub use crate::diff::{DiffBinary, DiffBinaryFile, DiffBinaryKind}; +pub use crate::diff::{DiffBinary, DiffBinaryFile, DiffBinaryKind, DiffPatchidOptions}; pub use crate::diff::{DiffFindOptions, DiffHunk, DiffLine, DiffLineType, DiffStats}; pub use crate::email::{Email, EmailCreateOptions}; pub use crate::error::Error; @@ -131,7 +131,7 @@ pub use crate::revert::RevertOptions; pub use crate::revspec::Revspec; pub use crate::revwalk::Revwalk; pub use crate::signature::Signature; -pub use crate::stash::{StashApplyOptions, StashApplyProgressCb, StashCb}; +pub use crate::stash::{StashApplyOptions, StashApplyProgressCb, StashCb, StashSaveOptions}; pub use crate::status::{StatusEntry, StatusIter, StatusOptions, StatusShow, Statuses}; pub use crate::submodule::{Submodule, SubmoduleUpdateOptions}; pub use crate::tag::Tag; diff --git a/src/remote.rs b/src/remote.rs index f36db6844b..c8f5a935a6 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -41,6 +41,7 @@ pub struct RemoteHead<'remote> { /// Options which can be specified to various fetch operations. pub struct FetchOptions<'cb> { callbacks: Option>, + depth: i32, proxy: Option>, prune: FetchPrune, update_fetchhead: bool, @@ -509,6 +510,7 @@ impl<'cb> FetchOptions<'cb> { follow_redirects: RemoteRedirect::Initial, custom_headers: Vec::new(), custom_headers_ptrs: Vec::new(), + depth: 0, // Not limited depth } } @@ -538,6 +540,17 @@ impl<'cb> FetchOptions<'cb> { self } + /// Set fetch depth, a value less or equal to 0 is interpreted as pull + /// everything (effectively the same as not declaring a limit depth). + + // FIXME(blyxyas): We currently don't have a test for shallow functions + // because libgit2 doesn't support local shallow clones. + // https://github.com/rust-lang/git2-rs/pull/979#issuecomment-1716299900 + pub fn depth(&mut self, depth: i32) -> &mut Self { + self.depth = depth.max(0); + self + } + /// Set how to behave regarding tags on the remote, such as auto-downloading /// tags for objects we're downloading or downloading all of them. /// @@ -590,7 +603,7 @@ impl<'cb> Binding for FetchOptions<'cb> { prune: crate::call::convert(&self.prune), update_fetchhead: crate::call::convert(&self.update_fetchhead), download_tags: crate::call::convert(&self.download_tags), - depth: 0, // GIT_FETCH_DEPTH_FULL. + depth: self.depth, follow_redirects: self.follow_redirects.raw(), custom_headers: git_strarray { count: self.custom_headers_ptrs.len(), diff --git a/src/stash.rs b/src/stash.rs index 6fcd525d2e..ea898e46ba 100644 --- a/src/stash.rs +++ b/src/stash.rs @@ -5,7 +5,6 @@ use libc::{c_char, c_int, c_void, size_t}; use std::ffi::{c_uint, CStr, CString}; use std::mem; -#[allow(unused)] /// Stash application options structure pub struct StashSaveOptions<'a> { message: Option, @@ -72,13 +71,14 @@ impl<'a> StashSaveOptions<'a> { /// /// Return `true` to continue processing, or `false` to /// abort the stash application. +// FIXME: This probably should have been pub(crate) since it is not used anywhere. pub type StashApplyProgressCb<'a> = dyn FnMut(StashApplyProgress) -> bool + 'a; /// This is a callback function you can provide to iterate over all the /// stashed states that will be invoked per entry. +// FIXME: This probably should have been pub(crate) since it is not used anywhere. pub type StashCb<'a> = dyn FnMut(usize, &str, &Oid) -> bool + 'a; -#[allow(unused)] /// Stash application options structure pub struct StashApplyOptions<'cb> { progress: Option>>, @@ -144,22 +144,20 @@ impl<'cb> StashApplyOptions<'cb> { } } -#[allow(unused)] -pub struct StashCbData<'a> { +pub(crate) struct StashCbData<'a> { pub callback: &'a mut StashCb<'a>, } -#[allow(unused)] -pub extern "C" fn stash_cb( +pub(crate) extern "C" fn stash_cb( index: size_t, message: *const c_char, stash_id: *const raw::git_oid, payload: *mut c_void, ) -> c_int { panic::wrap(|| unsafe { - let mut data = &mut *(payload as *mut StashCbData<'_>); + let data = &mut *(payload as *mut StashCbData<'_>); let res = { - let mut callback = &mut data.callback; + let callback = &mut data.callback; callback( index, CStr::from_ptr(message).to_str().unwrap(), @@ -191,15 +189,14 @@ fn convert_progress(progress: raw::git_stash_apply_progress_t) -> StashApplyProg } } -#[allow(unused)] extern "C" fn stash_apply_progress_cb( progress: raw::git_stash_apply_progress_t, payload: *mut c_void, ) -> c_int { panic::wrap(|| unsafe { - let mut options = &mut *(payload as *mut StashApplyOptions<'_>); + let options = &mut *(payload as *mut StashApplyOptions<'_>); let res = { - let mut callback = options.progress.as_mut().unwrap(); + let callback = options.progress.as_mut().unwrap(); callback(convert_progress(progress)) }; diff --git a/src/tree.rs b/src/tree.rs index 78b2413841..9a38244cfa 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -122,10 +122,6 @@ impl<'repo> Tree<'repo> { C: FnMut(&str, &TreeEntry<'_>) -> T, T: Into, { - #[allow(unused)] - struct TreeWalkCbData<'a, T> { - pub callback: &'a mut TreeWalkCb<'a, T>, - } unsafe { let mut data = TreeWalkCbData { callback: &mut callback, @@ -209,6 +205,10 @@ impl<'repo> Tree<'repo> { type TreeWalkCb<'a, T> = dyn FnMut(&str, &TreeEntry<'_>) -> T + 'a; +struct TreeWalkCbData<'a, T> { + callback: &'a mut TreeWalkCb<'a, T>, +} + extern "C" fn treewalk_cb>( root: *const c_char, entry: *const raw::git_tree_entry, @@ -220,8 +220,9 @@ extern "C" fn treewalk_cb>( _ => return -1, }; let entry = entry_from_raw_const(entry); - let payload = payload as *mut &mut TreeWalkCb<'_, T>; - (*payload)(root, &entry).into() + let payload = &mut *(payload as *mut TreeWalkCbData<'_, T>); + let callback = &mut payload.callback; + callback(root, &entry).into() }) { Some(value) => value, None => -1,