From 1142f6cbe88753c3edd6bc33a5d2de625152a456 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sun, 9 May 2021 14:34:09 +0200 Subject: [PATCH] Revert "try to get rid of touch" This reverts commit 1867ca18000383466083ccfd6bdd0b0c0dfad4c4. --- asyncgit/src/sync/diff.rs | 4 ++-- asyncgit/src/sync/utils.rs | 36 +++++++++++------------------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/asyncgit/src/sync/diff.rs b/asyncgit/src/sync/diff.rs index 1fbbd937..dd4764e9 100644 --- a/asyncgit/src/sync/diff.rs +++ b/asyncgit/src/sync/diff.rs @@ -180,7 +180,7 @@ pub fn get_diff( let work_dir = work_dir(&repo)?; let diff = get_diff_raw(&repo, p, stage, false, None)?; - raw_diff_to_file_diff(&diff, work_dir) + raw_diff_to_file_diff(&diff, &work_dir) } /// returns diff of a specific file inside a commit @@ -196,7 +196,7 @@ pub fn get_diff_commit( let work_dir = work_dir(&repo)?; let diff = get_commit_diff(&repo, id, Some(p))?; - raw_diff_to_file_diff(&diff, work_dir) + raw_diff_to_file_diff(&diff, &work_dir) } /// diff --git a/asyncgit/src/sync/utils.rs b/asyncgit/src/sync/utils.rs index 0219ec03..5c7d1e5e 100644 --- a/asyncgit/src/sync/utils.rs +++ b/asyncgit/src/sync/utils.rs @@ -4,7 +4,11 @@ use super::CommitId; use crate::error::{Error, Result}; use git2::{IndexAddOption, Repository, RepositoryOpenFlags}; use scopetime::scope_time; -use std::{fs::File, io::Write, path::Path}; +use std::{ + fs::File, + io::Write, + path::{Path, PathBuf}, +}; /// #[derive(PartialEq, Debug, Clone)] @@ -52,8 +56,9 @@ pub(crate) fn repo(repo_path: &str) -> Result { } /// -pub(crate) fn work_dir(repo: &Repository) -> Result<&Path> { - repo.workdir().ok_or(Error::NoWorkDir) +pub(crate) fn work_dir(repo: &Repository) -> Result { + let path = repo.workdir().ok_or(Error::NoWorkDir)?; + Ok(path.canonicalize()?) } /// @@ -167,7 +172,7 @@ pub(crate) fn bytes2string(bytes: &[u8]) -> Result { Ok(String::from_utf8(bytes.to_vec())?) } -/// write a file in repo (just for testing) +/// write a file in repo pub(crate) fn repo_write_file( repo: &Repository, file: &str, @@ -182,25 +187,6 @@ pub(crate) fn repo_write_file( Ok(()) } -/// write a file in repo (just for testing) -#[allow(clippy::unwrap_used)] -#[cfg(test)] -pub(crate) fn repo_write_file_panics( - repo: &Repository, - file: &str, - content: &str, -) { - let dir = work_dir(repo).unwrap().join(file); - let file_path = dir.to_str().unwrap(); - - //Note:: convert to long path - #[cfg(windows)] - let file_path = format!("{}{}", r#"\\?\"#, file_path); - - let mut file = File::create(file_path).unwrap(); - file.write_all(content.as_bytes()).unwrap(); -} - #[cfg(test)] pub(crate) fn repo_read_file( repo: &Repository, @@ -415,7 +401,7 @@ mod tests { let file_name = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"; - repo_write_file_panics(&repo, file_name, ""); + repo_write_file(&repo, file_name, "").unwrap(); assert_eq!(get_statuses(repo_path), (1, 0)); @@ -442,7 +428,7 @@ mod tests { let file_name = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"; - repo_write_file_panics(&repo, file_name, ""); + repo_write_file(&repo, file_name, "").unwrap(); assert_eq!(get_statuses(repo_path), (1, 0));