Skip to content

Commit 3db61eb

Browse files
authored
Merge pull request #1168 from joshtriplett/cred-feature
Make url optional via a new "cred" feature gate for credential helpers; disable default features
2 parents bb658dd + 875a4cc commit 3db61eb

File tree

6 files changed

+33
-20
lines changed

6 files changed

+33
-20
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git2"
3-
version = "0.20.2"
3+
version = "0.21.0"
44
authors = ["Josh Triplett <josh@joshtriplett.org>", "Alex Crichton <alex@alexcrichton.com>"]
55
license = "MIT OR Apache-2.0"
66
readme = "README.md"
@@ -16,7 +16,7 @@ categories = ["api-bindings"]
1616
edition = "2021"
1717

1818
[dependencies]
19-
url = "2.5.4"
19+
url = { version = "2.5.4", optional = true }
2020
bitflags = "2.1.0"
2121
libc = "0.2"
2222
log = "0.4.8"
@@ -30,12 +30,15 @@ openssl-probe = { version = "0.1", optional = true }
3030
clap = { version = "4.4.13", features = ["derive"] }
3131
time = { version = "0.3.37", features = ["formatting"] }
3232
tempfile = "3.1.0"
33+
url = "2.5.4"
3334

3435
[features]
3536
unstable = []
36-
default = ["ssh", "https"]
37-
ssh = ["libgit2-sys/ssh"]
38-
https = ["libgit2-sys/https", "openssl-sys", "openssl-probe"]
37+
default = []
38+
ssh = ["libgit2-sys/ssh", "cred"]
39+
https = ["libgit2-sys/https", "openssl-sys", "openssl-probe", "cred"]
40+
# Include support for credentials, which pulls in the `url` crate and all its dependencies
41+
cred = ["dep:url"]
3942
vendored-libgit2 = ["libgit2-sys/vendored"]
4043
vendored-openssl = ["openssl-sys/vendored", "libgit2-sys/vendored-openssl"]
4144
zlib-ng-compat = ["libgit2-sys/zlib-ng-compat"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ libgit2 bindings for Rust.
66

77
```toml
88
[dependencies]
9-
git2 = "0.20.2"
9+
git2 = "0.21"
1010
```
1111

1212
## Rust version requirements

git2-curl/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "git2-curl"
3-
version = "0.21.0"
3+
version = "0.22.0"
44
authors = ["Josh Triplett <josh@joshtriplett.org>", "Alex Crichton <alex@alexcrichton.com>"]
55
license = "MIT OR Apache-2.0"
66
repository = "https://github.com/rust-lang/git2-rs"
@@ -16,7 +16,7 @@ edition = "2021"
1616
curl = "0.4.33"
1717
url = "2.5.4"
1818
log = "0.4"
19-
git2 = { path = "..", version = "0.20", default-features = false }
19+
git2 = { path = "..", version = "0.21", default-features = false }
2020

2121
[dev-dependencies]
2222
tempfile = "3.0"

src/cred.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1+
#[cfg(feature = "cred")]
12
use log::{debug, trace};
23
use std::ffi::CString;
3-
use std::io::Write;
44
use std::mem;
55
use std::path::Path;
6-
use std::process::{Command, Stdio};
76
use std::ptr;
87

98
use crate::util::Binding;
10-
use crate::{raw, Config, Error, IntoCString};
9+
#[cfg(feature = "cred")]
10+
use crate::Config;
11+
use crate::{raw, Error, IntoCString};
1112

1213
/// A structure to represent git credentials in libgit2.
1314
pub struct Cred {
1415
raw: *mut raw::git_cred,
1516
}
1617

1718
/// Management of the gitcredentials(7) interface.
19+
#[cfg(feature = "cred")]
1820
pub struct CredentialHelper {
1921
/// A public field representing the currently discovered username from
2022
/// configuration.
@@ -118,6 +120,7 @@ impl Cred {
118120
/// successful.
119121
///
120122
/// [1]: https://www.kernel.org/pub/software/scm/git/docs/gitcredentials.html
123+
#[cfg(feature = "cred")]
121124
pub fn credential_helper(
122125
config: &Config,
123126
url: &str,
@@ -189,6 +192,7 @@ impl Drop for Cred {
189192
}
190193
}
191194

195+
#[cfg(feature = "cred")]
192196
impl CredentialHelper {
193197
/// Create a new credential helper object which will be used to probe git's
194198
/// local credential configuration.
@@ -292,6 +296,12 @@ impl CredentialHelper {
292296
// see https://www.kernel.org/pub/software/scm/git/docs/technical
293297
// /api-credentials.html#_credential_helpers
294298
fn add_command(&mut self, cmd: Option<&str>) {
299+
fn is_absolute_path(path: &str) -> bool {
300+
path.starts_with('/')
301+
|| path.starts_with('\\')
302+
|| cfg!(windows) && path.chars().nth(1).is_some_and(|x| x == ':')
303+
}
304+
295305
let cmd = match cmd {
296306
Some("") | None => return,
297307
Some(s) => s,
@@ -352,6 +362,9 @@ impl CredentialHelper {
352362
cmd: &str,
353363
username: &Option<String>,
354364
) -> (Option<String>, Option<String>) {
365+
use std::io::Write;
366+
use std::process::{Command, Stdio};
367+
355368
macro_rules! my_try( ($e:expr) => (
356369
match $e {
357370
Ok(e) => e,
@@ -481,13 +494,8 @@ impl CredentialHelper {
481494
}
482495
}
483496

484-
fn is_absolute_path(path: &str) -> bool {
485-
path.starts_with('/')
486-
|| path.starts_with('\\')
487-
|| cfg!(windows) && path.chars().nth(1).is_some_and(|x| x == ':')
488-
}
489-
490497
#[cfg(test)]
498+
#[cfg(feature = "cred")]
491499
mod test {
492500
use std::env;
493501
use std::fs::File;

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
//! source `Repository`, to ensure that they do not outlive the repository
6666
//! itself.
6767
68-
#![doc(html_root_url = "https://docs.rs/git2/0.20")]
68+
#![doc(html_root_url = "https://docs.rs/git2/0.21")]
6969
#![allow(trivial_numeric_casts, trivial_casts)]
7070
#![deny(missing_docs)]
7171
#![warn(rust_2018_idioms)]
@@ -88,7 +88,9 @@ pub use crate::buf::Buf;
8888
pub use crate::cherrypick::CherrypickOptions;
8989
pub use crate::commit::{Commit, Parents};
9090
pub use crate::config::{Config, ConfigEntries, ConfigEntry};
91-
pub use crate::cred::{Cred, CredentialHelper};
91+
pub use crate::cred::Cred;
92+
#[cfg(feature = "cred")]
93+
pub use crate::cred::CredentialHelper;
9294
pub use crate::describe::{Describe, DescribeFormatOptions, DescribeOptions};
9395
pub use crate::diff::{Deltas, Diff, DiffDelta, DiffFile, DiffOptions};
9496
pub use crate::diff::{DiffBinary, DiffBinaryFile, DiffBinaryKind, DiffPatchidOptions};

0 commit comments

Comments
 (0)