Skip to content

Commit 1223d83

Browse files
author
Stephan Dilly
committed
use Path to fix blame filename seperators (#981)
1 parent fa7cd37 commit 1223d83

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

src/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl App {
642642
self.tag_commit_popup.open(id)?;
643643
}
644644
InternalEvent::BlameFile(path) => {
645-
self.blame_file_popup.open(&path)?;
645+
self.blame_file_popup.open(path)?;
646646
flags
647647
.insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS);
648648
}

src/components/blame_file.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use asyncgit::{
1616
};
1717
use crossbeam_channel::Sender;
1818
use crossterm::event::Event;
19-
use std::convert::TryInto;
19+
use std::{convert::TryInto, path::PathBuf};
2020
use tui::{
2121
backend::Backend,
2222
layout::{Constraint, Rect},
@@ -32,7 +32,7 @@ pub struct BlameFileComponent {
3232
queue: Queue,
3333
async_blame: AsyncBlame,
3434
visible: bool,
35-
file_path: Option<String>,
35+
file_path: Option<PathBuf>,
3636
file_blame: Option<FileBlame>,
3737
table_state: std::cell::Cell<TableState>,
3838
key_config: SharedKeyConfig,
@@ -265,8 +265,8 @@ impl BlameFileComponent {
265265
}
266266

267267
///
268-
pub fn open(&mut self, file_path: &str) -> Result<()> {
269-
self.file_path = Some(file_path.into());
268+
pub fn open(&mut self, file_path: PathBuf) -> Result<()> {
269+
self.file_path = Some(file_path);
270270
self.file_blame = None;
271271
self.table_state.get_mut().select(Some(0));
272272
self.show()?;
@@ -297,7 +297,10 @@ impl BlameFileComponent {
297297
if self.is_visible() {
298298
if let Some(file_path) = &self.file_path {
299299
let blame_params = BlameParams {
300-
file_path: file_path.into(),
300+
file_path: file_path
301+
.to_str()
302+
.unwrap_or_default()
303+
.to_owned(),
301304
};
302305

303306
if let Some((
@@ -329,21 +332,23 @@ impl BlameFileComponent {
329332
(true, Some(file_path), _) => {
330333
format!(
331334
"{} -- {} -- <calculating.. (who is to blame?)>",
332-
self.title, file_path
335+
self.title,
336+
file_path.to_str().unwrap_or_default()
333337
)
334338
}
335339
(false, Some(file_path), Some(file_blame)) => {
336340
format!(
337341
"{} -- {} -- {}",
338342
self.title,
339-
file_path,
343+
file_path.to_str().unwrap_or_default(),
340344
file_blame.commit_id.get_short_string()
341345
)
342346
}
343347
(false, Some(file_path), None) => {
344348
format!(
345349
"{} -- {} -- <no blame available>",
346-
self.title, file_path
350+
self.title,
351+
file_path.to_str().unwrap_or_default()
347352
)
348353
}
349354
_ => format!("{} -- <no blame available>", self.title),

src/components/filetree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl Component for FileTreeComponent {
410410
match (&self.queue, self.selection_file()) {
411411
(Some(queue), Some(status_item)) => {
412412
queue.push(InternalEvent::BlameFile(
413-
status_item.path,
413+
status_item.path.into(),
414414
));
415415

416416
Ok(EventState::Consumed)

src/components/revision_files.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ impl RevisionFilesComponent {
132132
fn blame(&self) -> bool {
133133
self.tree.selected_file().map_or(false, |file| {
134134
self.queue.push(InternalEvent::BlameFile(
135-
file.full_path_str()
135+
file.full_path()
136136
.strip_prefix("./")
137-
.unwrap_or_default()
138-
.to_string(),
137+
.unwrap_or_else(|_| file.full_path())
138+
.to_owned(),
139139
));
140140
true
141141
})

src/queue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub enum InternalEvent {
7474
///
7575
Tags,
7676
///
77-
BlameFile(String),
77+
BlameFile(PathBuf),
7878
///
7979
CreateBranch,
8080
///

0 commit comments

Comments
 (0)