Skip to content

Commit ec47271

Browse files
committed
Add RepositoryPathBuf PoC
1 parent f1bb269 commit ec47271

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
@@ -323,14 +323,57 @@ impl Ord for EntryRef<'_> {
323323
}
324324
}
325325

326+
/// TODO
327+
/// Keep in mind that the path separator always is `/`, independent of the platform.
328+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
329+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
330+
pub struct RepositoryPathPuf {
331+
/// TODO
332+
inner: BString,
333+
}
334+
335+
impl std::fmt::Display for RepositoryPathPuf {
336+
#[inline]
337+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
338+
self.inner.fmt(f)
339+
}
340+
}
341+
342+
impl From<&str> for RepositoryPathPuf {
343+
fn from(value: &str) -> Self {
344+
Self { inner: value.into() }
345+
}
346+
}
347+
348+
impl From<&BStr> for RepositoryPathPuf {
349+
fn from(value: &BStr) -> Self {
350+
Self { inner: value.into() }
351+
}
352+
}
353+
354+
impl From<BString> for RepositoryPathPuf {
355+
fn from(value: BString) -> Self {
356+
Self { inner: value }
357+
}
358+
}
359+
360+
impl std::ops::Deref for RepositoryPathPuf {
361+
type Target = BString;
362+
363+
#[inline]
364+
fn deref(&self) -> &BString {
365+
&self.inner
366+
}
367+
}
368+
326369
/// An entry in a [`Tree`], similar to an entry in a directory.
327370
#[derive(PartialEq, Eq, Debug, Hash, Clone)]
328371
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
329372
pub struct Entry {
330373
/// The kind of object to which `oid` is pointing to.
331374
pub mode: EntryMode,
332375
/// The name of the file in the parent tree.
333-
pub filename: BString,
376+
pub filename: RepositoryPathPuf,
334377
/// The id of the object representing the entry.
335378
pub oid: gix_hash::ObjectId,
336379
}

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)