Skip to content

Commit fc21f4b

Browse files
committed
Add AsyncFileLogJob
1 parent 721f184 commit fc21f4b

File tree

4 files changed

+93
-2
lines changed

4 files changed

+93
-2
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;
32+
pub mod file_log;
3233
mod progress;
3334
mod push;
3435
mod push_tags;
@@ -75,6 +76,8 @@ pub enum AsyncGitNotification {
7576
///
7677
Log,
7778
///
79+
FileLog,
80+
///
7881
CommitFiles,
7982
///
8083
Tags,

asyncgit/src/sync/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn is_bare_repo(repo_path: &str) -> Result<bool> {
4444
}
4545

4646
///
47-
pub(crate) fn repo(repo_path: &str) -> Result<Repository> {
47+
pub fn repo(repo_path: &str) -> Result<Repository> {
4848
let repo = Repository::open_ext(
4949
repo_path,
5050
RepositoryOpenFlags::empty(),

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::{diff_contains_file, get_commits_info, CommitId},
1618
AsyncGitNotification, AsyncLog, FetchStatus, CWD,
1719
};
@@ -37,6 +39,7 @@ static DETAILS_WIDTH: u16 =
3739
///
3840
pub struct FileRevlogComponent {
3941
git_log: Option<AsyncLog>,
42+
async_file_log: AsyncSingleJob<AsyncFileLogJob>,
4043
theme: SharedTheme,
4144
queue: Queue,
4245
sender: Sender<AsyncGitNotification>,
@@ -61,6 +64,7 @@ impl FileRevlogComponent {
6164
queue: queue.clone(),
6265
sender: sender.clone(),
6366
git_log: None,
67+
async_file_log: AsyncSingleJob::new(sender.clone()),
6468
visible: false,
6569
file_path: None,
6670
table_state: std::cell::Cell::new(TableState::default()),
@@ -87,7 +91,7 @@ impl FileRevlogComponent {
8791

8892
///
8993
pub fn any_work_pending(&self) -> bool {
90-
self.git_log.as_ref().map_or(false, AsyncLog::is_pending)
94+
self.async_file_log.is_pending()
9195
}
9296

9397
///
@@ -177,6 +181,8 @@ impl FileRevlogComponent {
177181
self.items
178182
.iter()
179183
.map(|entry| {
184+
// let status = self.get_file_status(entry.id);
185+
180186
let spans = Spans::from(vec![
181187
Span::styled(
182188
entry.hash_short.to_string(),
@@ -199,6 +205,11 @@ impl FileRevlogComponent {
199205

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

208+
// let cells = vec![
209+
// Cell::from(status.to_string()),
210+
// Cell::from(text),
211+
// ];
212+
202213
Row::new(cells).height(2)
203214
})
204215
.collect()

0 commit comments

Comments
 (0)