Skip to content

Commit b4a6e16

Browse files
committed
refactor
1 parent fd2e5ba commit b4a6e16

File tree

15 files changed

+49
-43
lines changed

15 files changed

+49
-43
lines changed

DEVELOPMENT.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
* ...even if that includes only the most common usecases.
1818
* **Prefer to increment major version rapidly...**
1919
* ...instead of keeping major version zero for longer than needed.
20+
* **stability**
21+
* we adhere to semantic versioning
22+
* while below 1.0, expect a greater amount of breaking changes, which are announced with minor versions
23+
* From 1.0, we will try hardest to keep the API and user interface non-breaking the closer to the user a library is. Thus the CLI should remain at version
24+
1 for a long times. However, crates that make it up can change more rapidly and may see more major version changes over time.
2025

2126
### Guidelines
2227

@@ -30,15 +35,15 @@
3035
* `blocking` can be used to make `Read` and `Iterator` async, or move any operation onto a thread which blends it into the
3136
async world.
3237
* Most operations are fast and 'interrupting' them is as easy as ignoring their result by cancelling their task.
33-
* Long-running operations can be roughly interacted with using `git_features::interruptible::interrupt()` function, and after a moment
38+
* Long-running operations can be roughly interacted with using `git_features::interrupt::trigger()` function, and after a moment
3439
of waiting the flag can be unset with the `…::uninterrupt()` function to allow new long-running operations to work.
3540
Every long running operation supports this.
3641
* **server-side**
3742
* Building a pack is CPU and at some point, IO bound, and it makes no sense to use async to handle more connections - git
3843
needs a lot of resources and threads will do just fine.
3944

4045
* **interruption of long-running operations**
41-
* Use `git-features::interruptible::*` for building support for interruptions of long-running operations only.
46+
* Use `git-features::interrupt::*` for building support for interruptions of long-running operations only.
4247
* It's up to the author to decide how to best integrate it, generally we use a poll-based mechanism to check whether
4348
an interrupt flag is set.
4449
* **this is a must if…**

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
109109
* [ ] multi-ack
110110
* [ ] multi-ack detailed
111111
* [ ] [server-response (pack)](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L404:L404)
112+
* [ ] [side-band mode](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L467:L467)
112113
* [ ] push
113114
* [ ] [Version 2](https://github.com/git/git/blob/master/Documentation/technical/protocol-v2.txt)
114115

@@ -264,7 +265,7 @@ Once installed, there are two binaries:
264265
* **use async IO everywhere**
265266
* for the most part, git operations are heavily relying on memory mapped IO as well as CPU to decompress data,
266267
which doesn't lend itself well to async IO out of the box.
267-
* Use `blocking` as well as `git-features::interruptible` to bring operations into the async world and to control
268+
* Use `blocking` as well as `git-features::interrupt` to bring operations into the async world and to control
268269
long running operations.
269270
* When connecting or streaming over TCP connections, especially when receiving on the server, async seems like a must
270271
though, but behind a feature flag.
@@ -340,7 +341,7 @@ All feature toggles are additive.
340341
CPUs that support it, like AMD Ryzen or Intel Core i3.
341342
* **interrupt-handler**
342343
* Listen to interrupts and termination requests and provide long-running operations tooling to allow aborting the input stream.
343-
* **Note that** `git_features::interruptible::init_interrupt_handler()` must be called at the start of the application.
344+
* **Note that** `git_features::interrupt::init_handler()` must be called at the start of the application.
344345
* If unset, these utilities will be a no-op which may lead to leaking temporary files when interrupted.
345346
* If the application already sets a handler, this handler will have no effect.
346347

git-features/src/interruptible.rs renamed to git-features/src/interrupt.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod _impl {
1010
sync::atomic::{AtomicUsize, Ordering},
1111
};
1212

13-
pub fn init_interrupt_handler(mut message_channel: impl io::Write + Send + 'static) {
13+
pub fn init_handler(mut message_channel: impl io::Write + Send + 'static) {
1414
ctrlc::set_handler(move || {
1515
const MESSAGES: &[&str] = &[
1616
"interrupt requested",
@@ -19,7 +19,7 @@ mod _impl {
1919
"if the program doesn't respond quickly enough, please let us know here: https://github.com/Byron/gitoxide/issues"
2020
];
2121
static CURRENT_MESSAGE: AtomicUsize = AtomicUsize::new(0);
22-
if !super::is_interrupted() {
22+
if !super::is_triggered() {
2323
CURRENT_MESSAGE.store(0, Ordering::Relaxed);
2424
}
2525
let msg_idx =CURRENT_MESSAGE.fetch_add(1, Ordering::Relaxed);
@@ -33,9 +33,9 @@ mod _impl {
3333
mod _impl {
3434
use std::io;
3535

36-
pub fn init_interrupt_handler(_message_channel: impl io::Write + Send + 'static) {}
36+
pub fn init_handler(_message_channel: impl io::Write + Send + 'static) {}
3737
}
38-
pub use _impl::init_interrupt_handler;
38+
pub use _impl::init_handler;
3939

4040
pub struct Read<R> {
4141
pub inner: R,
@@ -46,7 +46,7 @@ where
4646
R: io::Read,
4747
{
4848
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
49-
if is_interrupted() {
49+
if is_triggered() {
5050
return Err(io::Error::new(io::ErrorKind::Other, "interrupted by user"));
5151
}
5252
self.inner.read(buf)
@@ -55,13 +55,13 @@ where
5555

5656
static IS_INTERRUPTED: AtomicBool = AtomicBool::new(false);
5757

58-
pub fn is_interrupted() -> bool {
58+
pub fn is_triggered() -> bool {
5959
IS_INTERRUPTED.load(Ordering::Relaxed)
6060
}
61-
pub fn interrupt() {
61+
pub fn trigger() {
6262
IS_INTERRUPTED.store(true, Ordering::Relaxed);
6363
}
64-
pub fn uninterrupt() {
64+
pub fn reset() {
6565
IS_INTERRUPTED.store(false, Ordering::Relaxed);
6666
}
6767

@@ -70,24 +70,24 @@ pub fn uninterrupt() {
7070
///
7171
/// Note that this is inherently racy and that this will only work deterministically if there is only one
7272
/// top-level function running in a process.
73-
pub struct ResetInterruptOnDrop {
73+
pub struct ResetOnDrop {
7474
was_interrupted: bool,
7575
}
7676

77-
impl Default for ResetInterruptOnDrop {
77+
impl Default for ResetOnDrop {
7878
fn default() -> Self {
79-
ResetInterruptOnDrop {
80-
was_interrupted: is_interrupted(),
79+
ResetOnDrop {
80+
was_interrupted: is_triggered(),
8181
}
8282
}
8383
}
8484

85-
impl Drop for ResetInterruptOnDrop {
85+
impl Drop for ResetOnDrop {
8686
fn drop(&mut self) {
8787
if self.was_interrupted {
88-
interrupt()
88+
trigger()
8989
} else {
90-
uninterrupt()
90+
reset()
9191
}
9292
}
9393
}

git-features/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![forbid(unsafe_code)]
22

33
pub mod hash;
4-
pub mod interruptible;
4+
pub mod interrupt;
55
pub mod parallel;
66
pub mod progress;

git-odb/src/hash.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use git_features::hash;
2-
use git_features::interruptible::is_interrupted;
2+
use git_features::interrupt::is_triggered;
33
use git_object::{owned, HashKind};
44
use std::{io, path::Path};
55

@@ -58,7 +58,7 @@ pub(crate) fn bytes_of_file(
5858
bytes_left -= out.len();
5959
progress.inc_by(out.len());
6060
hasher.update(out);
61-
if is_interrupted() {
61+
if is_triggered() {
6262
return Err(io::Error::new(io::ErrorKind::Other, "Interrupted"));
6363
}
6464
}

git-odb/src/pack/bundle/write/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use filebuffer::FileBuffer;
22

33
use crate::pack;
4-
use git_features::{interruptible, progress, progress::Progress};
4+
use git_features::{interrupt, progress, progress::Progress};
55
use std::{
66
io,
77
path::{Path, PathBuf},
@@ -56,7 +56,7 @@ impl pack::Bundle {
5656
}));
5757
let data_path: PathBuf = data_file.lock().path().into();
5858
let pack = PassThrough {
59-
reader: interruptible::Read { inner: pack },
59+
reader: interrupt::Read { inner: pack },
6060
writer: Some(data_file.clone()),
6161
};
6262
let eight_pages = 4096 * 8;

git-odb/src/pack/index/traverse/indexed.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
pack::index::{self, util::index_entries_sorted_by_offset_ascending},
55
pack::tree::traverse::Context,
66
};
7-
use git_features::interruptible::{interrupt, ResetInterruptOnDrop};
7+
use git_features::interrupt::{trigger, ResetOnDrop};
88
use git_features::{parallel, progress::Progress};
99
use git_object::owned;
1010

@@ -28,15 +28,15 @@ impl index::File {
2828
) -> Result<(), E>,
2929
E: std::error::Error + Send + Sync + 'static,
3030
{
31-
let _reset_interrupt = ResetInterruptOnDrop::default();
31+
let _reset_interrupt = ResetOnDrop::default();
3232
let (verify_result, traversal_result) = parallel::join(
3333
{
3434
let pack_progress = root.add_child("SHA1 of pack");
3535
let index_progress = root.add_child("SHA1 of index");
3636
move || {
3737
let res = self.possibly_verify(pack, check, pack_progress, index_progress);
3838
if res.is_err() {
39-
interrupt();
39+
trigger();
4040
}
4141
res
4242
}

git-odb/src/pack/index/traverse/lookup.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{Error, Reducer, SafetyCheck};
22
use crate::pack::{self, data::decode, index, index::util};
3-
use git_features::interruptible::ResetInterruptOnDrop;
3+
use git_features::interrupt::ResetOnDrop;
44
use git_features::{
55
parallel::{self, in_parallel_if},
66
progress::{self, unit, Progress},
@@ -31,15 +31,15 @@ impl index::File {
3131
&mut <<P as Progress>::SubProgress as Progress>::SubProgress,
3232
) -> Result<(), E>,
3333
{
34-
let _reset_interrupt = ResetInterruptOnDrop::default();
34+
let _reset_interrupt = ResetOnDrop::default();
3535
let (verify_result, traversal_result) = parallel::join(
3636
{
3737
let pack_progress = root.add_child("SHA1 of pack");
3838
let index_progress = root.add_child("SHA1 of index");
3939
move || {
4040
let res = self.possibly_verify(pack, check, pack_progress, index_progress);
4141
if res.is_err() {
42-
git_features::interruptible::interrupt();
42+
git_features::interrupt::trigger();
4343
}
4444
res
4545
}

git-odb/src/pack/index/traverse/reduce.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::pack::{data::decode, index::traverse};
2-
use git_features::{interruptible::is_interrupted, parallel, progress::Progress};
2+
use git_features::{interrupt::is_triggered, parallel, progress::Progress};
33
use std::time::Instant;
44

55
fn add_decode_result(lhs: &mut decode::Outcome, rhs: decode::Outcome) {
@@ -87,7 +87,7 @@ where
8787
add_decode_result(&mut self.stats.average, chunk_total);
8888
self.progress.lock().set(self.entries_seen);
8989

90-
if is_interrupted() {
90+
if is_triggered() {
9191
return Err(Self::Error::Interrupted);
9292
}
9393
Ok(())

git-odb/src/pack/tree/from_offsets.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{pack, pack::index::access::PackOffset, pack::tree::Tree};
22
use git_features::{
3-
interruptible::is_interrupted,
3+
interrupt::is_triggered,
44
progress::{self, Progress},
55
};
66
use quick_error::quick_error;
@@ -105,7 +105,7 @@ impl<T> Tree<T> {
105105
}
106106
};
107107
progress.inc();
108-
if idx % 10_000 == 0 && is_interrupted() {
108+
if idx % 10_000 == 0 && is_triggered() {
109109
return Err(Error::Interrupted);
110110
}
111111
}

git-odb/src/pack/tree/traverse/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
pack::tree::{Item, Tree},
55
};
66
use git_features::{
7-
interruptible::is_interrupted,
7+
interrupt::is_triggered,
88
parallel,
99
parallel::in_parallel_if,
1010
progress::{self, Progress},
@@ -127,7 +127,7 @@ where
127127
self.item_count += num_objects;
128128
self.size_progress.inc_by(decompressed_size as usize);
129129
self.progress.lock().set(self.item_count);
130-
if is_interrupted() {
130+
if is_triggered() {
131131
return Err(Error::Interrupted);
132132
}
133133
Ok(())

src/plumbing/lean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fn prepare(
173173
pub fn main() -> Result<()> {
174174
pub use options::*;
175175
let cli: Args = crate::shared::from_env();
176-
git_features::interruptible::init_interrupt_handler(std::io::stderr());
176+
git_features::interrupt::init_handler(std::io::stderr());
177177
let thread_limit = cli.threads;
178178
let verbose = cli.verbose;
179179
match cli.subcommand {

src/plumbing/pretty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fn prepare_and_run<T: Send + 'static>(
176176
) -> Result<T> {
177177
use crate::shared::{self, STANDARD_RANGE};
178178
super::init_env_logger(false);
179-
use git_features::interruptible::{interrupt, is_interrupted};
179+
use git_features::interrupt::{is_triggered, trigger};
180180
match (verbose, progress) {
181181
(false, false) => run(None, &mut stdout(), &mut stderr()),
182182
(true, false) => {
@@ -192,7 +192,7 @@ fn prepare_and_run<T: Send + 'static>(
192192
let tx = tx.clone();
193193
move || loop {
194194
std::thread::sleep(std::time::Duration::from_millis(500));
195-
if is_interrupted() {
195+
if is_triggered() {
196196
tx.send(Event::UIDone).ok();
197197
break;
198198
}
@@ -253,7 +253,7 @@ fn prepare_and_run<T: Send + 'static>(
253253
Event::UIDone => {
254254
// We don't know why the UI is done, usually it's the user aborting.
255255
// We need the computation to stop as well so let's wait for that to happen
256-
interrupt();
256+
trigger();
257257
continue;
258258
}
259259
Event::ComputationDone(res, out, err) => {
@@ -277,7 +277,7 @@ pub fn main() -> Result<()> {
277277
format,
278278
cmd,
279279
} = Args::parse();
280-
git_features::interruptible::init_interrupt_handler(std::io::stderr());
280+
git_features::interrupt::init_handler(std::io::stderr());
281281

282282
match cmd {
283283
Subcommands::IndexFromPack {

src/porcelain/lean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use gitoxide_core as core;
3030
pub fn main() -> Result<()> {
3131
pub use options::*;
3232
let cli: Args = crate::shared::from_env();
33-
git_features::interruptible::init_interrupt_handler(std::io::stderr());
33+
git_features::interrupt::init_handler(std::io::stderr());
3434

3535
match cli.subcommand {
3636
SubCommands::Init(_) => core::repository::init(),

src/porcelain/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod options {
2727
pub fn main() -> Result<()> {
2828
use options::*;
2929
let args = Args::parse();
30-
git_features::interruptible::init_interrupt_handler(std::io::stderr());
30+
git_features::interrupt::init_handler(std::io::stderr());
3131
match args.cmd {
3232
Subcommands::Init => core::repository::init(),
3333
}?;

0 commit comments

Comments
 (0)