Trait gix_dir::walk::Delegate

source ·
pub trait Delegate {
    // Required method
    fn emit(
        &mut self,
        entry: EntryRef<'_>,
        collapsed_directory_status: Option<Status>
    ) -> Action;

    // Provided method
    fn can_recurse(
        &mut self,
        entry: EntryRef<'_>,
        for_deletion: Option<ForDeletionMode>,
        worktree_root_is_repository: bool
    ) -> bool { ... }
}
Expand description

A way for the caller to control the traversal based on provided data.

Required Methods§

source

fn emit( &mut self, entry: EntryRef<'_>, collapsed_directory_status: Option<Status> ) -> Action

Called for each observed entry inside a directory, or the directory itself if the traversal is configured to simplify the result (i.e. if every file in a directory is ignored, emit the containing directory instead of each file), or if the root of the traversal passes through a directory that can’t be traversed.

It will also be called if the root in walk() itself is matching a particular status, even if it is a file.

Note that tracked entries will only be emitted if Options::emit_tracked is true. Further, not all pruned entries will be observable as they might be pruned so early that the kind of item isn’t yet known. Pruned entries are also only emitted if Options::emit_pruned is true.

collapsed_directory_status is Some(dir_status) if this entry was part of a directory with the given dir_status that wasn’t the same as the one of entry and if Options::emit_collapsed was CollapsedEntriesEmissionMode::OnStatusMismatch. It will also be Some(dir_status) if that option was CollapsedEntriesEmissionMode::All.

Provided Methods§

source

fn can_recurse( &mut self, entry: EntryRef<'_>, for_deletion: Option<ForDeletionMode>, worktree_root_is_repository: bool ) -> bool

Return true if the given entry can be recursed into. Will only be called if the entry is a physical directory. The base implementation will act like Git does by default in git status or git clean.

Use for_deletion to specify if the seen entries should ultimately be deleted, which may affect the decision of whether to resource or not.

If worktree_root_is_repository is true, then this status is part of the root of an iteration, and the corresponding worktree root is a repository itself. This typically happens for submodules. In this case, recursion rules are relaxed to allow traversing submodule worktrees.

Note that this method will see all directories, even though not all of them may end up being emitted. If this method returns false, the entry will always be emitted.

Implementors§