Skip to content

Commit

Permalink
Add a BlameRequest enum for re-using blame data in Goto line
Browse files Browse the repository at this point in the history
Modiy uses of BlameFileOpen accordingly

Make the blame field of BlameFilePopup private again
  • Loading branch information
andrea-berling authored and extrawurst committed Sep 17, 2024
1 parent 20ed1d2 commit e1291f0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
14 changes: 6 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use crate::{
options::{Options, SharedOptions},
popup_stack::PopupStack,
popups::{
AppOption, BlameFileOpen, BlameFilePopup, BranchListPopup,
CommitPopup, CompareCommitsPopup, ConfirmPopup,
CreateBranchPopup, ExternalEditorPopup, FetchPopup,
FileRevlogPopup, FuzzyFindPopup, GotoLinePopup, HelpPopup,
InspectCommitPopup, LogSearchPopupPopup, MsgPopup,
AppOption, BlameFileOpen, BlameFilePopup, BlameRequest,
BranchListPopup, CommitPopup, CompareCommitsPopup,
ConfirmPopup, CreateBranchPopup, ExternalEditorPopup,
FetchPopup, FileRevlogPopup, FuzzyFindPopup, GotoLinePopup,
HelpPopup, InspectCommitPopup, LogSearchPopupPopup, MsgPopup,
OptionsPopup, PullPopup, PushPopup, PushTagsPopup,
RenameBranchPopup, ResetPopup, RevisionFilesPopup,
StashMsgPopup, SubmodulesListPopup, TagCommitPopup,
Expand Down Expand Up @@ -885,13 +885,11 @@ impl App {
if let StackablePopupOpen::BlameFile(params) =
popup
{
let blame =
self.blame_file_popup.blame.clone();
self.popup_stack.push(
StackablePopupOpen::BlameFile(
BlameFileOpen {
selection: Some(line),
blame,
blame: BlameRequest::KeepExisting,
..params
},
),
Expand Down
4 changes: 2 additions & 2 deletions src/components/revision_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{
use crate::{
app::Environment,
keys::{key_match, SharedKeyConfig},
popups::{BlameFileOpen, FileRevOpen},
popups::{BlameFileOpen, BlameRequest, FileRevOpen},
queue::{InternalEvent, Queue, StackablePopupOpen},
strings::{self, order, symbol},
try_or_popup,
Expand Down Expand Up @@ -193,7 +193,7 @@ impl RevisionFilesComponent {
file_path: path,
commit_id: self.revision.as_ref().map(|c| c.id),
selection: None,
blame: None,
blame: BlameRequest::StartNew,
}),
));

Expand Down
4 changes: 2 additions & 2 deletions src/components/status_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
app::Environment,
components::{CommandInfo, Component, EventState},
keys::{key_match, SharedKeyConfig},
popups::{BlameFileOpen, FileRevOpen},
popups::{BlameFileOpen, BlameRequest, FileRevOpen},
queue::{InternalEvent, NeedsUpdate, Queue, StackablePopupOpen},
strings::{self, order},
ui::{self, style::SharedTheme},
Expand Down Expand Up @@ -456,7 +456,7 @@ impl Component for StatusTreeComponent {
file_path: status_item.path,
commit_id: self.revision,
selection: None,
blame: None,
blame: BlameRequest::StartNew,
},
),
));
Expand Down
22 changes: 13 additions & 9 deletions src/popups/blame_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ impl BlameProcess {
}
}

#[derive(Clone, Debug)]
pub enum BlameRequest {
StartNew,
KeepExisting,
}

#[derive(Clone, Debug)]
pub struct BlameFileOpen {
pub file_path: String,
pub commit_id: Option<CommitId>,
pub selection: Option<usize>,
pub blame: Option<BlameProcess>,
pub blame: BlameRequest,
}

pub struct BlameFilePopup {
Expand All @@ -96,7 +102,7 @@ pub struct BlameFilePopup {
table_state: std::cell::Cell<TableState>,
key_config: SharedKeyConfig,
current_height: std::cell::Cell<usize>,
pub blame: Option<BlameProcess>,
blame: Option<BlameProcess>,
app_sender: Sender<AsyncAppNotification>,
git_sender: Sender<AsyncGitNotification>,
repo: RepoPathRef,
Expand Down Expand Up @@ -378,7 +384,7 @@ impl BlameFilePopup {
file_path: request.file_path,
commit_id: request.commit_id,
selection: self.get_selection(),
blame: self.blame.clone(),
blame: BlameRequest::KeepExisting,
}),
));
}
Expand All @@ -394,15 +400,13 @@ impl BlameFilePopup {
file_path: open.file_path,
commit_id: open.commit_id,
});
self.blame = match open.blame {
None => {
if matches!(open.blame, BlameRequest::StartNew) {
self.blame =
Some(BlameProcess::GettingBlame(AsyncBlame::new(
self.repo.borrow().clone(),
&self.git_sender,
)))
}
blame => blame,
};
)));
}
self.table_state.get_mut().select(Some(0));
self.visible = true;
self.update()?;
Expand Down
4 changes: 2 additions & 2 deletions src/popups/file_revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use ratatui::{
Frame,
};

use super::{BlameFileOpen, InspectCommitOpen};
use super::{BlameFileOpen, BlameRequest, InspectCommitOpen};

const SLICE_SIZE: usize = 1200;

Expand Down Expand Up @@ -536,7 +536,7 @@ impl Component for FileRevlogPopup {
file_path: open_request.file_path,
commit_id: self.selected_commit(),
selection: None,
blame: None,
blame: BlameRequest::StartNew,
},
),
));
Expand Down
2 changes: 1 addition & 1 deletion src/popups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod submodules;
mod tag_commit;
mod taglist;

pub use blame_file::{BlameFileOpen, BlameFilePopup};
pub use blame_file::{BlameFileOpen, BlameFilePopup, BlameRequest};
pub use branchlist::BranchListPopup;
pub use commit::CommitPopup;
pub use compare_commits::CompareCommitsPopup;
Expand Down

0 comments on commit e1291f0

Please sign in to comment.