Skip to content

Commit e1291f0

Browse files
andrea-berlingextrawurst
authored andcommitted
Add a BlameRequest enum for re-using blame data in Goto line
Modiy uses of BlameFileOpen accordingly Make the blame field of BlameFilePopup private again
1 parent 20ed1d2 commit e1291f0

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

src/app.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use crate::{
1010
options::{Options, SharedOptions},
1111
popup_stack::PopupStack,
1212
popups::{
13-
AppOption, BlameFileOpen, BlameFilePopup, BranchListPopup,
14-
CommitPopup, CompareCommitsPopup, ConfirmPopup,
15-
CreateBranchPopup, ExternalEditorPopup, FetchPopup,
16-
FileRevlogPopup, FuzzyFindPopup, GotoLinePopup, HelpPopup,
17-
InspectCommitPopup, LogSearchPopupPopup, MsgPopup,
13+
AppOption, BlameFileOpen, BlameFilePopup, BlameRequest,
14+
BranchListPopup, CommitPopup, CompareCommitsPopup,
15+
ConfirmPopup, CreateBranchPopup, ExternalEditorPopup,
16+
FetchPopup, FileRevlogPopup, FuzzyFindPopup, GotoLinePopup,
17+
HelpPopup, InspectCommitPopup, LogSearchPopupPopup, MsgPopup,
1818
OptionsPopup, PullPopup, PushPopup, PushTagsPopup,
1919
RenameBranchPopup, ResetPopup, RevisionFilesPopup,
2020
StashMsgPopup, SubmodulesListPopup, TagCommitPopup,
@@ -885,13 +885,11 @@ impl App {
885885
if let StackablePopupOpen::BlameFile(params) =
886886
popup
887887
{
888-
let blame =
889-
self.blame_file_popup.blame.clone();
890888
self.popup_stack.push(
891889
StackablePopupOpen::BlameFile(
892890
BlameFileOpen {
893891
selection: Some(line),
894-
blame,
892+
blame: BlameRequest::KeepExisting,
895893
..params
896894
},
897895
),

src/components/revision_files.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::{
66
use crate::{
77
app::Environment,
88
keys::{key_match, SharedKeyConfig},
9-
popups::{BlameFileOpen, FileRevOpen},
9+
popups::{BlameFileOpen, BlameRequest, FileRevOpen},
1010
queue::{InternalEvent, Queue, StackablePopupOpen},
1111
strings::{self, order, symbol},
1212
try_or_popup,
@@ -193,7 +193,7 @@ impl RevisionFilesComponent {
193193
file_path: path,
194194
commit_id: self.revision.as_ref().map(|c| c.id),
195195
selection: None,
196-
blame: None,
196+
blame: BlameRequest::StartNew,
197197
}),
198198
));
199199

src/components/status_tree.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{
99
app::Environment,
1010
components::{CommandInfo, Component, EventState},
1111
keys::{key_match, SharedKeyConfig},
12-
popups::{BlameFileOpen, FileRevOpen},
12+
popups::{BlameFileOpen, BlameRequest, FileRevOpen},
1313
queue::{InternalEvent, NeedsUpdate, Queue, StackablePopupOpen},
1414
strings::{self, order},
1515
ui::{self, style::SharedTheme},
@@ -456,7 +456,7 @@ impl Component for StatusTreeComponent {
456456
file_path: status_item.path,
457457
commit_id: self.revision,
458458
selection: None,
459-
blame: None,
459+
blame: BlameRequest::StartNew,
460460
},
461461
),
462462
));

src/popups/blame_file.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,18 @@ impl BlameProcess {
7878
}
7979
}
8080

81+
#[derive(Clone, Debug)]
82+
pub enum BlameRequest {
83+
StartNew,
84+
KeepExisting,
85+
}
86+
8187
#[derive(Clone, Debug)]
8288
pub struct BlameFileOpen {
8389
pub file_path: String,
8490
pub commit_id: Option<CommitId>,
8591
pub selection: Option<usize>,
86-
pub blame: Option<BlameProcess>,
92+
pub blame: BlameRequest,
8793
}
8894

8995
pub struct BlameFilePopup {
@@ -96,7 +102,7 @@ pub struct BlameFilePopup {
96102
table_state: std::cell::Cell<TableState>,
97103
key_config: SharedKeyConfig,
98104
current_height: std::cell::Cell<usize>,
99-
pub blame: Option<BlameProcess>,
105+
blame: Option<BlameProcess>,
100106
app_sender: Sender<AsyncAppNotification>,
101107
git_sender: Sender<AsyncGitNotification>,
102108
repo: RepoPathRef,
@@ -378,7 +384,7 @@ impl BlameFilePopup {
378384
file_path: request.file_path,
379385
commit_id: request.commit_id,
380386
selection: self.get_selection(),
381-
blame: self.blame.clone(),
387+
blame: BlameRequest::KeepExisting,
382388
}),
383389
));
384390
}
@@ -394,15 +400,13 @@ impl BlameFilePopup {
394400
file_path: open.file_path,
395401
commit_id: open.commit_id,
396402
});
397-
self.blame = match open.blame {
398-
None => {
403+
if matches!(open.blame, BlameRequest::StartNew) {
404+
self.blame =
399405
Some(BlameProcess::GettingBlame(AsyncBlame::new(
400406
self.repo.borrow().clone(),
401407
&self.git_sender,
402-
)))
403-
}
404-
blame => blame,
405-
};
408+
)));
409+
}
406410
self.table_state.get_mut().select(Some(0));
407411
self.visible = true;
408412
self.update()?;

src/popups/file_revlog.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use ratatui::{
2828
Frame,
2929
};
3030

31-
use super::{BlameFileOpen, InspectCommitOpen};
31+
use super::{BlameFileOpen, BlameRequest, InspectCommitOpen};
3232

3333
const SLICE_SIZE: usize = 1200;
3434

@@ -536,7 +536,7 @@ impl Component for FileRevlogPopup {
536536
file_path: open_request.file_path,
537537
commit_id: self.selected_commit(),
538538
selection: None,
539-
blame: None,
539+
blame: BlameRequest::StartNew,
540540
},
541541
),
542542
));

src/popups/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mod submodules;
2525
mod tag_commit;
2626
mod taglist;
2727

28-
pub use blame_file::{BlameFileOpen, BlameFilePopup};
28+
pub use blame_file::{BlameFileOpen, BlameFilePopup, BlameRequest};
2929
pub use branchlist::BranchListPopup;
3030
pub use commit::CommitPopup;
3131
pub use compare_commits::CompareCommitsPopup;

0 commit comments

Comments
 (0)