radicle-surf: remove file_system::path

The file_system types, Label & Path, are overengineered. It's more
natural to use the Path and PathBuf types provided by the std library.

This replaces any mention of Label with String and any use of the old
Path with either std::path::Path or std::path::PathBuf, depending on
what kind of ownwership is needed.

Anywhere a "root" directory is needed `PathBuf::new()` is used,
i.e. an empty `PathBuf`. Otherwise `Path::new` can used to pass
directory, or in fact a &str can also be used since it implements
AsRef<Path>.

The `File` and `Directory` types also contain there relative paths,
which can be retrieved while traversing the Tree.

Note the special file name `"special/faux\\path"` requires the use of an
escaping string construction, i.e. `r"special/faux\\path"`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny
2022-11-24 12:08:44 +00:00
parent 887cdc8010
commit d657572dfd
20 changed files with 314 additions and 917 deletions
+15 -15
View File
@@ -17,13 +17,13 @@
#![allow(dead_code, unused_variables, missing_docs)]
use std::{convert::TryFrom, slice};
use std::{convert::TryFrom, path::PathBuf, slice};
#[cfg(feature = "serialize")]
use serde::{ser, Serialize, Serializer};
use crate::{
file_system::{Directory, Path},
file_system::Directory,
git::{Error, Repository},
};
@@ -52,14 +52,14 @@ impl Default for Diff {
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CreateFile {
pub path: Path,
pub path: PathBuf,
pub diff: FileDiff,
}
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DeleteFile {
pub path: Path,
pub path: PathBuf,
pub diff: FileDiff,
}
@@ -70,8 +70,8 @@ pub struct DeleteFile {
)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MoveFile {
pub old_path: Path,
pub new_path: Path,
pub old_path: PathBuf,
pub new_path: PathBuf,
}
#[cfg_attr(
@@ -81,8 +81,8 @@ pub struct MoveFile {
)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CopyFile {
pub old_path: Path,
pub new_path: Path,
pub old_path: PathBuf,
pub new_path: PathBuf,
}
#[cfg_attr(
@@ -104,7 +104,7 @@ pub enum EofNewLine {
)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ModifiedFile {
pub path: Path,
pub path: PathBuf,
pub diff: FileDiff,
pub eof: Option<EofNewLine>,
}
@@ -309,7 +309,7 @@ impl Diff {
pub(crate) fn add_modified_file(
&mut self,
path: Path,
path: PathBuf,
hunks: impl Into<Hunks>,
eof: Option<EofNewLine>,
) {
@@ -325,15 +325,15 @@ impl Diff {
});
}
pub(crate) fn add_moved_file(&mut self, old_path: Path, new_path: Path) {
pub(crate) fn add_moved_file(&mut self, old_path: PathBuf, new_path: PathBuf) {
self.moved.push(MoveFile { old_path, new_path });
}
pub(crate) fn add_copied_file(&mut self, old_path: Path, new_path: Path) {
pub(crate) fn add_copied_file(&mut self, old_path: PathBuf, new_path: PathBuf) {
self.copied.push(CopyFile { old_path, new_path });
}
pub(crate) fn add_modified_binary_file(&mut self, path: Path) {
pub(crate) fn add_modified_binary_file(&mut self, path: PathBuf) {
self.modified.push(ModifiedFile {
path,
diff: FileDiff::Binary,
@@ -341,11 +341,11 @@ impl Diff {
});
}
pub(crate) fn add_created_file(&mut self, path: Path, diff: FileDiff) {
pub(crate) fn add_created_file(&mut self, path: PathBuf, diff: FileDiff) {
self.created.push(CreateFile { path, diff });
}
pub(crate) fn add_deleted_file(&mut self, path: Path, diff: FileDiff) {
pub(crate) fn add_deleted_file(&mut self, path: PathBuf, diff: FileDiff) {
self.deleted.push(DeleteFile { path, diff });
}