Skip to content

Commit 00a50ed

Browse files
committed
Adapt gix test to changes in gix-path
1 parent f96467e commit 00a50ed

File tree

3 files changed

+46
-26
lines changed

3 files changed

+46
-26
lines changed

gix/src/open/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub enum Error {
5656
UnsafeGitDir { path: PathBuf },
5757
#[error(transparent)]
5858
EnvironmentAccessDenied(#[from] gix_sec::permission::Error<std::path::PathBuf>),
59+
#[error(transparent)]
60+
PrefixNotRelative(#[from] gix_path::relative_path::Error),
5961
}
6062

6163
mod options;

gix/src/open/repository.rs

+26-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![allow(clippy::result_large_err)]
22
use super::{Error, Options};
33
use crate::{
4-
bstr,
54
bstr::BString,
65
config,
76
config::{
@@ -12,6 +11,8 @@ use crate::{
1211
ThreadSafeRepository,
1312
};
1413
use gix_features::threading::OwnShared;
14+
use gix_object::bstr::ByteSlice;
15+
use gix_path::relative_path::RelativePath;
1516
use std::ffi::OsStr;
1617
use std::{borrow::Cow, path::PathBuf};
1718

@@ -345,24 +346,30 @@ impl ThreadSafeRepository {
345346

346347
refs.write_reflog = config::cache::util::reflog_or_default(config.reflog, worktree_dir.is_some());
347348
refs.namespace.clone_from(&config.refs_namespace);
348-
let replacements = replacement_objects_refs_prefix(&config.resolved, lenient_config, filter_config_section)?
349-
.and_then(|prefix| {
350-
use bstr::ByteSlice;
351-
let _span = gix_trace::detail!("find replacement objects");
352-
let platform = refs.iter().ok()?;
353-
let iter = platform.prefixed(prefix.as_bstr()).ok()?;
354-
let replacements = iter
355-
.filter_map(Result::ok)
356-
.filter_map(|r: gix_ref::Reference| {
357-
let target = r.target.try_id()?.to_owned();
358-
let source =
359-
gix_hash::ObjectId::from_hex(r.name.as_bstr().strip_prefix(prefix.as_slice())?).ok()?;
360-
Some((source, target))
361-
})
362-
.collect::<Vec<_>>();
363-
Some(replacements)
364-
})
365-
.unwrap_or_default();
349+
let prefix = replacement_objects_refs_prefix(&config.resolved, lenient_config, filter_config_section)?;
350+
let replacements = match prefix {
351+
Some(prefix) => {
352+
let prefix: &RelativePath = prefix.as_bstr().try_into()?;
353+
354+
Some(prefix).and_then(|prefix| {
355+
let _span = gix_trace::detail!("find replacement objects");
356+
let platform = refs.iter().ok()?;
357+
let iter = platform.prefixed(prefix).ok()?;
358+
let replacements = iter
359+
.filter_map(Result::ok)
360+
.filter_map(|r: gix_ref::Reference| {
361+
let target = r.target.try_id()?.to_owned();
362+
let source =
363+
gix_hash::ObjectId::from_hex(r.name.as_bstr().strip_prefix(prefix.as_ref())?).ok()?;
364+
Some((source, target))
365+
})
366+
.collect::<Vec<_>>();
367+
Some(replacements)
368+
})
369+
}
370+
None => None,
371+
};
372+
let replacements = replacements.unwrap_or_default();
366373

367374
Ok(ThreadSafeRepository {
368375
objects: OwnShared::new(gix_odb::Store::at_opts(

gix/src/reference/iter.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//!
22
#![allow(clippy::empty_docs)]
3-
use std::borrow::Cow;
43

5-
use gix_ref::{bstr::BStr, file::ReferenceExt};
4+
use gix_path::relative_path::RelativePath;
5+
use gix_ref::file::ReferenceExt;
66

77
/// A platform to create iterators over references.
88
#[must_use = "Iterators should be obtained from this iterator platform"]
@@ -45,32 +45,41 @@ impl Platform<'_> {
4545
/// These are of the form `refs/heads/` or `refs/remotes/origin`, and must not contain relative paths components like `.` or `..`.
4646
// TODO: Create a custom `Path` type that enforces the requirements of git naturally, this type is surprising possibly on windows
4747
// and when not using a trailing '/' to signal directories.
48-
pub fn prefixed<'a>(&self, prefix: impl Into<Cow<'a, BStr>>) -> Result<Iter<'_>, init::Error> {
49-
Ok(Iter::new(self.repo, self.platform.prefixed(prefix.into().as_ref())?))
48+
pub fn prefixed<'a>(
49+
&self,
50+
prefix: impl TryInto<&'a RelativePath, Error = gix_path::relative_path::Error>,
51+
) -> Result<Iter<'_>, init::Error> {
52+
Ok(Iter::new(self.repo, self.platform.prefixed(prefix.try_into()?)?))
5053
}
5154

5255
// TODO: tests
5356
/// Return an iterator over all references that are tags.
5457
///
5558
/// They are all prefixed with `refs/tags`.
5659
pub fn tags(&self) -> Result<Iter<'_>, init::Error> {
57-
Ok(Iter::new(self.repo, self.platform.prefixed(b"refs/tags/")?))
60+
Ok(Iter::new(self.repo, self.platform.prefixed(b"refs/tags/".try_into()?)?))
5861
}
5962

6063
// TODO: tests
6164
/// Return an iterator over all local branches.
6265
///
6366
/// They are all prefixed with `refs/heads`.
6467
pub fn local_branches(&self) -> Result<Iter<'_>, init::Error> {
65-
Ok(Iter::new(self.repo, self.platform.prefixed(b"refs/heads/")?))
68+
Ok(Iter::new(
69+
self.repo,
70+
self.platform.prefixed(b"refs/heads/".try_into()?)?,
71+
))
6672
}
6773

6874
// TODO: tests
6975
/// Return an iterator over all remote branches.
7076
///
7177
/// They are all prefixed with `refs/remotes`.
7278
pub fn remote_branches(&self) -> Result<Iter<'_>, init::Error> {
73-
Ok(Iter::new(self.repo, self.platform.prefixed(b"refs/remotes/")?))
79+
Ok(Iter::new(
80+
self.repo,
81+
self.platform.prefixed(b"refs/remotes/".try_into()?)?,
82+
))
7483
}
7584
}
7685

@@ -123,6 +132,8 @@ pub mod init {
123132
pub enum Error {
124133
#[error(transparent)]
125134
Io(#[from] std::io::Error),
135+
#[error(transparent)]
136+
RelativePath(#[from] gix_path::relative_path::Error),
126137
}
127138
}
128139

0 commit comments

Comments
 (0)