Skip to content

Commit 24892bb

Browse files
committed
Add AsyncFileLogJob
1 parent b503177 commit 24892bb

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

asyncgit/src/file_log.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//!
2+
3+
use crate::asyncjob::{AsyncJob, RunParams};
4+
use crate::error::Result;
5+
use crate::sync::CommitId;
6+
use crate::AsyncGitNotification;
7+
use crate::StatusItemType;
8+
use std::sync::Arc;
9+
use std::sync::Mutex;
10+
11+
enum JobState {
12+
Request(String),
13+
Response(Result<Vec<(CommitId, StatusItemType)>>),
14+
}
15+
16+
///
17+
#[derive(Clone, Default)]
18+
pub struct AsyncFileLogJob {
19+
state: Arc<Mutex<Option<JobState>>>,
20+
}
21+
22+
impl AsyncFileLogJob {
23+
///
24+
pub fn new(file_path: &str) -> Self {
25+
Self {
26+
state: Arc::new(Mutex::new(Some(JobState::Request(
27+
file_path.into(),
28+
)))),
29+
}
30+
}
31+
}
32+
33+
impl AsyncJob for AsyncFileLogJob {
34+
type Notification = AsyncGitNotification;
35+
type Progress = ();
36+
37+
fn run(
38+
&mut self,
39+
_params: RunParams<Self::Notification, Self::Progress>,
40+
) -> Result<Self::Notification> {
41+
if let Ok(mut state) = self.state.lock() {
42+
*state = Some(JobState::Response(Ok(vec![])));
43+
}
44+
45+
Ok(AsyncGitNotification::FileLog)
46+
}
47+
}
48+
49+
// fn get_file_status(&self, commit_id: CommitId) -> char {
50+
// self.file_path
51+
// .as_ref()
52+
// .and_then(|file_path| {
53+
// let repo = repo(CWD);
54+
55+
// repo.ok().and_then(|repo| {
56+
// let diff = get_commit_diff(
57+
// &repo,
58+
// commit_id,
59+
// Some(file_path.clone()),
60+
// );
61+
62+
// diff.ok().and_then(|diff| {
63+
// diff.deltas().next().map(|delta| {
64+
// let status: StatusItemType =
65+
// delta.status().into();
66+
67+
// match status {
68+
// StatusItemType::New => 'A',
69+
// StatusItemType::Deleted => 'D',
70+
// _ => 'M',
71+
// }
72+
// })
73+
// })
74+
// })
75+
// })
76+
// .unwrap_or(' ')
77+
// }

asyncgit/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ mod commit_files;
2929
mod diff;
3030
mod error;
3131
mod fetch_job;
32+
pub mod file_log;
3233
mod progress;
3334
mod pull;
3435
mod push;
@@ -77,6 +78,8 @@ pub enum AsyncGitNotification {
7778
///
7879
Log,
7980
///
81+
FileLog,
82+
///
8083
CommitFiles,
8184
///
8285
Tags,

src/components/file_revlog.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use crate::{
1212
};
1313
use anyhow::Result;
1414
use asyncgit::{
15+
asyncjob::AsyncSingleJob,
16+
file_log::AsyncFileLogJob,
1517
sync::{
1618
diff_contains_file, get_commits_info, CommitId, RepoPathRef,
1719
},
@@ -39,6 +41,7 @@ static DETAILS_WIDTH: u16 =
3941
///
4042
pub struct FileRevlogComponent {
4143
git_log: Option<AsyncLog>,
44+
async_file_log: AsyncSingleJob<AsyncFileLogJob>,
4245
theme: SharedTheme,
4346
queue: Queue,
4447
sender: Sender<AsyncGitNotification>,
@@ -65,6 +68,7 @@ impl FileRevlogComponent {
6568
queue: queue.clone(),
6669
sender: sender.clone(),
6770
git_log: None,
71+
async_file_log: AsyncSingleJob::new(sender.clone()),
6872
visible: false,
6973
repo_path: repo_path.clone(),
7074
file_path: None,
@@ -98,7 +102,7 @@ impl FileRevlogComponent {
98102

99103
///
100104
pub fn any_work_pending(&self) -> bool {
101-
self.git_log.as_ref().map_or(false, AsyncLog::is_pending)
105+
self.async_file_log.is_pending()
102106
}
103107

104108
///
@@ -188,6 +192,8 @@ impl FileRevlogComponent {
188192
self.items
189193
.iter()
190194
.map(|entry| {
195+
// let status = self.get_file_status(entry.id);
196+
191197
let spans = Spans::from(vec![
192198
Span::styled(
193199
entry.hash_short.to_string(),
@@ -210,6 +216,11 @@ impl FileRevlogComponent {
210216

211217
let cells = vec![Cell::from(""), Cell::from(text)];
212218

219+
// let cells = vec![
220+
// Cell::from(status.to_string()),
221+
// Cell::from(text),
222+
// ];
223+
213224
Row::new(cells).height(2)
214225
})
215226
.collect()

0 commit comments

Comments
 (0)