From d2a49919a5b9c0593887fa26596959c7ce9db4b0 Mon Sep 17 00:00:00 2001 From: Justin Wernick Date: Wed, 19 Apr 2023 17:37:17 +0200 Subject: Took some suggestions from clippy --- src/git.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/git.rs b/src/git.rs index 3cfaa8c..d571386 100644 --- a/src/git.rs +++ b/src/git.rs @@ -3,7 +3,11 @@ use crate::{ ShackleError, }; use git2::{ErrorCode, Repository, RepositoryInitMode, RepositoryInitOptions}; -use std::{fs, path::PathBuf, process::Command}; +use std::{ + fs, + path::{Path, PathBuf}, + process::Command, +}; use user_info::{get_user_groups, get_username}; pub struct GitInitResult { @@ -28,7 +32,7 @@ fn group_git_dir(group: &str) -> PathBuf { git_dir_prefix().join(group) } -fn is_valid_git_repo_path(path: &PathBuf) -> Result { +fn is_valid_git_repo_path(path: &Path) -> Result { let prefix = git_dir_prefix(); let relative_path = match path.strip_prefix(&prefix) { Ok(relative_path) => relative_path, @@ -94,7 +98,7 @@ pub fn init( if let Some(description) = description { // There is an init option for setting the description but it seems to // just do nothing? - set_description(&path, &description)?; + set_description(&path, description)?; } Ok(GitInitResult { path }) @@ -107,7 +111,7 @@ pub struct RepoMetadata { pub fn list() -> Result, ShackleError> { fn add_from_dir( - collection_dir: &PathBuf, + collection_dir: &Path, is_checking_group: bool, ) -> Result, ShackleError> { let mut results = Vec::new(); @@ -153,14 +157,14 @@ pub fn list() -> Result, ShackleError> { results.append(&mut add_from_dir(&personal_git_dir()?, false)?); let groups = get_user_groups(); for group in &groups { - results.append(&mut add_from_dir(&group_git_dir(&group), true)?); + results.append(&mut add_from_dir(&group_git_dir(group), true)?); } Ok(results) } -pub fn set_description(directory: &PathBuf, description: &str) -> Result<(), ShackleError> { - if !is_valid_git_repo_path(&directory)? { +pub fn set_description(directory: &Path, description: &str) -> Result<(), ShackleError> { + if !is_valid_git_repo_path(directory)? { return Err(ShackleError::InvalidDirectory); } @@ -172,12 +176,12 @@ pub fn set_description(directory: &PathBuf, description: &str) -> Result<(), Sha } } -pub fn set_branch(directory: &PathBuf, branch: &str) -> Result<(), ShackleError> { - if !is_valid_git_repo_path(&directory)? { +pub fn set_branch(directory: &Path, branch: &str) -> Result<(), ShackleError> { + if !is_valid_git_repo_path(directory)? { return Err(ShackleError::InvalidDirectory); } - if let Ok(repo) = Repository::open_bare(&directory) { + if let Ok(repo) = Repository::open_bare(directory) { repo.reference_symbolic( "HEAD", &format!("refs/heads/{branch}"), -- cgit v1.2.3