Skip to content

Commit 0af2fe6

Browse files
committed
improve gix clean reporting
1 parent 482d6f3 commit 0af2fe6

File tree

2 files changed

+44
-46
lines changed

2 files changed

+44
-46
lines changed

gitoxide-core/src/repository/clean.rs

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -103,44 +103,24 @@ pub(crate) mod function {
103103
continue;
104104
}
105105

106-
pruned_entries += usize::from(entry.pathspec_match.is_none());
107-
if entry.status.is_pruned() || entry.pathspec_match.is_none() {
108-
continue;
109-
}
110-
let mut disk_kind = entry.disk_kind.expect("present if not pruned");
111-
match disk_kind {
112-
Kind::File | Kind::Symlink => {}
113-
Kind::EmptyDirectory | Kind::Directory | Kind::Repository => {
114-
let keep = directories
115-
|| entry
116-
.pathspec_match
117-
.map_or(false, |m| m != gix::dir::entry::PathspecMatch::Always);
118-
if !keep {
119-
skipped_directories += 1;
120-
if debug {
121-
writeln!(err, "DBG: prune '{}' as -d is missing", entry.rela_path).ok();
122-
}
123-
continue;
124-
}
125-
}
126-
};
127-
128-
let keep = entry
106+
let pathspec_includes_entry = entry
129107
.pathspec_match
130-
.map_or(true, |m| m != gix::dir::entry::PathspecMatch::Excluded);
131-
if !keep {
132-
if debug {
133-
writeln!(err, "DBG: prune '{}' as it is excluded by pathspec", entry.rela_path).ok();
134-
}
108+
.map_or(false, |m| m != gix::dir::entry::PathspecMatch::Excluded);
109+
pruned_entries += usize::from(!pathspec_includes_entry);
110+
if !pathspec_includes_entry && debug {
111+
writeln!(err, "DBG: prune '{}' as it is excluded by pathspec", entry.rela_path).ok();
112+
}
113+
if entry.status.is_pruned() || !pathspec_includes_entry {
135114
continue;
136115
}
137116

117+
let mut disk_kind = entry.disk_kind.expect("present if not pruned");
138118
let keep = match entry.status {
139119
Status::DotGit | Status::Pruned | Status::TrackedExcluded => {
140-
unreachable!("Pruned aren't emitted")
120+
unreachable!("BUG: Pruned are skipped already as their pathspec is always None")
141121
}
142122
Status::Tracked => {
143-
unreachable!("tracked aren't emitted")
123+
unreachable!("BUG: tracked aren't emitted")
144124
}
145125
Status::Ignored(gix::ignore::Kind::Expendable) => {
146126
skipped_ignored += usize::from(!ignored);
@@ -168,18 +148,30 @@ pub(crate) mod function {
168148
disk_kind = gix::dir::entry::Kind::Repository;
169149
}
170150

171-
let is_ignored = matches!(entry.status, gix::dir::entry::Status::Ignored(_));
172-
let display_path = entry.rela_path[prefix_len..].as_bstr();
173-
if (!repositories || is_ignored) && disk_kind == gix::dir::entry::Kind::Repository {
174-
if !is_ignored {
175-
skipped_repositories += 1;
151+
match disk_kind {
152+
Kind::File | Kind::Symlink => {}
153+
Kind::EmptyDirectory | Kind::Directory => {
154+
if !directories {
155+
skipped_directories += 1;
156+
if debug {
157+
writeln!(err, "DBG: prune '{}' as -d is missing", entry.rela_path).ok();
158+
}
159+
continue;
160+
}
176161
}
177-
if debug {
178-
writeln!(err, "DBG: skipped repository at '{display_path}'")?;
162+
Kind::Repository => {
163+
if !repositories {
164+
skipped_repositories += 1;
165+
if debug {
166+
writeln!(err, "DBG: skipped repository at '{}'", entry.rela_path)?;
167+
}
168+
continue;
169+
}
179170
}
180-
continue;
181-
}
171+
};
182172

173+
let is_ignored = matches!(entry.status, gix::dir::entry::Status::Ignored(_));
174+
let display_path = entry.rela_path[prefix_len..].as_bstr();
183175
if disk_kind == gix::dir::entry::Kind::Directory {
184176
saw_ignored_directory |= is_ignored;
185177
saw_untracked_directory |= entry.status == gix::dir::entry::Status::Untracked;
@@ -194,8 +186,8 @@ pub(crate) mod function {
194186
Cow::Owned(format!(
195187
"({})",
196188
match kind {
197-
gix::ignore::Kind::Precious => "$",
198-
gix::ignore::Kind::Expendable => "",
189+
gix::ignore::Kind::Precious => "💲",
190+
gix::ignore::Kind::Expendable => "🗑️",
199191
}
200192
))
201193
}
@@ -210,10 +202,16 @@ pub(crate) mod function {
210202
},
211203
},
212204
maybe = if execute { "removing" } else { "WOULD remove" },
213-
suffix = if disk_kind == gix::dir::entry::Kind::Repository {
214-
" repository"
215-
} else {
216-
""
205+
suffix = match disk_kind {
206+
Kind::File | Kind::Symlink | Kind::Directory => {
207+
""
208+
}
209+
Kind::EmptyDirectory => {
210+
" empty"
211+
}
212+
Kind::Repository => {
213+
" repository"
214+
}
217215
},
218216
)?;
219217

gitoxide-core/src/repository/index/entries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ pub(crate) mod function {
419419
buf.push_str(" ➡ ");
420420
}
421421
if a.is_excluded {
422-
buf.push_str(" ");
422+
buf.push_str(" 🗑️");
423423
}
424424
if !a.attributes.is_empty() {
425425
buf.push_str(" (");

0 commit comments

Comments
 (0)