From b0b9fb570dda654592dac84f2052965d4f96eb38 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Mon, 23 Mar 2020 00:50:55 +0100 Subject: [PATCH] better asyncgit crate structure --- asyncgit/src/lib.rs | 14 ++++++-------- asyncgit/src/{ => sync}/diff.rs | 2 +- asyncgit/src/sync/mod.rs | 6 ++++++ asyncgit/src/{ => sync}/status.rs | 3 +-- asyncgit/src/{ => sync}/utils.rs | 0 src/app.rs | 8 ++++---- src/components/commit.rs | 3 ++- src/components/index.rs | 4 ++-- 8 files changed, 22 insertions(+), 18 deletions(-) rename asyncgit/src/{ => sync}/diff.rs (99%) create mode 100644 asyncgit/src/sync/mod.rs rename asyncgit/src/{ => sync}/status.rs (98%) rename asyncgit/src/{ => sync}/utils.rs (100%) diff --git a/asyncgit/src/lib.rs b/asyncgit/src/lib.rs index 8d9b54c6..7d721dcf 100644 --- a/asyncgit/src/lib.rs +++ b/asyncgit/src/lib.rs @@ -1,18 +1,16 @@ -mod diff; -mod status; -mod utils; +pub mod sync; -pub use crate::{ - diff::{get_diff, Diff, DiffLine, DiffLineType}, - status::{get_index, StatusItem, StatusItemType, StatusType}, - utils::{commit, index_reset, stage_add, stage_reset}, -}; use crossbeam_channel::Sender; use std::{ collections::hash_map::DefaultHasher, hash::{Hash, Hasher}, sync::{Arc, Mutex}, }; +use sync::diff::get_diff; +pub use sync::{ + diff::{Diff, DiffLine, DiffLineType}, + status::{StatusItem, StatusItemType, StatusType}, +}; #[derive(Default, Hash)] struct DiffRequest(String, bool); diff --git a/asyncgit/src/diff.rs b/asyncgit/src/sync/diff.rs similarity index 99% rename from asyncgit/src/diff.rs rename to asyncgit/src/sync/diff.rs index c6ed5fed..f01b09b4 100644 --- a/asyncgit/src/diff.rs +++ b/asyncgit/src/sync/diff.rs @@ -1,4 +1,4 @@ -use crate::utils; +use super::utils; use git2::{DiffFormat, DiffOptions}; use scopetime::scope_time; diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs new file mode 100644 index 00000000..91cef5f5 --- /dev/null +++ b/asyncgit/src/sync/mod.rs @@ -0,0 +1,6 @@ +pub mod diff; +pub mod status; +pub mod utils; + +pub use status::get_index; +pub use utils::{commit, index_reset, stage_add, stage_reset}; diff --git a/asyncgit/src/status.rs b/asyncgit/src/sync/status.rs similarity index 98% rename from asyncgit/src/status.rs rename to asyncgit/src/sync/status.rs index 44882b96..57772de2 100644 --- a/asyncgit/src/status.rs +++ b/asyncgit/src/sync/status.rs @@ -1,8 +1,7 @@ -use crate::utils; +use crate::sync::utils; use git2::{Status, StatusOptions, StatusShow}; use scopetime::scope_time; -/// #[derive(PartialEq, Copy, Clone)] pub enum StatusItemType { New, diff --git a/asyncgit/src/utils.rs b/asyncgit/src/sync/utils.rs similarity index 100% rename from asyncgit/src/utils.rs rename to asyncgit/src/sync/utils.rs diff --git a/src/app.rs b/src/app.rs index 4be09978..7e94fb2b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,7 +5,7 @@ use crate::{ }, keys, strings, }; -use asyncgit::{AsyncDiff, StatusType}; +use asyncgit::{sync, AsyncDiff, StatusType}; use crossbeam_channel::Sender; use crossterm::event::Event; use itertools::Itertools; @@ -353,7 +353,7 @@ impl App { if let Some(i) = self.index_wd.selection() { let path = Path::new(i.path.as_str()); - if asyncgit::stage_add(path) { + if sync::stage_add(path) { self.update(); } } @@ -361,7 +361,7 @@ impl App { if let Some(i) = self.index.selection() { let path = Path::new(i.path.as_str()); - if asyncgit::stage_reset(path) { + if sync::stage_reset(path) { self.update(); } } @@ -373,7 +373,7 @@ impl App { if let Some(i) = self.index_wd.selection() { let path = Path::new(i.path.as_str()); - if asyncgit::index_reset(path) { + if sync::index_reset(path) { self.update(); } } diff --git a/src/components/commit.rs b/src/components/commit.rs index 5d6131ba..933a47d6 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -1,5 +1,6 @@ use super::{CommandInfo, Component}; use crate::{strings, ui}; +use asyncgit::sync; use crossterm::event::{Event, KeyCode}; use std::borrow::Cow; use tui::{ @@ -100,7 +101,7 @@ impl Component for CommitComponent { impl CommitComponent { fn commit(&mut self) { - asyncgit::commit(&self.msg); + sync::commit(&self.msg); self.msg.clear(); self.hide(); diff --git a/src/components/index.rs b/src/components/index.rs index 34a9f1e7..828b2735 100644 --- a/src/components/index.rs +++ b/src/components/index.rs @@ -1,6 +1,6 @@ use crate::components::{CommandInfo, Component}; use crate::ui; -use asyncgit::{StatusItem, StatusItemType, StatusType}; +use asyncgit::{sync, StatusItem, StatusItemType, StatusType}; use crossterm::event::{Event, KeyCode}; use std::{borrow::Cow, cmp}; use tui::{ @@ -39,7 +39,7 @@ impl IndexComponent { } /// pub fn update(&mut self) { - let new_status = asyncgit::get_index(self.index_type.into()); + let new_status = sync::get_index(self.index_type.into()); if self.items != new_status { self.items = new_status;