satisfy clippy

This commit is contained in:
Nikita Galaiko 2023-12-21 14:52:36 +01:00 committed by GitButler
parent bcbf2f4d5e
commit 49af066180
4 changed files with 32 additions and 49 deletions

View File

@ -22,7 +22,7 @@ impl<'reader> SessionReader<'reader> {
let wd_reader = reader::Reader::open(&repository.root())?;
if let Ok(reader::Content::UTF8(current_session_id)) =
wd_reader.read(&repository.session_path().join("meta").join("id"))
wd_reader.read(repository.session_path().join("meta").join("id"))
{
if current_session_id == session.id.to_string() {
let head_commit = repository.git_repository().head()?.peel_to_commit()?;
@ -81,6 +81,6 @@ impl<'reader> SessionReader<'reader> {
pub fn file<P: AsRef<path::Path>>(&self, path: P) -> Result<reader::Content, reader::Error> {
let path = path.as_ref();
self.previous_reader
.read(&std::path::Path::new("wd").join(path))
.read(std::path::Path::new("wd").join(path))
}
}

View File

@ -10,8 +10,6 @@ pub use ownership::Ownership;
pub use reader::BranchReader as Reader;
pub use writer::BranchWriter as Writer;
use std::path;
use serde::{Deserialize, Serialize};
use anyhow::Result;
@ -71,34 +69,34 @@ impl TryFrom<&crate::reader::Reader<'_>> for Branch {
type Error = crate::reader::Error;
fn try_from(reader: &crate::reader::Reader) -> Result<Self, Self::Error> {
let id: String = reader.read(&path::PathBuf::from("id"))?.try_into()?;
let id: String = reader.read("id")?.try_into()?;
let id: BranchId = id.parse().map_err(|e| {
crate::reader::Error::Io(std::io::Error::new(
std::io::ErrorKind::Other,
format!("id: {}", e),
))
})?;
let name: String = reader.read(&path::PathBuf::from("meta/name"))?.try_into()?;
let name: String = reader.read("meta/name")?.try_into()?;
let notes: String = match reader.read(&path::PathBuf::from("meta/notes")) {
let notes: String = match reader.read("meta/notes") {
Ok(notes) => Ok(notes.try_into()?),
Err(crate::reader::Error::NotFound) => Ok(String::new()),
Err(e) => Err(e),
}?;
let applied = match reader.read(&path::PathBuf::from("meta/applied")) {
let applied = match reader.read("meta/applied") {
Ok(applied) => applied.try_into(),
_ => Ok(false),
}
.unwrap_or(false);
let order: usize = match reader.read(&path::PathBuf::from("meta/order")) {
let order: usize = match reader.read("meta/order") {
Ok(order) => Ok(order.try_into()?),
Err(crate::reader::Error::NotFound) => Ok(0),
Err(e) => Err(e),
}?;
let upstream_head = match reader.read(&path::PathBuf::from("meta/upstream_head")) {
let upstream_head = match reader.read("meta/upstream_head") {
Ok(crate::reader::Content::UTF8(upstream_head)) => {
upstream_head.parse().map(Some).map_err(|e| {
crate::reader::Error::Io(std::io::Error::new(
@ -111,7 +109,7 @@ impl TryFrom<&crate::reader::Reader<'_>> for Branch {
Err(e) => Err(e),
}?;
let upstream = match reader.read(&path::PathBuf::from("meta/upstream")) {
let upstream = match reader.read("meta/upstream") {
Ok(crate::reader::Content::UTF8(upstream)) => {
if upstream.is_empty() {
Ok(None)
@ -131,18 +129,12 @@ impl TryFrom<&crate::reader::Reader<'_>> for Branch {
Err(e) => Err(e),
}?;
let tree: String = reader.read(&path::PathBuf::from("meta/tree"))?.try_into()?;
let head: String = reader.read(&path::PathBuf::from("meta/head"))?.try_into()?;
let created_timestamp_ms = reader
.read(&path::PathBuf::from("meta/created_timestamp_ms"))?
.try_into()?;
let updated_timestamp_ms = reader
.read(&path::PathBuf::from("meta/updated_timestamp_ms"))?
.try_into()?;
let tree: String = reader.read("meta/tree")?.try_into()?;
let head: String = reader.read("meta/head")?.try_into()?;
let created_timestamp_ms = reader.read("meta/created_timestamp_ms")?.try_into()?;
let updated_timestamp_ms = reader.read("meta/updated_timestamp_ms")?.try_into()?;
let ownership_string: String = reader
.read(&path::PathBuf::from("meta/ownership"))?
.try_into()?;
let ownership_string: String = reader.read("meta/ownership")?.try_into()?;
let ownership = ownership_string.parse().map_err(|e| {
crate::reader::Error::Io(std::io::Error::new(
std::io::ErrorKind::Other,

View File

@ -1,4 +1,4 @@
use std::{collections::HashSet, path};
use std::collections::HashSet;
use anyhow::Result;
@ -15,7 +15,7 @@ impl<'i> BranchIterator<'i> {
pub fn new(session_reader: &'i sessions::Reader<'i>) -> Result<Self> {
let reader = session_reader.reader();
let ids_itarator = reader
.list_files(&path::PathBuf::from("branches"))?
.list_files("branches")?
.into_iter()
.map(|file_path| {
file_path

View File

@ -1,8 +1,6 @@
mod reader;
mod writer;
use std::path;
use serde::{ser::SerializeStruct, Serialize, Serializer};
pub use reader::TargetReader as Reader;
@ -35,12 +33,10 @@ impl Serialize for Target {
// this is a backwards compatibile with the old format
fn read_remote_url(reader: &crate::reader::Reader) -> Result<String, crate::reader::Error> {
match reader.read(&path::PathBuf::from("remote_url")) {
match reader.read("remote_url") {
Ok(url) => Ok(url.try_into()?),
// fallback to the old format
Err(crate::reader::Error::NotFound) => {
Ok(reader.read(&path::PathBuf::from("remote"))?.try_into()?)
}
Err(crate::reader::Error::NotFound) => Ok(reader.read("remote")?.try_into()?),
Err(e) => Err(e),
}
}
@ -49,7 +45,7 @@ fn read_remote_url(reader: &crate::reader::Reader) -> Result<String, crate::read
fn read_remote_name_branch_name(
reader: &crate::reader::Reader,
) -> Result<(String, String), crate::reader::Error> {
match reader.read(&path::PathBuf::from("name")) {
match reader.read("name") {
Ok(branch) => {
let branch: String = branch.try_into()?;
let parts = branch.split('/').collect::<Vec<_>>();
@ -57,12 +53,8 @@ fn read_remote_name_branch_name(
}
Err(crate::reader::Error::NotFound) => {
// fallback to the old format
let remote_name: String = reader
.read(&path::PathBuf::from("remote_name"))?
.try_into()?;
let branch_name: String = reader
.read(&path::PathBuf::from("branch_name"))?
.try_into()?;
let remote_name: String = reader.read("remote_name")?.try_into()?;
let branch_name: String = reader.read("branch_name")?.try_into()?;
Ok((remote_name, branch_name))
}
Err(e) => Err(e),
@ -83,7 +75,7 @@ impl Target {
format!("remote: {}", e),
))
})?;
let sha: String = reader.read(&path::PathBuf::from("sha"))?.try_into()?;
let sha: String = reader.read("sha")?.try_into()?;
let sha = sha.parse().map_err(|e| {
crate::reader::Error::Io(std::io::Error::new(
std::io::ErrorKind::InvalidData,
@ -91,17 +83,16 @@ impl Target {
))
})?;
let last_fetched_ms: Option<u128> =
match reader.read(&path::PathBuf::from("last_fetched_ms")) {
Ok(last_fetched) => Some(last_fetched.try_into().map_err(|e| {
crate::reader::Error::Io(std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!("last_fetched_ms: {}", e),
))
})?),
Err(crate::reader::Error::NotFound) => None,
Err(e) => return Err(e),
};
let last_fetched_ms: Option<u128> = match reader.read("last_fetched_ms") {
Ok(last_fetched) => Some(last_fetched.try_into().map_err(|e| {
crate::reader::Error::Io(std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!("last_fetched_ms: {}", e),
))
})?),
Err(crate::reader::Error::NotFound) => None,
Err(e) => return Err(e),
};
Ok(Self {
branch: format!("refs/remotes/{}", branch_name).parse().unwrap(),