summaryrefslogtreecommitdiffstats
path: root/src/tabs
diff options
context:
space:
mode:
authorextrawurst <mail@rusticorn.com>2022-11-21 16:32:17 +0100
committerextrawurst <mail@rusticorn.com>2022-11-21 16:32:17 +0100
commit92f63d107c1dca1f10139668ff5b3ca752261b0f (patch)
treed2909f2a2f9413ae8c3eb431333847e0f48cb774 /src/tabs
parent3fee481e8d8325814fd3b7b45fddd4c0b2038d8f (diff)
support fetching branch_infos async
Diffstat (limited to 'src/tabs')
-rw-r--r--src/tabs/revlog.rs36
-rw-r--r--src/tabs/status.rs27
2 files changed, 47 insertions, 16 deletions
diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs
index 1e146592..02f6d7a8 100644
--- a/src/tabs/revlog.rs
+++ b/src/tabs/revlog.rs
@@ -12,9 +12,10 @@ use crate::{
};
use anyhow::Result;
use asyncgit::{
- sync::{self, get_branches_info, CommitId, RepoPathRef},
- AsyncGitNotification, AsyncLog, AsyncTags, CommitFilesParams,
- FetchStatus,
+ asyncjob::AsyncSingleJob,
+ sync::{self, CommitId, RepoPathRef},
+ AsyncBranchesJob, AsyncGitNotification, AsyncLog, AsyncTags,
+ CommitFilesParams, FetchStatus,
};
use crossbeam_channel::Sender;
use crossterm::event::Event;
@@ -35,6 +36,7 @@ pub struct Revlog {
list: CommitList,
git_log: AsyncLog,
git_tags: AsyncTags,
+ git_branches: AsyncSingleJob<AsyncBranchesJob>,
queue: Queue,
visible: bool,
key_config: SharedKeyConfig,
@@ -71,6 +73,7 @@ impl Revlog {
None,
),
git_tags: AsyncTags::new(repo.borrow().clone(), sender),
+ git_branches: AsyncSingleJob::new(sender.clone()),
visible: false,
key_config,
}
@@ -80,6 +83,7 @@ impl Revlog {
pub fn any_work_pending(&self) -> bool {
self.git_log.is_pending()
|| self.git_tags.is_pending()
+ || self.git_branches.is_pending()
|| self.commit_details.any_work_pending()
}
@@ -101,11 +105,6 @@ impl Revlog {
self.git_tags.request(Duration::from_secs(3), false)?;
- self.list.set_branches(get_branches_info(
- &self.repo.borrow(),
- true,
- )?);
-
if self.commit_details.is_visible() {
let commit = self.selected_commit();
let tags = self.selected_commit_tags(&commit);
@@ -135,6 +134,21 @@ impl Revlog {
self.update()?;
}
}
+ AsyncGitNotification::Branches => {
+ if let Some(branches) =
+ self.git_branches.take_last()
+ {
+ if let Some(Ok(branches)) = branches.result()
+ {
+ log::info!(
+ "branches: {}",
+ branches.len()
+ );
+ self.list.set_branches(branches);
+ self.update()?;
+ }
+ }
+ }
_ => (),
}
}
@@ -447,6 +461,12 @@ impl Component for Revlog {
fn show(&mut self) -> Result<()> {
self.visible = true;
self.list.clear();
+
+ self.git_branches.spawn(AsyncBranchesJob::new(
+ self.repo.borrow().clone(),
+ true,
+ ));
+
self.update()?;
Ok(())
diff --git a/src/tabs/status.rs b/src/tabs/status.rs
index 544986df..e17ce384 100644
--- a/src/tabs/status.rs
+++ b/src/tabs/status.rs
@@ -14,13 +14,14 @@ use crate::{
};
use anyhow::Result;
use asyncgit::{
+ asyncjob::AsyncSingleJob,
cached,
sync::{
self, status::StatusType, RepoPath, RepoPathRef, RepoState,
},
sync::{BranchCompare, CommitId},
- AsyncDiff, AsyncGitNotification, AsyncStatus, DiffParams,
- DiffType, PushType, StatusParams,
+ AsyncBranchesJob, AsyncDiff, AsyncGitNotification, AsyncStatus,
+ DiffParams, DiffType, PushType, StatusParams,
};
use crossbeam_channel::Sender;
use crossterm::event::Event;
@@ -73,6 +74,7 @@ pub struct Status {
git_status_stage: AsyncStatus,
git_branch_state: Option<BranchCompare>,
git_branch_name: cached::BranchName,
+ git_branches: AsyncSingleJob<AsyncBranchesJob>,
queue: Queue,
git_action_executed: bool,
options: SharedOptions,
@@ -203,6 +205,7 @@ impl Status {
repo_clone,
sender.clone(),
),
+ git_branches: AsyncSingleJob::new(sender.clone()),
git_action_executed: false,
git_branch_state: None,
git_branch_name: cached::BranchName::new(repo.clone()),
@@ -424,14 +427,22 @@ impl Status {
self.git_diff.is_pending()
|| self.git_status_stage.is_pending()
|| self.git_status_workdir.is_pending()
+ || self.git_branches.is_pending()
}
fn check_remotes(&mut self) {
- //TODO: make get_branches_info async
- self.has_remotes =
- sync::get_branches_info(&self.repo.borrow(), false)
- .map(|branches| !branches.is_empty())
- .unwrap_or(false);
+ self.has_remotes = false;
+
+ if let Some(result) = self.git_branches.take_last() {
+ if let Some(Ok(branches)) = result.result() {
+ self.has_remotes = !branches.is_empty();
+ }
+ } else {
+ self.git_branches.spawn(AsyncBranchesJob::new(
+ self.repo.borrow().clone(),
+ false,
+ ));
+ }
}
///
@@ -442,6 +453,7 @@ impl Status {
match ev {
AsyncGitNotification::Diff => self.update_diff()?,
AsyncGitNotification::Status => self.update_status()?,
+ AsyncGitNotification::Branches => self.check_remotes(),
AsyncGitNotification::Push
| AsyncGitNotification::Pull
| AsyncGitNotification::CommitFiles => {
@@ -461,7 +473,6 @@ impl Status {
self.index_wd.set_items(&workdir_status.items)?;
self.update_diff()?;
- self.check_remotes();
if self.git_action_executed {
self.git_action_executed = false;