• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MitMaro / git-interactive-rebase-tool / 14340401715

08 Apr 2025 06:00PM UTC coverage: 95.488% (-1.9%) from 97.339%
14340401715

Pull #959

github

web-flow
Merge 755a26246 into aa2157af9
Pull Request #959: WIP: Move Diff to Thread

372 of 483 new or added lines in 31 files covered. (77.02%)

4 existing lines in 2 files now uncovered.

4741 of 4965 relevant lines covered (95.49%)

2.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/src/diff/state.rs
1
use std::sync::{
2
        Arc,
3
        atomic::{AtomicBool, Ordering},
4
};
5

6
use parking_lot::RwLock;
7

8
use crate::diff::{Action, CommitDiff};
9

10
// TODO move
11
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
12
pub(crate) enum LoadStatus {
13
        New,
14
        QuickDiff(usize, usize),
15
        CompleteQuickDiff,
16
        Diff(usize, usize),
17
        DiffComplete,
18
}
19

20
#[derive(Clone, Debug)]
21
pub(crate) struct State {
22
        load_status: Arc<RwLock<LoadStatus>>,
23
        diff: Arc<RwLock<CommitDiff>>,
24
        ended: Arc<AtomicBool>,
25
        cancelled: Arc<AtomicBool>,
26
        update_receiver: crossbeam_channel::Receiver<Action>,
27
        update_sender: crossbeam_channel::Sender<Action>,
28
}
29

30
impl State {
31
        pub(crate) fn new(diff: Arc<RwLock<CommitDiff>>) -> Self {
1✔
32
                let (update_sender, update_receiver) = crossbeam_channel::unbounded();
2✔
33
                Self {
34
                        load_status: Arc::new(RwLock::new(LoadStatus::New)),
2✔
35
                        diff,
36
                        ended: Arc::new(AtomicBool::from(false)),
2✔
37
                        cancelled: Arc::new(AtomicBool::from(false)),
2✔
38
                        update_receiver,
39
                        update_sender,
40
                }
41
        }
42

43
        pub(crate) fn load_status(&self) -> Arc<RwLock<LoadStatus>> {
1✔
44
                Arc::clone(&self.load_status)
1✔
45
        }
46

47
        pub(crate) fn diff(&self) -> Arc<RwLock<CommitDiff>> {
1✔
48
                Arc::clone(&self.diff)
1✔
49
        }
50

51
        pub(crate) fn receive_update(&self) -> Action {
1✔
52
                self.update_receiver.recv().unwrap_or(Action::End)
1✔
53
        }
54

55
        pub(crate) fn send_update(&self, action: Action) {
1✔
56
                let _result = self.update_sender.send(action);
1✔
57
        }
58

59
        pub(crate) fn is_cancelled(&self) -> bool {
1✔
60
                self.cancelled.load(Ordering::Acquire) || self.ended.load(Ordering::Acquire)
1✔
61
        }
62

63
        pub(crate) fn is_ended(&self) -> bool {
1✔
64
                self.ended.load(Ordering::Acquire)
1✔
65
        }
66

NEW
67
        pub(crate) fn cancel(&self) {
×
NEW
68
                self.cancelled.store(true, Ordering::Release);
×
69
        }
70

NEW
71
        pub(crate) fn resume(&self) {
×
NEW
72
                self.cancelled.store(false, Ordering::Release);
×
73
        }
74

75
        pub(crate) fn end(&self) {
1✔
76
                self.ended.store(true, Ordering::Release);
1✔
77
                self.send_update(Action::End);
1✔
78
        }
79
}
80
// #[cfg(test)]
81
// mod tests {
82
//
83
//         use super::*;
84
//
85
//         #[test]
86
//         fn send_recv_update() {
87
//                 let state = State::new();
88
//                 state.send_update(Action::Start(String::from("test")));
89
//                 assert!(matches!(state.receive_update(), Action::Start(_)));
90
//         }
91
//
92
//         #[test]
93
//         fn send_recv_update_timeout() {
94
//                 let state = State::new();
95
//                 assert!(matches!(state.receive_update(), Action::Continue));
96
//         }
97
//
98
//         #[test]
99
//         fn send_recv_disconnect() {
100
//                 let (update_sender, _update_receiver) = crossbeam_channel::unbounded();
101
//                 let mut state = State::new();
102
//                 state.update_sender = update_sender; // replace last reference to sender, to force a disconnect
103
//                 assert!(matches!(state.receive_update(), Action::End));
104
//         }
105
//
106
//         #[test]
107
//         fn paused() {
108
//                 let state = State::new();
109
//                 state.pause();
110
//                 assert!(state.is_paused());
111
//         }
112
//
113
//         #[test]
114
//         fn resumed() {
115
//                 let state = State::new();
116
//                 state.resume();
117
//                 assert!(!state.is_paused());
118
//         }
119
//
120
//         #[test]
121
//         fn ended() {
122
//                 let state = State::new();
123
//                 state.end();
124
//                 assert!(state.is_ended());
125
//         }
126
// }
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc