-
-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fee481
commit 92f63d1
Showing
5 changed files
with
129 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use crate::{ | ||
asyncjob::{AsyncJob, RunParams}, | ||
error::Result, | ||
sync::{branch::get_branches_info, BranchInfo, RepoPath}, | ||
AsyncGitNotification, | ||
}; | ||
use std::sync::{Arc, Mutex}; | ||
|
||
enum JobState { | ||
Request { | ||
local_branches: bool, | ||
repo: RepoPath, | ||
}, | ||
Response(Result<Vec<BranchInfo>>), | ||
} | ||
|
||
/// | ||
#[derive(Clone, Default)] | ||
pub struct AsyncBranchesJob { | ||
state: Arc<Mutex<Option<JobState>>>, | ||
} | ||
|
||
/// | ||
impl AsyncBranchesJob { | ||
/// | ||
pub fn new(repo: RepoPath, local_branches: bool) -> Self { | ||
Self { | ||
state: Arc::new(Mutex::new(Some(JobState::Request { | ||
repo, | ||
local_branches, | ||
}))), | ||
} | ||
} | ||
|
||
/// | ||
pub fn result(&self) -> Option<Result<Vec<BranchInfo>>> { | ||
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 AsyncBranchesJob { | ||
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 { | ||
local_branches, | ||
repo, | ||
} => { | ||
let branches = | ||
get_branches_info(&repo, local_branches); | ||
|
||
JobState::Response(branches) | ||
} | ||
JobState::Response(result) => { | ||
JobState::Response(result) | ||
} | ||
}); | ||
} | ||
|
||
Ok(AsyncGitNotification::Branches) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters