Skip to content

Commit 572be62

Browse files
author
Stephan Dilly
committed
cleanup having two AsyncStatus
1 parent e271def commit 572be62

File tree

5 files changed

+82
-199
lines changed

5 files changed

+82
-199
lines changed

asyncgit/src/lib.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ mod diff;
88
mod error;
99
mod revlog;
1010
mod status;
11-
mod status2;
1211
pub mod sync;
1312

1413
pub use crate::{
1514
diff::{AsyncDiff, DiffParams},
1615
revlog::AsyncLog,
17-
status::AsyncStatus,
18-
status2::{AsyncStatus2, StatusParams},
16+
status::{AsyncStatus, StatusParams},
1917
sync::{
2018
diff::{DiffLine, DiffLineType, FileDiff},
2119
status::{StatusItem, StatusItemType},
@@ -25,7 +23,6 @@ pub use crate::{
2523
use std::{
2624
collections::hash_map::DefaultHasher,
2725
hash::{Hash, Hasher},
28-
time::{SystemTime, UNIX_EPOCH},
2926
};
3027

3128
/// this type is used to communicate events back through the channel
@@ -48,11 +45,3 @@ pub fn hash<T: Hash + ?Sized>(v: &T) -> u64 {
4845
v.hash(&mut hasher);
4946
hasher.finish()
5047
}
51-
52-
/// helper function to return the current tick since unix epoch
53-
pub fn current_tick() -> u64 {
54-
SystemTime::now()
55-
.duration_since(UNIX_EPOCH)
56-
.unwrap()
57-
.as_millis() as u64
58-
}

asyncgit/src/status.rs

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::{
2-
error::Result, hash, sync, sync::status::StatusType,
3-
AsyncNotification, StatusItem, CWD,
2+
error::Result, hash, sync, AsyncNotification, StatusItem, CWD,
43
};
54
use crossbeam_channel::Sender;
65
use log::trace;
@@ -10,12 +9,42 @@ use std::{
109
atomic::{AtomicUsize, Ordering},
1110
Arc, Mutex,
1211
},
12+
time::{SystemTime, UNIX_EPOCH},
1313
};
14+
use sync::status::StatusType;
15+
16+
fn current_tick() -> u64 {
17+
SystemTime::now()
18+
.duration_since(UNIX_EPOCH)
19+
.unwrap()
20+
.as_millis() as u64
21+
}
1422

1523
#[derive(Default, Hash, Clone)]
1624
pub struct Status {
17-
pub work_dir: Vec<StatusItem>,
18-
pub stage: Vec<StatusItem>,
25+
pub items: Vec<StatusItem>,
26+
}
27+
28+
///
29+
#[derive(Default, Hash, Clone, PartialEq)]
30+
pub struct StatusParams {
31+
tick: u64,
32+
status_type: StatusType,
33+
include_untracked: bool,
34+
}
35+
36+
impl StatusParams {
37+
///
38+
pub fn new(
39+
status_type: StatusType,
40+
include_untracked: bool,
41+
) -> Self {
42+
Self {
43+
tick: current_tick(),
44+
status_type,
45+
include_untracked,
46+
}
47+
}
1948
}
2049

2150
struct Request<R, A>(R, Option<A>);
@@ -51,10 +80,13 @@ impl AsyncStatus {
5180
}
5281

5382
///
54-
pub fn fetch(&mut self, request: u64) -> Result<Option<Status>> {
55-
let hash_request = hash(&request);
83+
pub fn fetch(
84+
&mut self,
85+
params: StatusParams,
86+
) -> Result<Option<Status>> {
87+
let hash_request = hash(&params);
5688

57-
trace!("request: {} [hash: {}]", request, hash_request);
89+
trace!("request: [hash: {}]", hash_request);
5890

5991
{
6092
let mut current = self.current.lock()?;
@@ -71,10 +103,14 @@ impl AsyncStatus {
71103
let arc_last = Arc::clone(&self.last);
72104
let sender = self.sender.clone();
73105
let arc_pending = Arc::clone(&self.pending);
106+
let status_type = params.status_type;
107+
let include_untracked = params.include_untracked;
74108
rayon_core::spawn(move || {
75109
arc_pending.fetch_add(1, Ordering::Relaxed);
76110

77-
AsyncStatus::fetch_helper(
111+
Self::fetch_helper(
112+
status_type,
113+
include_untracked,
78114
hash_request,
79115
arc_current,
80116
arc_last,
@@ -92,11 +128,13 @@ impl AsyncStatus {
92128
}
93129

94130
fn fetch_helper(
131+
status_type: StatusType,
132+
include_untracked: bool,
95133
hash_request: u64,
96134
arc_current: Arc<Mutex<Request<u64, Status>>>,
97135
arc_last: Arc<Mutex<Status>>,
98136
) -> Result<()> {
99-
let res = Self::get_status()?;
137+
let res = Self::get_status(status_type, include_untracked)?;
100138
trace!("status fetched: {}", hash(&res));
101139

102140
{
@@ -114,11 +152,16 @@ impl AsyncStatus {
114152
Ok(())
115153
}
116154

117-
fn get_status() -> Result<Status> {
118-
let work_dir =
119-
sync::status::get_status(CWD, StatusType::WorkingDir)?;
120-
let stage = sync::status::get_status(CWD, StatusType::Stage)?;
121-
122-
Ok(Status { stage, work_dir })
155+
fn get_status(
156+
status_type: StatusType,
157+
include_untracked: bool,
158+
) -> Result<Status> {
159+
Ok(Status {
160+
items: sync::status::get_status_new(
161+
CWD,
162+
status_type,
163+
include_untracked,
164+
)?,
165+
})
123166
}
124167
}

asyncgit/src/status2.rs

Lines changed: 0 additions & 160 deletions
This file was deleted.

src/tabs/stashing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
};
1111
use asyncgit::{
1212
sync::{self, status::StatusType},
13-
AsyncNotification, AsyncStatus2, StatusParams, CWD,
13+
AsyncNotification, AsyncStatus, StatusParams, CWD,
1414
};
1515
use crossbeam_channel::Sender;
1616
use crossterm::event::Event;
@@ -31,7 +31,7 @@ pub struct Stashing {
3131
options: Options,
3232
index: FileTreeComponent,
3333
theme: Theme,
34-
git_status: AsyncStatus2,
34+
git_status: AsyncStatus,
3535
queue: Queue,
3636
}
3737

@@ -55,7 +55,7 @@ impl Stashing {
5555
theme,
5656
),
5757
theme: *theme,
58-
git_status: AsyncStatus2::new(sender.clone()),
58+
git_status: AsyncStatus::new(sender.clone()),
5959
queue: queue.clone(),
6060
}
6161
}

0 commit comments

Comments
 (0)