Skip to content

Commit 0b93ac3

Browse files
committed
Add RepositoryPathBuf PoC
1 parent 420e730 commit 0b93ac3

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

gix-object/src/object/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl From<tree::EntryRef<'_>> for tree::Entry {
7272
let tree::EntryRef { mode, filename, oid } = other;
7373
tree::Entry {
7474
mode,
75-
filename: filename.to_owned(),
75+
filename: filename.to_owned().into(),
7676
oid: oid.into(),
7777
}
7878
}

gix-object/src/tree/mod.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,57 @@ impl Ord for EntryRef<'_> {
249249
}
250250
}
251251

252+
/// TODO
253+
/// Keep in mind that the path separator always is `/`, independent of the platform.
254+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
255+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
256+
pub struct RepositoryPathPuf {
257+
/// TODO
258+
inner: BString,
259+
}
260+
261+
impl std::fmt::Display for RepositoryPathPuf {
262+
#[inline]
263+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
264+
self.inner.fmt(f)
265+
}
266+
}
267+
268+
impl From<&str> for RepositoryPathPuf {
269+
fn from(value: &str) -> Self {
270+
Self { inner: value.into() }
271+
}
272+
}
273+
274+
impl From<&BStr> for RepositoryPathPuf {
275+
fn from(value: &BStr) -> Self {
276+
Self { inner: value.into() }
277+
}
278+
}
279+
280+
impl From<BString> for RepositoryPathPuf {
281+
fn from(value: BString) -> Self {
282+
Self { inner: value }
283+
}
284+
}
285+
286+
impl std::ops::Deref for RepositoryPathPuf {
287+
type Target = BString;
288+
289+
#[inline]
290+
fn deref(&self) -> &BString {
291+
&self.inner
292+
}
293+
}
294+
252295
/// An entry in a [`Tree`], similar to an entry in a directory.
253296
#[derive(PartialEq, Eq, Debug, Hash, Clone)]
254297
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
255298
pub struct Entry {
256299
/// The kind of object to which `oid` is pointing to.
257300
pub mode: EntryMode,
258301
/// The name of the file in the parent tree.
259-
pub filename: BString,
302+
pub filename: RepositoryPathPuf,
260303
/// The id of the object representing the entry.
261304
pub oid: gix_hash::ObjectId,
262305
}

gix-object/src/tree/write.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ impl crate::WriteTo for Tree {
4040
out.write_all(mode.as_bytes(&mut buf))?;
4141
out.write_all(SPACE)?;
4242

43+
let name: &BString = filename;
44+
4345
if filename.find_byte(0).is_some() {
4446
return Err(Error::NullbyteInFilename {
45-
name: (*filename).to_owned(),
47+
name: (*name).to_owned(),
4648
}
4749
.into());
4850
}

gix/src/object/tree/editor.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,21 @@ fn write_cursor<'repo>(cursor: &mut Cursor<'_, 'repo>) -> Result<Id<'repo>, writ
287287
.then_some(gix_validate::path::component::Mode::Symlink),
288288
cursor.validate,
289289
)
290-
.map_err(|err| write::Error::InvalidFilename {
291-
filename: entry.filename.clone(),
292-
kind: entry.mode.into(),
293-
id: entry.oid,
294-
source: err,
290+
.map_err(|err| {
291+
let filename: &BString = &entry.filename;
292+
293+
write::Error::InvalidFilename {
294+
filename: filename.clone(),
295+
kind: entry.mode.into(),
296+
id: entry.oid,
297+
source: err,
298+
}
295299
})?;
296300
if !entry.mode.is_commit() && !cursor.repo.has_object(entry.oid) {
301+
let filename: &BString = &entry.filename;
302+
297303
return Err(write::Error::MissingObject {
298-
filename: entry.filename.clone(),
304+
filename: filename.clone(),
299305
kind: entry.mode.into(),
300306
id: entry.oid,
301307
});

0 commit comments

Comments
 (0)