Skip to content

Commit 7dec60c

Browse files
committed
Remove RepositoryPathBuf as there is no use for it currently.
One day the Entry could be more strongly typed to indicate it's a valid component, while leaving `EntryRef` to point to whatever was read, even if it's invalid.
1 parent 3994c09 commit 7dec60c

File tree

12 files changed

+18
-142
lines changed

12 files changed

+18
-142
lines changed

Cargo.lock

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

gix-object/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ gix-hashtable = { version = "^0.8.0", path = "../gix-hashtable" }
4949
gix-validate = { version = "^0.9.4", path = "../gix-validate" }
5050
gix-actor = { version = "^0.34.0", path = "../gix-actor" }
5151
gix-date = { version = "^0.9.4", path = "../gix-date" }
52-
gix-fs = { version = "^0.14.0", path = "../gix-fs" }
5352
gix-path = { version = "^0.10.15", path = "../gix-path" }
5453
gix-utils = { version = "^0.2.0", path = "../gix-utils" }
5554

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().try_into().expect("TODO"),
75+
filename: filename.to_owned(),
7676
oid: oid.into(),
7777
}
7878
}

gix-object/src/tree/editor.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ pub enum Error {
3333
EmptyPathComponent,
3434
#[error(transparent)]
3535
FindExistingObject(#[from] crate::find::existing_object::Error),
36-
#[error(transparent)]
37-
RepositoryPathBuf(#[from] crate::tree::repository_path_buf::Error),
3836
}
3937

4038
/// Lifecycle
@@ -326,7 +324,7 @@ impl Editor<'_> {
326324
cursor.entries.insert(
327325
insertion_idx,
328326
tree::Entry {
329-
filename: name.try_into()?,
327+
filename: name.into(),
330328
mode: if is_last { kind.into() } else { EntryKind::Tree.into() },
331329
oid: if is_last { id } else { id.kind().null() },
332330
},

gix-object/src/tree/mod.rs

Lines changed: 1 addition & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use bstr::ByteSlice;
2-
use gix_fs::stack::ToNormalPathComponents;
3-
41
use crate::{
52
bstr::{BStr, BString},
63
tree, Tree, TreeRef,
@@ -326,131 +323,14 @@ impl Ord for EntryRef<'_> {
326323
}
327324
}
328325

329-
/// A wrapper for `BString`. It is used to enforce the following constraints:
330-
///
331-
/// - The path separator always is `/`, independent of the platform.
332-
/// - Only normal components are allowed.
333-
/// - It is always represented as a bunch of bytes.
334-
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
335-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
336-
pub struct RepositoryPathPuf {
337-
inner: BString,
338-
}
339-
340-
impl RepositoryPathPuf {
341-
fn len(&self) -> usize {
342-
self.inner.len()
343-
}
344-
345-
fn get(&self, index: usize) -> std::option::Option<&u8> {
346-
self.inner.get(index)
347-
}
348-
349-
fn find_byte(&self, byte: u8) -> std::option::Option<usize> {
350-
self.inner.find_byte(byte)
351-
}
352-
353-
/// Do not use this method.
354-
///
355-
/// This method is intended to be used during the transition from `BString` to
356-
/// `RepositoryPathBuf` as long as there are APIs that expect the former instead of the latter.
357-
pub fn into_bstring_do_not_use(self) -> BString {
358-
self.inner
359-
}
360-
}
361-
362-
impl std::fmt::Display for RepositoryPathPuf {
363-
#[inline]
364-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
365-
self.inner.fmt(f)
366-
}
367-
}
368-
369-
impl std::ops::Index<std::ops::RangeTo<usize>> for RepositoryPathPuf {
370-
type Output = BStr;
371-
372-
#[inline]
373-
fn index(&self, r: std::ops::RangeTo<usize>) -> &BStr {
374-
use bstr::ByteSlice;
375-
376-
BStr::new(&self.inner.as_bytes()[..r.end])
377-
}
378-
}
379-
380-
///
381-
pub mod repository_path_buf {
382-
use gix_fs::stack::to_normal_path_components;
383-
384-
/// The error used in [`RepositoryPathPuf`](super::RepositoryPathPuf).
385-
#[derive(Debug, thiserror::Error)]
386-
#[allow(missing_docs)]
387-
pub enum Error {
388-
#[error(transparent)]
389-
ContainsNonNormalComponents(#[from] to_normal_path_components::Error),
390-
#[error(transparent)]
391-
IllegalUtf8(#[from] gix_path::Utf8Error),
392-
}
393-
}
394-
395-
impl TryFrom<&str> for RepositoryPathPuf {
396-
type Error = repository_path_buf::Error;
397-
398-
fn try_from(value: &str) -> Result<Self, Self::Error> {
399-
let path = std::path::Path::new(value);
400-
401-
for component in path.to_normal_path_components() {
402-
component?;
403-
}
404-
405-
Ok(Self { inner: value.into() })
406-
}
407-
}
408-
409-
impl TryFrom<&BStr> for RepositoryPathPuf {
410-
type Error = repository_path_buf::Error;
411-
412-
fn try_from(value: &BStr) -> Result<Self, Self::Error> {
413-
let path: &std::path::Path = &gix_path::try_from_bstr(value)?;
414-
415-
for component in path.to_normal_path_components() {
416-
component?;
417-
}
418-
419-
Ok(Self { inner: value.into() })
420-
}
421-
}
422-
423-
impl TryFrom<BString> for RepositoryPathPuf {
424-
type Error = repository_path_buf::Error;
425-
426-
fn try_from(value: BString) -> Result<Self, Self::Error> {
427-
let path: &std::path::Path = &gix_path::try_from_bstr(&value)?;
428-
429-
for component in path.to_normal_path_components() {
430-
component?;
431-
}
432-
433-
Ok(Self { inner: value })
434-
}
435-
}
436-
437-
impl std::ops::Deref for RepositoryPathPuf {
438-
type Target = [u8];
439-
440-
#[inline]
441-
fn deref(&self) -> &[u8] {
442-
&self.inner
443-
}
444-
}
445-
446326
/// An entry in a [`Tree`], similar to an entry in a directory.
447327
#[derive(PartialEq, Eq, Debug, Hash, Clone)]
448328
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
449329
pub struct Entry {
450330
/// The kind of object to which `oid` is pointing to.
451331
pub mode: EntryMode,
452332
/// The name of the file in the parent tree.
453-
pub filename: RepositoryPathPuf,
333+
pub filename: BString,
454334
/// The id of the object representing the entry.
455335
pub oid: gix_hash::ObjectId,
456336
}

gix-object/src/tree/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl crate::WriteTo for Tree {
4242

4343
if filename.find_byte(0).is_some() {
4444
return Err(Error::NullbyteInFilename {
45-
name: filename.clone().into_bstring_do_not_use(),
45+
name: (*filename).to_owned(),
4646
}
4747
.into());
4848
}

gix-object/tests/object/encode/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ mod tree {
111111
let mut tree = gix_object::Tree::empty();
112112
tree.entries.push(tree::Entry {
113113
mode: EntryKind::Blob.into(),
114-
filename: "".try_into().expect("TODO"),
114+
filename: "".into(),
115115
oid: gix_hash::Kind::Sha1.null(),
116116
});
117117
tree.entries.push(tree::Entry {
118118
mode: EntryKind::Tree.into(),
119-
filename: "something\nwith\newlines\n".try_into().expect("TODO"),
119+
filename: "something\nwith\newlines\n".into(),
120120
oid: gix_hash::ObjectId::empty_tree(gix_hash::Kind::Sha1),
121121
});
122122
tree.write_to(&mut std::io::sink())
@@ -128,7 +128,7 @@ mod tree {
128128
let mut tree = gix_object::Tree::empty();
129129
tree.entries.push(tree::Entry {
130130
mode: EntryKind::Blob.into(),
131-
filename: "hi\0ho".try_into().expect("TODO"),
131+
filename: "hi\0ho".into(),
132132
oid: gix_hash::Kind::Sha1.null(),
133133
});
134134
let err = tree.write_to(&mut std::io::sink()).unwrap_err();

gix-object/tests/object/tree/editor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn from_empty_cursor() -> crate::Result {
4141
cursor.get(Some("empty-dir-via-cursor")),
4242
Some(&Entry {
4343
mode: EntryKind::Tree.into(),
44-
filename: "empty-dir-via-cursor".try_into().expect("TODO"),
44+
filename: "empty-dir-via-cursor".into(),
4545
oid: gix_hash::ObjectId::empty_tree(gix_hash::Kind::Sha1),
4646
}),
4747
);
@@ -69,7 +69,7 @@ fn from_empty_cursor() -> crate::Result {
6969
edit.get(["some", "deeply", "nested", "path"]),
7070
Some(&Entry {
7171
mode: EntryKind::Tree.into(),
72-
filename: "path".try_into().expect("TODO"),
72+
filename: "path".into(),
7373
oid: gix_hash::Kind::Sha1.null(),
7474
}),
7575
"the directory leading to the removed one is still present"
@@ -470,7 +470,7 @@ fn from_empty_add() -> crate::Result {
470470
edit.get(["a", "b"]),
471471
Some(&Entry {
472472
mode: EntryKind::Tree.into(),
473-
filename: "b".try_into().expect("TODO"),
473+
filename: "b".into(),
474474
oid: hex_to_id("4b825dc642cb6eb9a060e54bf8d69288fbee4904"),
475475
}),
476476
"before writing, entries are still present, just like they were written"
@@ -479,7 +479,7 @@ fn from_empty_add() -> crate::Result {
479479
edit.get(["a", "b", "c"]),
480480
Some(&Entry {
481481
mode: EntryKind::Tree.into(),
482-
filename: "c".try_into().expect("TODO"),
482+
filename: "c".into(),
483483
oid: gix_hash::ObjectId::empty_tree(gix_hash::Kind::Sha1),
484484
}),
485485
);
@@ -503,7 +503,7 @@ fn from_empty_add() -> crate::Result {
503503
edit.get(Some("a")),
504504
Some(&Entry {
505505
mode: EntryKind::Tree.into(),
506-
filename: "a".try_into().expect("TODO"),
506+
filename: "a".into(),
507507
oid: hex_to_id("850bf83c26003cb0541318718bc9217c4a5bde6d"),
508508
}),
509509
"but the top-level tree is still available and can yield its entries, as written with proper ids"

gix-object/tests/object/tree/iter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ mod lookup_entry {
124124
pub(super) fn entry(filename: &str, mode: tree::EntryKind, oid: gix_hash::ObjectId) -> Option<tree::Entry> {
125125
Some(tree::Entry {
126126
mode: mode.into(),
127-
filename: filename.try_into().ok()?,
127+
filename: filename.into(),
128128
oid,
129129
})
130130
}

gix-odb/tests/odb/memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn without_memory() -> crate::Result {
1919
let mut tree = tree.to_owned();
2020
tree.entries.push(tree::Entry {
2121
mode: tree::EntryKind::Blob.into(),
22-
filename: "z-for-sorting_another-file-with-same-content".try_into().expect("TODO"),
22+
filename: "z-for-sorting_another-file-with-same-content".into(),
2323
oid: existing,
2424
});
2525
let new_tree_id = odb.write(&tree)?;
@@ -62,7 +62,7 @@ fn with_memory() -> crate::Result {
6262
let mut tree = tree.to_owned();
6363
tree.entries.push(tree::Entry {
6464
mode: tree::EntryKind::Blob.into(),
65-
filename: "z-for-sorting_another-file-with-same-content".try_into().expect("TODO"),
65+
filename: "z-for-sorting_another-file-with-same-content".into(),
6666
oid: existing,
6767
});
6868
let new_tree_id = odb.write(&tree)?;

gix/examples/init-repo-and-commit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() -> anyhow::Result<()> {
3232
let entry = tree::Entry {
3333
mode: tree::EntryKind::Blob.into(),
3434
oid: blob_id,
35-
filename: "hello.txt".try_into()?,
35+
filename: "hello.txt".into(),
3636
};
3737

3838
tree.entries.push(entry);

gix/src/object/tree/editor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,14 @@ fn write_cursor<'repo>(cursor: &mut Cursor<'_, 'repo>) -> Result<Id<'repo>, writ
288288
cursor.validate,
289289
)
290290
.map_err(|err| write::Error::InvalidFilename {
291-
filename: entry.filename.clone().into_bstring_do_not_use(),
291+
filename: entry.filename.clone(),
292292
kind: entry.mode.into(),
293293
id: entry.oid,
294294
source: err,
295295
})?;
296296
if !entry.mode.is_commit() && !cursor.repo.has_object(entry.oid) {
297297
return Err(write::Error::MissingObject {
298-
filename: entry.filename.clone().into_bstring_do_not_use(),
298+
filename: entry.filename.clone(),
299299
kind: entry.mode.into(),
300300
id: entry.oid,
301301
});

0 commit comments

Comments
 (0)