From 18e195db1c10aefb2f1e2a7cffdc004bcdbfa40c Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Fri, 12 Nov 2021 15:35:39 +0100 Subject: [PATCH 1/3] fixup windows path (#981) --- asyncgit/src/sync/blame.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/asyncgit/src/sync/blame.rs b/asyncgit/src/sync/blame.rs index 8a3aaed281..8814bc5179 100644 --- a/asyncgit/src/sync/blame.rs +++ b/asyncgit/src/sync/blame.rs @@ -39,6 +39,15 @@ pub struct FileBlame { pub lines: Vec<(Option, String)>, } +#[cfg(windows)] +fn fixup_windows_path(path: String) -> String { + path.replace("\\", "/") +} +#[cfg(not(windows))] +const fn fixup_windows_path(path: &str) -> &str { + path +} + /// pub fn blame_file( repo_path: &str, @@ -50,7 +59,11 @@ pub fn blame_file( let commit_id = utils::get_head_repo(&repo)?; - let spec = format!("{}:{}", commit_id.to_string(), file_path); + let spec = format!( + "{}:{}", + commit_id.to_string(), + fixup_windows_path(file_path) + ); let object = repo.revparse_single(&spec)?; let blob = repo.find_blob(object.id())?; @@ -214,4 +227,24 @@ mod tests { Ok(()) } + + #[test] + fn test_blame_windows_path_dividers() { + let file_path = Path::new("bar\\foo"); + let (_td, repo) = repo_init_empty().unwrap(); + let root = repo.path().parent().unwrap(); + let repo_path = root.as_os_str().to_str().unwrap(); + + std::fs::create_dir(&root.join("bar")).unwrap(); + + File::create(&root.join(file_path)) + .unwrap() + .write_all(b"line 1\n") + .unwrap(); + + stage_add_file(repo_path, file_path).unwrap(); + commit(repo_path, "first commit").unwrap(); + + assert!(blame_file(&repo_path, "bar\\foo").is_ok()); + } } From 66c0e78d96a5aa873cc5486ec8a760a3375da543 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Fri, 12 Nov 2021 15:40:11 +0100 Subject: [PATCH 2/3] fix win build --- asyncgit/src/sync/blame.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asyncgit/src/sync/blame.rs b/asyncgit/src/sync/blame.rs index 8814bc5179..24655c03c0 100644 --- a/asyncgit/src/sync/blame.rs +++ b/asyncgit/src/sync/blame.rs @@ -40,7 +40,7 @@ pub struct FileBlame { } #[cfg(windows)] -fn fixup_windows_path(path: String) -> String { +fn fixup_windows_path(path: &str) -> String { path.replace("\\", "/") } #[cfg(not(windows))] From ef8f95168499fbc5a95acac9e807bc587a7acfed Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Fri, 12 Nov 2021 15:47:46 +0100 Subject: [PATCH 3/3] cleanup --- CHANGELOG.md | 1 + asyncgit/src/sync/blame.rs | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a67f39da65..d94cfbe68e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933)) - improved file diff speed dramatically ([#976](https://github.com/extrawurst/gitui/issues/976)) +- blaming files in sub-folders on windows ([#981](https://github.com/extrawurst/gitui/issues/981)) ## [0.18] - 2021-10-11 diff --git a/asyncgit/src/sync/blame.rs b/asyncgit/src/sync/blame.rs index 24655c03c0..c9e3c1c6fe 100644 --- a/asyncgit/src/sync/blame.rs +++ b/asyncgit/src/sync/blame.rs @@ -39,13 +39,17 @@ pub struct FileBlame { pub lines: Vec<(Option, String)>, } -#[cfg(windows)] +/// fixup `\` windows path seperators to git compatible `/` fn fixup_windows_path(path: &str) -> String { - path.replace("\\", "/") -} -#[cfg(not(windows))] -const fn fixup_windows_path(path: &str) -> &str { - path + #[cfg(windows)] + { + path.replace("\\", "/") + } + + #[cfg(not(windows))] + { + path.to_string() + } } ///