Skip to content

Commit a77d2d0

Browse files
committed
Pass hash_type by reference
1 parent f48dc97 commit a77d2d0

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/dirs.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ pub fn local_path_and_canonical_url(
99
url: &str,
1010
cargo_home: Option<&std::path::Path>,
1111
) -> Result<(std::path::PathBuf, String), Error> {
12-
local_path_and_canonical_url_with_hash_kind(url, cargo_home, HashKind::Legacy)
12+
local_path_and_canonical_url_with_hash_kind(url, cargo_home, &DEFAULT_HASHER_KIND)
1313
}
1414

1515
/// Like [`local_path_and_canonical_url`] but accepts [`HashKind`] for determining the crate index path.
1616
pub fn local_path_and_canonical_url_with_hash_kind(
1717
url: &str,
1818
cargo_home: Option<&std::path::Path>,
19-
hash_kind: HashKind,
19+
hash_kind: &HashKind,
2020
) -> Result<(std::path::PathBuf, String), Error> {
2121
let (dir_name, canonical_url) = url_to_local_dir(url, hash_kind)?;
2222

@@ -101,7 +101,7 @@ pub(crate) const DEFAULT_HASHER_KIND: HashKind = HashKind::Legacy;
101101

102102
/// Converts a full url, eg https://github.com/rust-lang/crates.io-index, into
103103
/// the root directory name where cargo itself will fetch it on disk
104-
fn url_to_local_dir(url: &str, hash_kind: HashKind) -> Result<(String, String), Error> {
104+
fn url_to_local_dir(url: &str, hash_kind: &HashKind) -> Result<(String, String), Error> {
105105
#[allow(deprecated)]
106106
fn legacy_hash_u64(url: &str, registry_kind: u64) -> u64 {
107107
use std::hash::{Hash, Hasher, SipHasher};
@@ -258,11 +258,11 @@ mod test {
258258
fn http_index_url_matches_cargo() {
259259
use crate::sparse::URL;
260260
assert_eq!(
261-
super::url_to_local_dir(URL, HashKind::Legacy).unwrap(),
261+
super::url_to_local_dir(URL, &HashKind::Legacy).unwrap(),
262262
("index.crates.io-6f17d22bba15001f".to_owned(), URL.to_owned(),)
263263
);
264264
assert_eq!(
265-
super::url_to_local_dir(URL, HashKind::Stable).unwrap(),
265+
super::url_to_local_dir(URL, &HashKind::Stable).unwrap(),
266266
("index.crates.io-1949cf8c6b5b557f".to_owned(), URL.to_owned(),)
267267
);
268268

@@ -272,7 +272,7 @@ mod test {
272272
assert_eq!(
273273
super::url_to_local_dir(
274274
"https://dl.cloudsmith.io/aBcW1234aBcW1234/embark/rust/cargo/index.git",
275-
HashKind::Legacy
275+
&HashKind::Legacy
276276
)
277277
.unwrap(),
278278
(
@@ -283,7 +283,7 @@ mod test {
283283
assert_eq!(
284284
super::url_to_local_dir(
285285
"https://dl.cloudsmith.io/aBcW1234aBcW1234/embark/rust/cargo/index.git",
286-
HashKind::Stable
286+
&HashKind::Stable
287287
)
288288
.unwrap(),
289289
(
@@ -298,23 +298,23 @@ mod test {
298298
fn git_url_matches_cargo() {
299299
use crate::git::URL;
300300
assert_eq!(
301-
crate::dirs::url_to_local_dir(URL, HashKind::Legacy).unwrap(),
301+
crate::dirs::url_to_local_dir(URL, &HashKind::Legacy).unwrap(),
302302
("github.com-1ecc6299db9ec823".to_owned(), URL.to_owned())
303303
);
304304
assert_eq!(
305-
crate::dirs::url_to_local_dir(URL, HashKind::Stable).unwrap(),
305+
crate::dirs::url_to_local_dir(URL, &HashKind::Stable).unwrap(),
306306
("github.com-25cdd57fae9f0462".to_owned(), URL.to_owned())
307307
);
308308

309309
// Ensure we actually strip off the irrelevant parts of a url, note that
310310
// the .git suffix is not part of the canonical url, but *is* used when hashing
311311
assert_eq!(
312-
crate::dirs::url_to_local_dir(&format!("registry+{}.git?one=1&two=2#fragment", URL), HashKind::Legacy)
312+
crate::dirs::url_to_local_dir(&format!("registry+{}.git?one=1&two=2#fragment", URL), &HashKind::Legacy)
313313
.unwrap(),
314314
("github.com-c786010fb7ef2e6e".to_owned(), URL.to_owned())
315315
);
316316
assert_eq!(
317-
crate::dirs::url_to_local_dir(&format!("registry+{}.git?one=1&two=2#fragment", URL), HashKind::Stable)
317+
crate::dirs::url_to_local_dir(&format!("registry+{}.git?one=1&two=2#fragment", URL), &HashKind::Stable)
318318
.unwrap(),
319319
("github.com-e78ed0bbfe5f35d7".to_owned(), URL.to_owned())
320320
);

src/git/impl_.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ impl GitIndex {
9494
/// Concurrent invocations may fail if the index needs to be cloned. To prevent that,
9595
/// use synchronization mechanisms like mutexes or file locks as needed by the application.
9696
pub fn from_url(url: &str) -> Result<Self, Error> {
97-
Self::from_url_with_hash_kind(url, DEFAULT_HASHER_KIND)
97+
Self::from_url_with_hash_kind(url, &DEFAULT_HASHER_KIND)
9898
}
9999

100100
/// Like [`Self::from_url`], but accepts an explicit [`HashKind`] for determining the crates index path.
101-
pub fn from_url_with_hash_kind(url: &str, hash_kind: HashKind) -> Result<Self, Error> {
101+
pub fn from_url_with_hash_kind(url: &str, hash_kind: &HashKind) -> Result<Self, Error> {
102102
let (path, canonical_url) = local_path_and_canonical_url_with_hash_kind(url, None, hash_kind)?;
103103
Ok(
104104
Self::from_path_and_url(path, canonical_url, Mode::CloneUrlToPathIfRepoMissing)?
@@ -108,11 +108,11 @@ impl GitIndex {
108108

109109
/// Like [`Self::from_url()`], but read-only without auto-cloning the index at `url`.
110110
pub fn try_from_url(url: &str) -> Result<Option<Self>, Error> {
111-
Self::try_from_url_with_hash_kind(url, DEFAULT_HASHER_KIND)
111+
Self::try_from_url_with_hash_kind(url, &DEFAULT_HASHER_KIND)
112112
}
113113

114114
/// Like [`Self::try_from_url`], but accepts an explicit [`HashKind`] for determining the crates index path.
115-
pub fn try_from_url_with_hash_kind(url: &str, hash_kind: HashKind) -> Result<Option<Self>, Error> {
115+
pub fn try_from_url_with_hash_kind(url: &str, hash_kind: &HashKind) -> Result<Option<Self>, Error> {
116116
let (path, canonical_url) = local_path_and_canonical_url_with_hash_kind(url, None, hash_kind)?;
117117
Self::from_path_and_url(path, canonical_url, Mode::ReadOnly)
118118
}

src/sparse.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ impl SparseIndex {
1717
/// Note this function takes the `CARGO_HOME` environment variable into account
1818
#[inline]
1919
pub fn from_url(url: &str) -> Result<Self, Error> {
20-
Self::from_url_with_hash_kind(url, DEFAULT_HASHER_KIND)
20+
Self::from_url_with_hash_kind(url, &DEFAULT_HASHER_KIND)
2121
}
2222

2323
/// Like [`Self::from_url`] but accepts an explicit [`HashKind`] for determining the crates index path.
2424
#[inline]
25-
pub fn from_url_with_hash_kind(url: &str, hash_kind: HashKind) -> Result<Self, Error> {
25+
pub fn from_url_with_hash_kind(url: &str, hash_kind: &HashKind) -> Result<Self, Error> {
2626
Self::with_path_and_hash_kind(home::cargo_home()?, url, hash_kind)
2727
}
2828

@@ -41,15 +41,15 @@ impl SparseIndex {
4141
/// at the specified location
4242
#[inline]
4343
pub fn with_path(cargo_home: impl AsRef<Path>, url: impl AsRef<str>) -> Result<Self, Error> {
44-
Self::with_path_and_hash_kind(cargo_home, url, DEFAULT_HASHER_KIND)
44+
Self::with_path_and_hash_kind(cargo_home, url, &DEFAULT_HASHER_KIND)
4545
}
4646

4747
/// Like [`Self::with_path`] but accepts an explicit [`HashKind`] for determining the crates index path.
4848
#[inline]
4949
pub fn with_path_and_hash_kind(
5050
cargo_home: impl AsRef<Path>,
5151
url: impl AsRef<str>,
52-
hash_kind: HashKind,
52+
hash_kind: &HashKind,
5353
) -> Result<Self, Error> {
5454
let url = url.as_ref();
5555
// It is required to have the sparse+ scheme modifier for sparse urls as

0 commit comments

Comments
 (0)