mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
Add async wrapper for branch_compare_upstream
Implements AsyncBranchCompareJob following the existing pattern from AsyncBranchesJob. Wraps the synchronous branch_compare_upstream function to prevent UI blocking on large repositories. - Created asyncgit/src/branch_compare.rs with AsyncBranchCompareJob - Added BranchCompare variant to AsyncGitNotification enum - Exported AsyncBranchCompareJob from asyncgit public API Fixes #1850
This commit is contained in:
parent
8619c07f3f
commit
3549efadf3
2 changed files with 77 additions and 0 deletions
73
asyncgit/src/branch_compare.rs
Normal file
73
asyncgit/src/branch_compare.rs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
use crate::{
|
||||
asyncjob::{AsyncJob, RunParams},
|
||||
error::Result,
|
||||
sync::{branch::branch_compare_upstream, BranchCompare, RepoPath},
|
||||
AsyncGitNotification,
|
||||
};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
enum JobState {
|
||||
Request {
|
||||
repo: RepoPath,
|
||||
branch: String,
|
||||
},
|
||||
Response(Result<BranchCompare>),
|
||||
}
|
||||
|
||||
///
|
||||
#[derive(Clone, Default)]
|
||||
pub struct AsyncBranchCompareJob {
|
||||
state: Arc<Mutex<Option<JobState>>>,
|
||||
}
|
||||
|
||||
impl AsyncBranchCompareJob {
|
||||
///
|
||||
pub fn new(repo: RepoPath, branch: String) -> Self {
|
||||
Self {
|
||||
state: Arc::new(Mutex::new(Some(JobState::Request {
|
||||
repo,
|
||||
branch,
|
||||
}))),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
pub fn result(&self) -> Option<Result<BranchCompare>> {
|
||||
if let Ok(mut state) = self.state.lock() {
|
||||
if let Some(state) = state.take() {
|
||||
return match state {
|
||||
JobState::Request { .. } => None,
|
||||
JobState::Response(result) => Some(result),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncJob for AsyncBranchCompareJob {
|
||||
type Notification = AsyncGitNotification;
|
||||
type Progress = ();
|
||||
|
||||
fn run(
|
||||
&mut self,
|
||||
_params: RunParams<Self::Notification, Self::Progress>,
|
||||
) -> Result<Self::Notification> {
|
||||
if let Ok(mut state) = self.state.lock() {
|
||||
*state = state.take().map(|state| match state {
|
||||
JobState::Request { repo, branch } => {
|
||||
let compare =
|
||||
branch_compare_upstream(&repo, &branch);
|
||||
|
||||
JobState::Response(compare)
|
||||
}
|
||||
JobState::Response(result) => {
|
||||
JobState::Response(result)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ok(AsyncGitNotification::BranchCompare)
|
||||
}
|
||||
}
|
||||
|
|
@ -45,6 +45,7 @@ It wraps libraries like git2 and gix.
|
|||
|
||||
pub mod asyncjob;
|
||||
mod blame;
|
||||
mod branch_compare;
|
||||
mod branches;
|
||||
pub mod cached;
|
||||
mod commit_files;
|
||||
|
|
@ -66,6 +67,7 @@ mod treefiles;
|
|||
|
||||
pub use crate::{
|
||||
blame::{AsyncBlame, BlameParams},
|
||||
branch_compare::AsyncBranchCompareJob,
|
||||
branches::AsyncBranchesJob,
|
||||
commit_files::{AsyncCommitFiles, CommitFilesParams},
|
||||
diff::{AsyncDiff, DiffParams, DiffType},
|
||||
|
|
@ -125,6 +127,8 @@ pub enum AsyncGitNotification {
|
|||
///
|
||||
Branches,
|
||||
///
|
||||
BranchCompare,
|
||||
///
|
||||
TreeFiles,
|
||||
///
|
||||
CommitFilter,
|
||||
|
|
|
|||
Loading…
Reference in a new issue