diff --git a/Cargo.lock b/Cargo.lock index 7df14ca6..d4ae2ab7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -290,7 +290,6 @@ dependencies = [ "crossbeam-channel", "crossterm 0.15.0", "dirs", - "git2", "itertools 0.9.0", "log", "scopetime", diff --git a/Cargo.toml b/Cargo.toml index 60b399a0..72beb470 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ homepage = "https://gitui.org" edition = "2018" [dependencies] -git2 = "0.10" crossterm = "0.15" itertools = "0.9" log = "0.4" diff --git a/asyncgit/src/lib.rs b/asyncgit/src/lib.rs index a2f5e680..8d9b54c6 100644 --- a/asyncgit/src/lib.rs +++ b/asyncgit/src/lib.rs @@ -1,7 +1,13 @@ mod diff; +mod status; +mod utils; +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; -pub use diff::{get_diff, Diff, DiffLine, DiffLineType}; use std::{ collections::hash_map::DefaultHasher, hash::{Hash, Hasher}, diff --git a/src/git_status.rs b/asyncgit/src/status.rs similarity index 77% rename from src/git_status.rs rename to asyncgit/src/status.rs index 72081cbe..44882b96 100644 --- a/src/git_status.rs +++ b/asyncgit/src/status.rs @@ -1,7 +1,8 @@ -use crate::git_utils; +use crate::utils; use git2::{Status, StatusOptions, StatusShow}; use scopetime::scope_time; +/// #[derive(PartialEq, Copy, Clone)] pub enum StatusItemType { New, @@ -27,21 +28,39 @@ impl From for StatusItemType { } } +/// #[derive(Default, PartialEq, Clone)] pub struct StatusItem { pub path: String, pub status: Option, } -pub fn get_index(show: StatusShow) -> Vec { +/// +#[derive(Copy, Clone)] +pub enum StatusType { + WorkingDir, + Stage, +} + +impl Into for StatusType { + fn into(self) -> StatusShow { + match self { + StatusType::WorkingDir => StatusShow::Workdir, + StatusType::Stage => StatusShow::Index, + } + } +} + +/// +pub fn get_index(status_type: StatusType) -> Vec { scope_time!("get_index"); - let repo = git_utils::repo(); + let repo = utils::repo(); let statuses = repo .statuses(Some( StatusOptions::default() - .show(show) + .show(status_type.into()) .include_untracked(true) .renames_head_to_index(true) .recurse_untracked_dirs(true), diff --git a/src/git_utils.rs b/asyncgit/src/utils.rs similarity index 99% rename from src/git_utils.rs rename to asyncgit/src/utils.rs index 1c3f9386..05fa8cfe 100644 --- a/src/git_utils.rs +++ b/asyncgit/src/utils.rs @@ -46,6 +46,7 @@ pub fn commit(msg: &String) { .unwrap(); } +/// pub fn stage_add(path: &Path) -> bool { scope_time!("stage_add"); @@ -73,6 +74,7 @@ pub fn stage_add(path: &Path) -> bool { false } +/// pub fn stage_reset(path: &Path) -> bool { scope_time!("stage_reset"); @@ -93,6 +95,7 @@ pub fn stage_reset(path: &Path) -> bool { false } +/// pub fn index_reset(path: &Path) -> bool { scope_time!("index_reset"); diff --git a/src/app.rs b/src/app.rs index d0bd6d67..4be09978 100644 --- a/src/app.rs +++ b/src/app.rs @@ -3,12 +3,11 @@ use crate::{ CommandInfo, CommitComponent, Component, DiffComponent, IndexComponent, }, - git_utils, keys, strings, + keys, strings, }; -use asyncgit::AsyncDiff; +use asyncgit::{AsyncDiff, StatusType}; use crossbeam_channel::Sender; use crossterm::event::Event; -use git2::StatusShow; use itertools::Itertools; use log::trace; use std::{borrow::Cow, path::Path}; @@ -57,12 +56,12 @@ impl App { commit: CommitComponent::default(), index_wd: IndexComponent::new( strings::TITLE_STATUS, - StatusShow::Workdir, + StatusType::WorkingDir, true, ), index: IndexComponent::new( strings::TITLE_INDEX, - StatusShow::Index, + StatusType::Stage, false, ), diff: DiffComponent::default(), @@ -354,7 +353,7 @@ impl App { if let Some(i) = self.index_wd.selection() { let path = Path::new(i.path.as_str()); - if git_utils::stage_add(path) { + if asyncgit::stage_add(path) { self.update(); } } @@ -362,7 +361,7 @@ impl App { if let Some(i) = self.index.selection() { let path = Path::new(i.path.as_str()); - if git_utils::stage_reset(path) { + if asyncgit::stage_reset(path) { self.update(); } } @@ -374,7 +373,7 @@ impl App { if let Some(i) = self.index_wd.selection() { let path = Path::new(i.path.as_str()); - if git_utils::index_reset(path) { + if asyncgit::index_reset(path) { self.update(); } } diff --git a/src/components/commit.rs b/src/components/commit.rs index a26c7d02..5d6131ba 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -1,5 +1,5 @@ use super::{CommandInfo, Component}; -use crate::{git_utils, strings, ui}; +use crate::{strings, ui}; use crossterm::event::{Event, KeyCode}; use std::borrow::Cow; use tui::{ @@ -100,7 +100,7 @@ impl Component for CommitComponent { impl CommitComponent { fn commit(&mut self) { - git_utils::commit(&self.msg); + asyncgit::commit(&self.msg); self.msg.clear(); self.hide(); diff --git a/src/components/index.rs b/src/components/index.rs index 6e063557..34a9f1e7 100644 --- a/src/components/index.rs +++ b/src/components/index.rs @@ -1,10 +1,7 @@ use crate::components::{CommandInfo, Component}; -use crate::{ - git_status::{self, StatusItem, StatusItemType}, - ui, -}; +use crate::ui; +use asyncgit::{StatusItem, StatusItemType, StatusType}; use crossterm::event::{Event, KeyCode}; -use git2::StatusShow; use std::{borrow::Cow, cmp}; use tui::{ backend::Backend, @@ -18,7 +15,7 @@ use tui::{ pub struct IndexComponent { title: String, items: Vec, - index_type: StatusShow, + index_type: StatusType, selection: Option, focused: bool, show_selection: bool, @@ -28,7 +25,7 @@ impl IndexComponent { /// pub fn new( title: &str, - index_type: StatusShow, + index_type: StatusType, focus: bool, ) -> Self { Self { @@ -42,7 +39,7 @@ impl IndexComponent { } /// pub fn update(&mut self) { - let new_status = git_status::get_index(self.index_type); + let new_status = asyncgit::get_index(self.index_type.into()); if self.items != new_status { self.items = new_status; diff --git a/src/main.rs b/src/main.rs index 85f02570..d1931be4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,5 @@ mod app; mod components; -mod git_status; -mod git_utils; mod keys; mod poll; mod strings;