Skip to content

Commit 70109be

Browse files
committed
feat: ein find --debug to learn why it is slow
1 parent 055b117 commit 70109be

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ git-actor = { opt-level = 3 }
106106
git-config = { opt-level = 3 }
107107
miniz_oxide = { opt-level = 3 }
108108
sha-1 = { opt-level = 3 }
109-
sha1 = { opt-level = 3 }
109+
sha1_smol = { opt-level = 3 }
110110

111111
[profile.release]
112112
overflow-checks = false

gitoxide-core/src/organize.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ enum RepoKind {
2323
fn find_git_repository_workdirs<P: Progress>(
2424
root: impl AsRef<Path>,
2525
mut progress: P,
26+
debug: bool,
2627
) -> impl Iterator<Item = (PathBuf, RepoKind)>
2728
where
2829
<P as Progress>::SubProgress: Sync,
@@ -64,7 +65,10 @@ where
6465
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
6566
let walk = walk.parallelism(jwalk::Parallelism::RayonNewPool(4));
6667

67-
walk.process_read_dir(move |_depth, _path, _read_dir_state, siblings| {
68+
walk.process_read_dir(move |_depth, path, _read_dir_state, siblings| {
69+
if debug {
70+
eprintln!("{}", path.display());
71+
}
6872
let mut found_any_repo = false;
6973
let mut found_bare_repo = false;
7074
for entry in siblings.iter_mut().flatten() {
@@ -74,7 +78,7 @@ where
7478
entry.client_state = State { is_repo: true, is_bare };
7579
entry.read_children_path = None;
7680

77-
found_any_repo = !is_bare;
81+
found_any_repo = true;
7882
found_bare_repo = is_bare;
7983
}
8084
}
@@ -212,11 +216,14 @@ pub fn discover<P: Progress>(
212216
source_dir: impl AsRef<Path>,
213217
mut out: impl std::io::Write,
214218
mut progress: P,
219+
debug: bool,
215220
) -> anyhow::Result<()>
216221
where
217222
<<P as Progress>::SubProgress as Progress>::SubProgress: Sync,
218223
{
219-
for (git_workdir, _kind) in find_git_repository_workdirs(source_dir, progress.add_child("Searching repositories")) {
224+
for (git_workdir, _kind) in
225+
find_git_repository_workdirs(source_dir, progress.add_child("Searching repositories"), debug)
226+
{
220227
writeln!(&mut out, "{}", git_workdir.display())?;
221228
}
222229
Ok(())
@@ -233,7 +240,9 @@ where
233240
{
234241
let mut num_errors = 0usize;
235242
let destination = destination.as_ref().canonicalize()?;
236-
for (path_to_move, kind) in find_git_repository_workdirs(source_dir, progress.add_child("Searching repositories")) {
243+
for (path_to_move, kind) in
244+
find_git_repository_workdirs(source_dir, progress.add_child("Searching repositories"), false)
245+
{
237246
if let Err(err) = handle(mode, kind, &path_to_move, &destination, &mut progress) {
238247
progress.fail(format!(
239248
"Error when handling directory {:?}: {}",

src/porcelain/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn main() -> Result<()> {
6363
},
6464
)
6565
}
66-
crate::porcelain::options::ToolCommands::Find { root } => {
66+
crate::porcelain::options::ToolCommands::Find { root, debug } => {
6767
use gitoxide_core::organize;
6868
prepare_and_run(
6969
"find",
@@ -76,6 +76,7 @@ pub fn main() -> Result<()> {
7676
root.unwrap_or_else(|| [std::path::Component::CurDir].iter().collect()),
7777
out,
7878
git_features::progress::DoOrDiscard::from(progress),
79+
debug,
7980
)
8081
},
8182
)

src/porcelain/options.rs

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ pub enum Subcommands {
4747
pub enum ToolCommands {
4848
/// Find all repositories in a given directory.
4949
Find {
50+
/// If set, print additional information to help understand why the traversal is slow.
51+
///
52+
/// Typically it will encounter too many paths without a git repository, forcing a lot
53+
/// of additional paths to be searched unnecessarily.
54+
#[clap(long, short = 'd')]
55+
debug: bool,
5056
/// The directory in which to find all git repositories.
5157
///
5258
/// Defaults to the current working directory.

0 commit comments

Comments
 (0)