Skip to content

Commit 6d3faa2

Browse files
committed
Use filetreelist crate
No longer safe Status inside of FileTreeItem. For Status storage, now introduced a new Item, which contains Status alongside FileTreeItem. Note that FileTreeItemKind is no longer publicy available - thus we cannot store this enum anywhere anymore.
1 parent ad45102 commit 6d3faa2

File tree

9 files changed

+289
-350
lines changed

9 files changed

+289
-350
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
* changes in commit message inside external editor [[@bc-universe]](https://github.com/bc-universe) ([#1420](https://github.com/extrawurst/gitui/issues/1420))
1212
* add no-verify option on commits to not run hooks [[@dam5h]](https://github.com/dam5h) ([#1374](https://github.com/extrawurst/gitui/issues/1374))
1313
* allow `fetch` on status tab [[@alensiljak]](https://github.com/alensiljak) ([#1471](https://github.com/extrawurst/gitui/issues/1471))
14+
* Use `filetreelist` crate for the status tree. [[@abergmeier]](https://github.com/abergmeier) ([#1504](https://github.com/extrawurst/gitui/issues/1504))
1415

1516
### Fixes
1617
* commit msg history ordered the wrong way ([#1445](https://github.com/extrawurst/gitui/issues/1445))

src/components/changes.rs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::{
2-
status_tree::StatusTreeComponent,
3-
utils::filetree::{FileTreeItem, FileTreeItemKind},
4-
CommandBlocking, DrawableComponent,
2+
status_tree::StatusTreeComponent, CommandBlocking,
3+
DrawableComponent,
54
};
65
use crate::{
76
components::{CommandInfo, Component, EventState},
@@ -17,6 +16,7 @@ use asyncgit::{
1716
StatusItem, StatusItemType,
1817
};
1918
use crossterm::event::Event;
19+
use filetreelist::FileTreeItem;
2020
use std::path::Path;
2121
use tui::{backend::Backend, layout::Rect, Frame};
2222

@@ -68,10 +68,14 @@ impl ChangesComponent {
6868
}
6969

7070
///
71-
pub fn selection(&self) -> Option<FileTreeItem> {
71+
pub fn selection_ref(&self) -> Option<&FileTreeItem> {
7272
self.files.selection()
7373
}
7474

75+
pub fn selection_status(&self) -> Option<StatusItem> {
76+
self.files.selection_status()
77+
}
78+
7579
///
7680
pub fn focus_select(&mut self, focus: bool) {
7781
self.files.focus(focus);
@@ -85,16 +89,28 @@ impl ChangesComponent {
8589

8690
///
8791
pub fn is_file_seleted(&self) -> bool {
88-
self.files.is_file_seleted()
92+
self.files.is_file_selected()
8993
}
9094

95+
/// Returns true when there was a selection.
9196
fn index_add_remove(&mut self) -> Result<bool> {
92-
if let Some(tree_item) = self.selection() {
97+
if let Some(tree_item) = self.selection_ref() {
9398
if self.is_working_dir {
94-
if let FileTreeItemKind::File(i) = tree_item.kind {
95-
let path = Path::new(i.path.as_str());
96-
match i.status {
97-
StatusItemType::Deleted => {
99+
if tree_item.kind().is_path() {
100+
let config =
101+
self.options.borrow().status_show_untracked();
102+
103+
//TODO: check if we can handle the one file case with it aswell
104+
sync::stage_add_all(
105+
&self.repo.borrow(),
106+
tree_item.info().full_path_str(),
107+
config,
108+
)?;
109+
} else {
110+
let path =
111+
Path::new(tree_item.info().full_path_str());
112+
match self.selection_status().map(|s| s.status) {
113+
Some(StatusItemType::Deleted) => {
98114
sync::stage_addremoved(
99115
&self.repo.borrow(),
100116
path,
@@ -105,16 +121,6 @@ impl ChangesComponent {
105121
path,
106122
)?,
107123
};
108-
} else {
109-
let config =
110-
self.options.borrow().status_show_untracked();
111-
112-
//TODO: check if we can handle the one file case with it aswell
113-
sync::stage_add_all(
114-
&self.repo.borrow(),
115-
tree_item.info.full_path.as_str(),
116-
config,
117-
)?;
118124
}
119125

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

@@ -159,12 +165,14 @@ impl ChangesComponent {
159165
}
160166

161167
fn dispatch_reset_workdir(&mut self) -> bool {
162-
if let Some(tree_item) = self.selection() {
163-
let is_folder =
164-
matches!(tree_item.kind, FileTreeItemKind::Path(_));
168+
if let Some(tree_item) = self.selection_ref() {
169+
let is_folder = tree_item.kind().is_path();
165170
self.queue.push(InternalEvent::ConfirmAction(
166171
Action::Reset(ResetItem {
167-
path: tree_item.info.full_path,
172+
path: tree_item
173+
.info()
174+
.full_path_str()
175+
.to_string(),
168176
is_folder,
169177
}),
170178
));
@@ -175,15 +183,16 @@ impl ChangesComponent {
175183
}
176184

177185
fn add_to_ignore(&mut self) -> bool {
178-
if let Some(tree_item) = self.selection() {
186+
if let Some(tree_item) = self.selection_ref() {
179187
if let Err(e) = sync::add_to_ignore(
180188
&self.repo.borrow(),
181-
&tree_item.info.full_path,
189+
tree_item.info().full_path_str(),
182190
) {
183191
self.queue.push(InternalEvent::ShowErrorMsg(
184192
format!(
185193
"ignore error:\n{}\nfile:\n{:?}",
186-
e, tree_item.info.full_path
194+
e,
195+
tree_item.info().full_path()
187196
),
188197
));
189198
} else {
@@ -218,7 +227,7 @@ impl Component for ChangesComponent {
218227
) -> CommandBlocking {
219228
self.files.commands(out, force_all);
220229

221-
let some_selection = self.selection().is_some();
230+
let some_selection = self.selection_ref().is_some();
222231

223232
if self.is_working_dir {
224233
out.push(CommandInfo::new(

src/components/compare_commits.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl CompareCommitsComponent {
256256
if let Some(f) = self.details.files().selection_file()
257257
{
258258
let diff_params = DiffParams {
259-
path: f.path.clone(),
259+
path: f.full_path_str().to_string(),
260260
diff_type: DiffType::Commits(ids),
261261
options: DiffOptions::default(),
262262
};
@@ -265,7 +265,11 @@ impl CompareCommitsComponent {
265265
self.git_diff.last()?
266266
{
267267
if params == diff_params {
268-
self.diff.update(f.path, false, last);
268+
self.diff.update(
269+
f.full_path_str().to_string(),
270+
false,
271+
last,
272+
);
269273
return Ok(());
270274
}
271275
}
@@ -293,7 +297,7 @@ impl CompareCommitsComponent {
293297
}
294298

295299
fn can_focus_diff(&self) -> bool {
296-
self.details.files().selection_file().is_some()
300+
self.details.files().selection_file_ref().is_some()
297301
}
298302

299303
fn hide_stacked(&mut self, stack: bool) {

src/components/inspect_commit.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl InspectCommitComponent {
270270
if let Some(f) = self.details.files().selection_file()
271271
{
272272
let diff_params = DiffParams {
273-
path: f.path.clone(),
273+
path: f.full_path_str().to_string(),
274274
diff_type: DiffType::Commit(
275275
request.commit_id,
276276
),
@@ -281,7 +281,11 @@ impl InspectCommitComponent {
281281
self.git_diff.last()?
282282
{
283283
if params == diff_params {
284-
self.diff.update(f.path, false, last);
284+
self.diff.update(
285+
f.full_path_str().to_string(),
286+
false,
287+
last,
288+
);
285289
return Ok(());
286290
}
287291
}
@@ -311,7 +315,7 @@ impl InspectCommitComponent {
311315
}
312316

313317
fn can_focus_diff(&self) -> bool {
314-
self.details.files().selection_file().is_some()
318+
self.details.files().selection_file_ref().is_some()
315319
}
316320

317321
fn hide_stacked(&mut self, stack: bool) {

src/components/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ pub use syntax_text::SyntaxTextComponent;
6565
pub use tag_commit::TagCommitComponent;
6666
pub use taglist::TagListComponent;
6767
pub use textinput::{InputType, TextInputComponent};
68-
pub use utils::filetree::FileTreeItemKind;
6968

7069
use crate::ui::style::Theme;
7170
use anyhow::Result;

0 commit comments

Comments
 (0)