Skip to content

Commit c60ea36

Browse files
committed
Allow --git --tree, too
This works by checking if any of the (immediate) files being listed are under Git, and hiding the column if all aren’t.
1 parent 9cda05d commit c60ea36

File tree

8 files changed

+60
-36
lines changed

8 files changed

+60
-36
lines changed

src/fs/feature/git.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ fn repo_to_statuses(repo: git2::Repository, workdir: &Path) -> Git {
212212
Git { statuses }
213213
}
214214

215+
// The `repo.statuses` call above takes a long time. exa debug output:
216+
//
217+
// 20.311276 INFO:exa::fs::feature::git: Getting Git statuses for repo with workdir "/vagrant/"
218+
// 20.799610 DEBUG:exa::output::table: Getting Git status for file "./Cargo.toml"
219+
//
220+
// Even inserting another logging line immediately afterwards doesn't make it
221+
// look any faster.
222+
215223

216224
/// Container of Git statuses for all the files in this folder’s Git repository.
217225
struct Git {

src/output/details.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ impl<'a> Render<'a> {
144144
let mut rows = Vec::new();
145145

146146
if let Some(ref table) = self.opts.table {
147-
if self.dir.is_none() { git = None }
148-
if let (Some(g), Some(d)) = (git, self.dir) { if !g.has_anything_for(&d.path) { git = None } }
147+
match (git, self.dir) {
148+
(Some(g), Some(d)) => if !g.has_anything_for(&d.path) { git = None },
149+
(Some(g), None) => if !self.files.iter().any(|f| g.has_anything_for(&f.path)) { git = None },
150+
(None, _) => {/* Keep Git how it is */},
151+
}
152+
149153
let mut table = Table::new(&table, git, &self.colours);
150154

151155
if self.opts.header {
@@ -154,7 +158,7 @@ impl<'a> Render<'a> {
154158
rows.push(self.render_header(header));
155159
}
156160

157-
// This is weird, but I can't find a way around it:
161+
// This is weird, but I cant find a way around it:
158162
// https://internals.rust-lang.org/t/should-option-mut-t-implement-copy/3715/6
159163
let mut table = Some(table);
160164
self.add_files_to_table(&mut table, &mut rows, &self.files, TreeDepth::root());

src/output/grid_details.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,12 @@ impl<'a> Render<'a> {
168168
}
169169

170170
fn make_table<'t>(&'a self, options: &'a TableOptions, mut git: Option<&'a GitCache>, drender: &DetailsRender) -> (Table<'a>, Vec<DetailsRow>) {
171-
if self.dir.is_none() { git = None }
172-
if let (Some(g), Some(d)) = (git, self.dir) { if !g.has_anything_for(&d.path) { git = None } }
171+
match (git, self.dir) {
172+
(Some(g), Some(d)) => if !g.has_anything_for(&d.path) { git = None },
173+
(Some(g), None) => if !self.files.iter().any(|f| g.has_anything_for(&f.path)) { git = None },
174+
(None, _) => {/* Keep Git how it is */},
175+
}
176+
173177
let mut table = Table::new(options, git, self.colours);
174178
let mut rows = Vec::new();
175179

xtests/git_1_file

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.rw-rw-r-- 21 cassowary  1 Jan 12:34 N- /testcases/git/moves/thither

xtests/git_1_files

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.rw-rw-r-- 20 cassowary  1 Jan 12:34 NM /testcases/git/additions/edited .rw-rw-r-- 15 cassowary  1 Jan 12:34 M- /testcases/git/edits/staged
2+
.rw-rw-r-- 0 cassowary  1 Jan 12:34 N- /testcases/git/additions/staged .rw-rw-r-- 20 cassowary  1 Jan 12:34 -M /testcases/git/edits/unstaged
3+
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -N /testcases/git/additions/unstaged .rw-rw-r-- 21 cassowary  1 Jan 12:34 N- /testcases/git/moves/thither
4+
.rw-rw-r-- 20 cassowary  1 Jan 12:34 MM /testcases/git/edits/both drwxr-xr-x - cassowary  1 Jan 12:34 -- /testcases

xtests/git_1_tree

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
drwxrwxr-x - cassowary  1 Jan 12:34 /testcases/git
2-
drwxrwxr-x - cassowary  1 Jan 12:34 ├── additions
3-
.rw-rw-r-- 20 cassowary  1 Jan 12:34 │ ├── edited
4-
.rw-rw-r-- 0 cassowary  1 Jan 12:34 │ ├── staged
5-
.rw-rw-r-- 0 cassowary  1 Jan 12:34 │ └── unstaged
6-
drwxrwxr-x - cassowary  1 Jan 12:34 ├── edits
7-
.rw-rw-r-- 20 cassowary  1 Jan 12:34 │ ├── both
8-
.rw-rw-r-- 15 cassowary  1 Jan 12:34 │ ├── staged
9-
.rw-rw-r-- 20 cassowary  1 Jan 12:34 │ └── unstaged
10-
drwxrwxr-x - cassowary  1 Jan 12:34 └── moves
11-
.rw-rw-r-- 21 cassowary  1 Jan 12:34  └── thither
1+
drwxrwxr-x - cassowary  1 Jan 12:34 NN /testcases/git
2+
drwxrwxr-x - cassowary  1 Jan 12:34 NN ├── additions
3+
.rw-rw-r-- 20 cassowary  1 Jan 12:34 NM │ ├── edited
4+
.rw-rw-r-- 0 cassowary  1 Jan 12:34 N- │ ├── staged
5+
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -N │ └── unstaged
6+
drwxrwxr-x - cassowary  1 Jan 12:34 MM ├── edits
7+
.rw-rw-r-- 20 cassowary  1 Jan 12:34 MM │ ├── both
8+
.rw-rw-r-- 15 cassowary  1 Jan 12:34 M- │ ├── staged
9+
.rw-rw-r-- 20 cassowary  1 Jan 12:34 -M │ └── unstaged
10+
drwxrwxr-x - cassowary  1 Jan 12:34 N- └── moves
11+
.rw-rw-r-- 21 cassowary  1 Jan 12:34 N-  └── thither

xtests/git_2_tree

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
drwxrwxr-x - cassowary  1 Jan 12:34 /testcases/git2
2-
drwxrwxr-x - cassowary  1 Jan 12:34 ├── deeply
3-
drwxrwxr-x - cassowary  1 Jan 12:34 │ └── nested
4-
drwxrwxr-x - cassowary  1 Jan 12:34 │ ├── directory
5-
.rw-rw-r-- 0 cassowary  1 Jan 12:34 │ │ ├── l8st
6-
.rw-rw-r-- 18 cassowary  1 Jan 12:34 │ │ └── upd8d
7-
drwxrwxr-x - cassowary  1 Jan 12:34 │ └── repository
8-
.rw-rw-r-- 0 cassowary  1 Jan 12:34 │ └── subfile
9-
drwxrwxr-x - cassowary  1 Jan 12:34 ├── ignoreds
10-
.rw-rw-r-- 0 cassowary  1 Jan 12:34 │ ├── music.m4a
11-
.rw-rw-r-- 0 cassowary  1 Jan 12:34 │ └── music.mp3
12-
drwxrwxr-x - cassowary  1 Jan 12:34 └── target
13-
.rw-rw-r-- 0 cassowary  1 Jan 12:34  └── another ignored file
1+
drwxrwxr-x - cassowary  1 Jan 12:34 -N /testcases/git2
2+
drwxrwxr-x - cassowary  1 Jan 12:34 -N ├── deeply
3+
drwxrwxr-x - cassowary  1 Jan 12:34 -N │ └── nested
4+
drwxrwxr-x - cassowary  1 Jan 12:34 -N │ ├── directory
5+
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -N │ │ ├── l8st
6+
.rw-rw-r-- 18 cassowary  1 Jan 12:34 -M │ │ └── upd8d
7+
drwxrwxr-x - cassowary  1 Jan 12:34 -N │ └── repository
8+
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -- │ └── subfile
9+
drwxrwxr-x - cassowary  1 Jan 12:34 -N ├── ignoreds
10+
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -N │ ├── music.m4a
11+
.rw-rw-r-- 0 cassowary  1 Jan 12:34 -- │ └── music.mp3
12+
drwxrwxr-x - cassowary  1 Jan 12:34 -- └── target
13+
.rw-rw-r-- 0 cassowary  1 Jan 12:34 --  └── another ignored file

xtests/run.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,14 @@ COLUMNS=80 $exa_binary --colour=never $testcases/file-names-exts | diff -q -
188188

189189

190190
# Git
191-
$exa $testcases/git -l --git 2>&1 | diff -q - $results/git_1_long || exit 1
192-
$exa $testcases/git -l 2>&1 | diff -q - $results/git_1_nogit || exit 1
193-
$exa $testcases/git --tree -l --git 2>&1 | diff -q - $results/git_1_tree || exit 1
194-
$exa $testcases/git --recurse -l --git 2>&1 | diff -q - $results/git_1_recurse || exit 1
195-
$exa $testcases/git/additions -l --git 2>&1 | diff -q - $results/git_1_additions || exit 1
196-
$exa $testcases/git/edits -l --git 2>&1 | diff -q - $results/git_1_edits || exit 1
197-
$exa $testcases/git/{additions,edits} -l --git 2>&1 | diff -q - $results/git_1_both || exit 1
191+
$exa $testcases/git -l --git 2>&1 | diff -q - $results/git_1_long || exit 1
192+
$exa $testcases/git -l 2>&1 | diff -q - $results/git_1_nogit || exit 1
193+
$exa $testcases/git --recurse -l --git 2>&1 | diff -q - $results/git_1_recurse || exit 1
194+
$exa $testcases/git --tree -l --git 2>&1 | diff -q - $results/git_1_tree || exit 1
195+
$exa $testcases/git/moves/thither --tree -l --git 2>&1 | diff -q - $results/git_1_file || exit 1
196+
$exa $testcases/git/additions -l --git 2>&1 | diff -q - $results/git_1_additions || exit 1
197+
$exa $testcases/git/edits -l --git 2>&1 | diff -q - $results/git_1_edits || exit 1
198+
$exa $testcases/git/{additions,edits} -l --git 2>&1 | diff -q - $results/git_1_both || exit 1
198199

199200
$exa $testcases/git2 -l --git 2>&1 | diff -q - $results/git_2_long || exit 1
200201
$exa $testcases/git2 -l 2>&1 | diff -q - $results/git_2_nogit || exit 1
@@ -205,6 +206,8 @@ $exa $testcases/git2/target -l --git 2>&1 | diff -q - $results
205206
$exa $testcases/git2/deeply/nested/repository -l --git 2>&1 | diff -q - $results/git_2_repository || exit 1
206207
$exa $testcases/git2/{deeply,ignoreds,target} -l --git 2>&1 | diff -q - $results/git_2_all || exit 1
207208

209+
COLUMNS=150 $exa $testcases/git/**/* $testcases --git --long --grid -d | diff -q - $results/git_1_files || exit 1
210+
208211
$exa $testcases/git $testcases/git2 --git --long | diff -q - $results/git_12 || exit 1
209212

210213
$exa $testcases/git/additions $testcases/git2/deeply \

0 commit comments

Comments
 (0)