Skip to content

Use filetreelist crate #1508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* changes in commit message inside external editor [[@bc-universe]](https://github.com/bc-universe) ([#1420](https://github.com/extrawurst/gitui/issues/1420))
* add no-verify option on commits to not run hooks [[@dam5h]](https://github.com/dam5h) ([#1374](https://github.com/extrawurst/gitui/issues/1374))
* allow `fetch` on status tab [[@alensiljak]](https://github.com/alensiljak) ([#1471](https://github.com/extrawurst/gitui/issues/1471))
* Use `filetreelist` crate for the status tree. [[@abergmeier]](https://github.com/abergmeier) ([#1504](https://github.com/extrawurst/gitui/issues/1504))

### Fixes
* commit msg history ordered the wrong way ([#1445](https://github.com/extrawurst/gitui/issues/1445))
Expand Down
67 changes: 38 additions & 29 deletions src/components/changes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::{
status_tree::StatusTreeComponent,
utils::filetree::{FileTreeItem, FileTreeItemKind},
CommandBlocking, DrawableComponent,
status_tree::StatusTreeComponent, CommandBlocking,
DrawableComponent,
};
use crate::{
components::{CommandInfo, Component, EventState},
Expand All @@ -17,6 +16,7 @@ use asyncgit::{
StatusItem, StatusItemType,
};
use crossterm::event::Event;
use filetreelist::FileTreeItem;
use std::path::Path;
use tui::{backend::Backend, layout::Rect, Frame};

Expand Down Expand Up @@ -68,10 +68,14 @@ impl ChangesComponent {
}

///
pub fn selection(&self) -> Option<FileTreeItem> {
pub fn selection_ref(&self) -> Option<&FileTreeItem> {
self.files.selection()
}

pub fn selection_status(&self) -> Option<StatusItem> {
self.files.selection_status()
}

///
pub fn focus_select(&mut self, focus: bool) {
self.files.focus(focus);
Expand All @@ -85,16 +89,28 @@ impl ChangesComponent {

///
pub fn is_file_seleted(&self) -> bool {
self.files.is_file_seleted()
self.files.is_file_selected()
}

/// Returns true when there was a selection.
fn index_add_remove(&mut self) -> Result<bool> {
if let Some(tree_item) = self.selection() {
if let Some(tree_item) = self.selection_ref() {
if self.is_working_dir {
if let FileTreeItemKind::File(i) = tree_item.kind {
let path = Path::new(i.path.as_str());
match i.status {
StatusItemType::Deleted => {
if tree_item.kind().is_path() {
let config =
self.options.borrow().status_show_untracked();

//TODO: check if we can handle the one file case with it aswell
sync::stage_add_all(
&self.repo.borrow(),
tree_item.info().full_path_str(),
config,
)?;
} else {
let path =
Path::new(tree_item.info().full_path_str());
match self.selection_status().map(|s| s.status) {
Some(StatusItemType::Deleted) => {
sync::stage_addremoved(
&self.repo.borrow(),
path,
Expand All @@ -105,16 +121,6 @@ impl ChangesComponent {
path,
)?,
};
} else {
let config =
self.options.borrow().status_show_untracked();

//TODO: check if we can handle the one file case with it aswell
sync::stage_add_all(
&self.repo.borrow(),
tree_item.info.full_path.as_str(),
config,
)?;
}

//TODO: this might be slow in big repos,
Expand All @@ -130,7 +136,7 @@ impl ChangesComponent {
}
} else {
// this is a staged entry, so lets unstage it
let path = tree_item.info.full_path.as_str();
let path = tree_item.info().full_path_str();
sync::reset_stage(&self.repo.borrow(), path)?;
}

Expand Down Expand Up @@ -159,12 +165,14 @@ impl ChangesComponent {
}

fn dispatch_reset_workdir(&mut self) -> bool {
if let Some(tree_item) = self.selection() {
let is_folder =
matches!(tree_item.kind, FileTreeItemKind::Path(_));
if let Some(tree_item) = self.selection_ref() {
let is_folder = tree_item.kind().is_path();
self.queue.push(InternalEvent::ConfirmAction(
Action::Reset(ResetItem {
path: tree_item.info.full_path,
path: tree_item
.info()
.full_path_str()
.to_string(),
is_folder,
}),
));
Expand All @@ -175,15 +183,16 @@ impl ChangesComponent {
}

fn add_to_ignore(&mut self) -> bool {
if let Some(tree_item) = self.selection() {
if let Some(tree_item) = self.selection_ref() {
if let Err(e) = sync::add_to_ignore(
&self.repo.borrow(),
&tree_item.info.full_path,
tree_item.info().full_path_str(),
) {
self.queue.push(InternalEvent::ShowErrorMsg(
format!(
"ignore error:\n{}\nfile:\n{:?}",
e, tree_item.info.full_path
e,
tree_item.info().full_path()
),
));
} else {
Expand Down Expand Up @@ -218,7 +227,7 @@ impl Component for ChangesComponent {
) -> CommandBlocking {
self.files.commands(out, force_all);

let some_selection = self.selection().is_some();
let some_selection = self.selection_ref().is_some();

if self.is_working_dir {
out.push(CommandInfo::new(
Expand Down
10 changes: 7 additions & 3 deletions src/components/compare_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl CompareCommitsComponent {
if let Some(f) = self.details.files().selection_file()
{
let diff_params = DiffParams {
path: f.path.clone(),
path: f.full_path_str().to_string(),
diff_type: DiffType::Commits(ids),
options: DiffOptions::default(),
};
Expand All @@ -265,7 +265,11 @@ impl CompareCommitsComponent {
self.git_diff.last()?
{
if params == diff_params {
self.diff.update(f.path, false, last);
self.diff.update(
f.full_path_str().to_string(),
false,
last,
);
return Ok(());
}
}
Expand Down Expand Up @@ -293,7 +297,7 @@ impl CompareCommitsComponent {
}

fn can_focus_diff(&self) -> bool {
self.details.files().selection_file().is_some()
self.details.files().selection_file_ref().is_some()
}

fn hide_stacked(&mut self, stack: bool) {
Expand Down
10 changes: 7 additions & 3 deletions src/components/inspect_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl InspectCommitComponent {
if let Some(f) = self.details.files().selection_file()
{
let diff_params = DiffParams {
path: f.path.clone(),
path: f.full_path_str().to_string(),
diff_type: DiffType::Commit(
request.commit_id,
),
Expand All @@ -281,7 +281,11 @@ impl InspectCommitComponent {
self.git_diff.last()?
{
if params == diff_params {
self.diff.update(f.path, false, last);
self.diff.update(
f.full_path_str().to_string(),
false,
last,
);
return Ok(());
}
}
Expand Down Expand Up @@ -311,7 +315,7 @@ impl InspectCommitComponent {
}

fn can_focus_diff(&self) -> bool {
self.details.files().selection_file().is_some()
self.details.files().selection_file_ref().is_some()
}

fn hide_stacked(&mut self, stack: bool) {
Expand Down
1 change: 0 additions & 1 deletion src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub use syntax_text::SyntaxTextComponent;
pub use tag_commit::TagCommitComponent;
pub use taglist::TagListComponent;
pub use textinput::{InputType, TextInputComponent};
pub use utils::filetree::FileTreeItemKind;

use crate::ui::style::Theme;
use anyhow::Result;
Expand Down
Loading