Skip to content

Commit

Permalink
feat: ein find --debug to learn why it is slow
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Mar 10, 2022
1 parent 055b117 commit 70109be
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ git-actor = { opt-level = 3 }
git-config = { opt-level = 3 }
miniz_oxide = { opt-level = 3 }
sha-1 = { opt-level = 3 }
sha1 = { opt-level = 3 }
sha1_smol = { opt-level = 3 }

[profile.release]
overflow-checks = false
Expand Down
17 changes: 13 additions & 4 deletions gitoxide-core/src/organize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum RepoKind {
fn find_git_repository_workdirs<P: Progress>(
root: impl AsRef<Path>,
mut progress: P,
debug: bool,
) -> impl Iterator<Item = (PathBuf, RepoKind)>
where
<P as Progress>::SubProgress: Sync,
Expand Down Expand Up @@ -64,7 +65,10 @@ where
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
let walk = walk.parallelism(jwalk::Parallelism::RayonNewPool(4));

walk.process_read_dir(move |_depth, _path, _read_dir_state, siblings| {
walk.process_read_dir(move |_depth, path, _read_dir_state, siblings| {
if debug {
eprintln!("{}", path.display());
}
let mut found_any_repo = false;
let mut found_bare_repo = false;
for entry in siblings.iter_mut().flatten() {
Expand All @@ -74,7 +78,7 @@ where
entry.client_state = State { is_repo: true, is_bare };
entry.read_children_path = None;

found_any_repo = !is_bare;
found_any_repo = true;
found_bare_repo = is_bare;
}
}
Expand Down Expand Up @@ -212,11 +216,14 @@ pub fn discover<P: Progress>(
source_dir: impl AsRef<Path>,
mut out: impl std::io::Write,
mut progress: P,
debug: bool,
) -> anyhow::Result<()>
where
<<P as Progress>::SubProgress as Progress>::SubProgress: Sync,
{
for (git_workdir, _kind) in find_git_repository_workdirs(source_dir, progress.add_child("Searching repositories")) {
for (git_workdir, _kind) in
find_git_repository_workdirs(source_dir, progress.add_child("Searching repositories"), debug)
{
writeln!(&mut out, "{}", git_workdir.display())?;
}
Ok(())
Expand All @@ -233,7 +240,9 @@ where
{
let mut num_errors = 0usize;
let destination = destination.as_ref().canonicalize()?;
for (path_to_move, kind) in find_git_repository_workdirs(source_dir, progress.add_child("Searching repositories")) {
for (path_to_move, kind) in
find_git_repository_workdirs(source_dir, progress.add_child("Searching repositories"), false)
{
if let Err(err) = handle(mode, kind, &path_to_move, &destination, &mut progress) {
progress.fail(format!(
"Error when handling directory {:?}: {}",
Expand Down
3 changes: 2 additions & 1 deletion src/porcelain/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn main() -> Result<()> {
},
)
}
crate::porcelain::options::ToolCommands::Find { root } => {
crate::porcelain::options::ToolCommands::Find { root, debug } => {
use gitoxide_core::organize;
prepare_and_run(
"find",
Expand All @@ -76,6 +76,7 @@ pub fn main() -> Result<()> {
root.unwrap_or_else(|| [std::path::Component::CurDir].iter().collect()),
out,
git_features::progress::DoOrDiscard::from(progress),
debug,
)
},
)
Expand Down
6 changes: 6 additions & 0 deletions src/porcelain/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ pub enum Subcommands {
pub enum ToolCommands {
/// Find all repositories in a given directory.
Find {
/// If set, print additional information to help understand why the traversal is slow.
///
/// Typically it will encounter too many paths without a git repository, forcing a lot
/// of additional paths to be searched unnecessarily.
#[clap(long, short = 'd')]
debug: bool,
/// The directory in which to find all git repositories.
///
/// Defaults to the current working directory.
Expand Down

0 comments on commit 70109be

Please sign in to comment.