1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
use gix_dir::walk::{CollapsedEntriesEmissionMode, EmissionMode, ForDeletionMode};
/// Options for use in the [`Repository::dirwalk()`](crate::Repository::dirwalk()) function.
///
/// Note that all values start out disabled.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub struct Options {
precompose_unicode: bool,
ignore_case: bool,
recurse_repositories: bool,
emit_pruned: bool,
emit_ignored: Option<EmissionMode>,
for_deletion: Option<ForDeletionMode>,
emit_tracked: bool,
emit_untracked: EmissionMode,
emit_empty_directories: bool,
classify_untracked_bare_repositories: bool,
emit_collapsed: Option<CollapsedEntriesEmissionMode>,
pub(crate) empty_patterns_match_prefix: bool,
}
/// Construction
impl Options {
pub(crate) fn from_fs_caps(caps: gix_fs::Capabilities) -> Self {
Self {
precompose_unicode: caps.precompose_unicode,
ignore_case: caps.ignore_case,
recurse_repositories: false,
emit_pruned: false,
emit_ignored: None,
for_deletion: None,
emit_tracked: false,
emit_untracked: Default::default(),
emit_empty_directories: false,
classify_untracked_bare_repositories: false,
emit_collapsed: None,
empty_patterns_match_prefix: false,
}
}
}
impl From<Options> for gix_dir::walk::Options {
fn from(v: Options) -> Self {
gix_dir::walk::Options {
precompose_unicode: v.precompose_unicode,
ignore_case: v.ignore_case,
recurse_repositories: v.recurse_repositories,
emit_pruned: v.emit_pruned,
emit_ignored: v.emit_ignored,
for_deletion: v.for_deletion,
emit_tracked: v.emit_tracked,
emit_untracked: v.emit_untracked,
emit_empty_directories: v.emit_empty_directories,
classify_untracked_bare_repositories: v.classify_untracked_bare_repositories,
emit_collapsed: v.emit_collapsed,
}
}
}
impl Options {
/// If `true`, default `false`, pathspecs and the directory walk itself will be setup to use the [prefix](crate::Repository::prefix)
/// if patterns are empty.
///
/// This means that the directory walk will be limited to only what's inside the [repository prefix](crate::Repository::prefix).
/// By default, the directory walk will see everything.
pub fn empty_patterns_match_prefix(mut self, toggle: bool) -> Self {
self.empty_patterns_match_prefix = toggle;
self
}
/// If `toggle` is `true`, we will stop figuring out if any directory that is a candidate for recursion is also a nested repository,
/// which saves time but leads to recurse into it. If `false`, nested repositories will not be traversed.
pub fn recurse_repositories(mut self, toggle: bool) -> Self {
self.recurse_repositories = toggle;
self
}
/// If `toggle` is `true`, entries that are pruned and whose [Kind](gix_dir::entry::Kind) is known will be emitted.
pub fn emit_pruned(mut self, toggle: bool) -> Self {
self.emit_pruned = toggle;
self
}
/// If `value` is `Some(mode)`, entries that are ignored will be emitted according to the given `mode`.
/// If `None`, ignored entries will not be emitted at all.
pub fn emit_ignored(mut self, value: Option<EmissionMode>) -> Self {
self.emit_ignored = value;
self
}
/// When the walk is for deletion, `value` must be `Some(_)` to assure we don't collapse directories that have precious files in
/// them, and otherwise assure that no entries are observable that shouldn't be deleted.
/// If `None`, precious files are treated like expendable files, which is usually what you want when displaying them
/// for addition to the repository, and the collapse of folders can be more generous in relation to ignored files.
pub fn for_deletion(mut self, value: Option<ForDeletionMode>) -> Self {
self.for_deletion = value;
self
}
/// If `toggle` is `true`, we will also emit entries for tracked items. Otherwise these will remain 'hidden',
/// even if a pathspec directly refers to it.
pub fn emit_tracked(mut self, toggle: bool) -> Self {
self.emit_tracked = toggle;
self
}
/// Controls the way untracked files are emitted. By default, this is happening immediately and without any simplification.
pub fn emit_untracked(mut self, toggle: EmissionMode) -> Self {
self.emit_untracked = toggle;
self
}
/// If `toggle` is `true`, emit empty directories as well. Note that a directory also counts as empty if it has any
/// amount or depth of nested subdirectories, as long as none of them includes a file.
/// Thus, this makes leaf-level empty directories visible, as those don't have any content.
pub fn emit_empty_directories(mut self, toggle: bool) -> Self {
self.emit_empty_directories = toggle;
self
}
/// If `toggle` is `true`, we will not only find non-bare repositories in untracked directories, but also bare ones.
///
/// Note that this is very costly, but without it, bare repositories will appear like untracked directories when collapsed,
/// and they will be recursed into.
pub fn classify_untracked_bare_repositories(mut self, toggle: bool) -> Self {
self.classify_untracked_bare_repositories = toggle;
self
}
/// Control whether entries that are in an about-to-be collapsed directory will be emitted. The default is `None`,
/// so entries in a collapsed directory are not observable.
pub fn emit_collapsed(mut self, value: Option<CollapsedEntriesEmissionMode>) -> Self {
self.emit_collapsed = value;
self
}
}