Skip to content

Commit 28935a5

Browse files
authored
Merge pull request #1975 from GitoxideLabs/improvements
various improvements
2 parents dc3c7c9 + dbf65c9 commit 28935a5

File tree

16 files changed

+210
-166
lines changed

16 files changed

+210
-166
lines changed

gitoxide-core/src/hours/core.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub fn estimate_hours(
4444
};
4545

4646
let author = &commits[0].1;
47-
let (files, lines) = (!stats.is_empty())
48-
.then(|| {
47+
let (files, lines) = if !stats.is_empty() {
48+
{
4949
commits
5050
.iter()
5151
.map(|t| &t.0)
@@ -60,8 +60,10 @@ pub fn estimate_hours(
6060
}
6161
Err(_) => acc,
6262
})
63-
})
64-
.unwrap_or_default();
63+
}
64+
} else {
65+
Default::default()
66+
};
6567
WorkByEmail {
6668
name: author.name,
6769
email: author.email,

gitoxide-core/src/hours/mod.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ where
113113
Ok(out)
114114
});
115115

116-
let (stats_progresses, stats_counters) = needs_stats
117-
.then(|| {
116+
let (stats_progresses, stats_counters) = if needs_stats {
117+
{
118118
let mut sp = progress.add_child("extract stats");
119119
sp.init(None, progress::count("commits"));
120120
let sc = sp.counter();
@@ -128,14 +128,16 @@ where
128128
let lc = lp.counter();
129129

130130
(Some((sp, cp, lp)), Some((sc, cc, lc)))
131-
})
132-
.unwrap_or_default();
131+
}
132+
} else {
133+
Default::default()
134+
};
133135

134136
let mut progress = progress.add_child("traverse commit graph");
135137
progress.init(None, progress::count("commits"));
136138

137-
let (tx_tree_id, stat_threads) = needs_stats
138-
.then(|| {
139+
let (tx_tree_id, stat_threads) = if needs_stats {
140+
{
139141
let (tx, threads) = spawn_tree_delta_threads(
140142
scope,
141143
threads,
@@ -144,8 +146,10 @@ where
144146
stats_counters.clone().expect("counters are set"),
145147
);
146148
(Some(tx), threads)
147-
})
148-
.unwrap_or_default();
149+
}
150+
} else {
151+
Default::default()
152+
};
149153

150154
let mut commit_idx = 0_u32;
151155
let mut skipped_merge_commits = 0;
@@ -296,7 +300,7 @@ where
296300
total_hours,
297301
total_hours / HOURS_PER_WORKDAY,
298302
total_commits,
299-
is_shallow.then_some(" (shallow)").unwrap_or_default(),
303+
if is_shallow { " (shallow)" } else { Default::default() },
300304
num_authors
301305
)?;
302306
if file_stats {

gitoxide-core/src/index/checkout.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,18 @@ pub fn checkout_exclusive(
115115
progress.done(format!(
116116
"Created {} {} files{} ({})",
117117
files_updated,
118-
no_repo.then_some("empty").unwrap_or_default(),
119-
should_interrupt
120-
.load(Ordering::Relaxed)
121-
.then(|| {
118+
if no_repo { "empty" } else { Default::default() },
119+
if should_interrupt.load(Ordering::Relaxed) {
120+
{
122121
format!(
123122
" of {}",
124123
entries_for_checkout
125124
.saturating_sub(errors.len() + collisions.len() + delayed_paths_unprocessed.len())
126125
)
127-
})
128-
.unwrap_or_default(),
126+
}
127+
} else {
128+
Default::default()
129+
},
129130
gix::progress::bytes()
130131
.unwrap()
131132
.display(bytes_written as usize, None, None)

gitoxide-core/src/repository/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub(crate) mod function {
237237
out,
238238
"{maybe}{suffix} {}{} {status}",
239239
display_path.display(),
240-
disk_kind.is_dir().then_some("/").unwrap_or_default(),
240+
if disk_kind.is_dir() { "/" } else { Default::default() },
241241
status = match entry.status {
242242
Status::Ignored(kind) => {
243243
Cow::Owned(format!(

gitoxide-core/src/repository/config.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,15 @@ fn write_meta(meta: &gix::config::file::Metadata, out: &mut impl std::io::Write)
9494
.as_deref()
9595
.map_or_else(|| "memory".into(), |p| p.display().to_string()),
9696
meta.source,
97-
(meta.level != 0)
98-
.then(|| format!(", include level {}", meta.level))
99-
.unwrap_or_default(),
100-
(meta.trust != gix::sec::Trust::Full)
101-
.then_some(", untrusted")
102-
.unwrap_or_default()
97+
if meta.level != 0 {
98+
format!(", include level {}", meta.level)
99+
} else {
100+
Default::default()
101+
},
102+
if meta.trust != gix::sec::Trust::Full {
103+
", untrusted"
104+
} else {
105+
Default::default()
106+
}
103107
)
104108
}

gix-diff/tests/diff/blob/platform.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn resources_of_worktree_and_odb_and_check_link() -> crate::Result {
7070
2,
7171
3
7272
)),
73-
format!("{}test a <tmp-path> 0000000000000000000000000000000000000000 100644 <tmp-path> 4c469b6c8c4486fdc9ded9d597d8f6816a455707 100755", (!cfg!(windows)).then_some("GIT_DIFF_PATH_COUNTER=3 GIT_DIFF_PATH_TOTAL=3 GIT_DIR=. ").unwrap_or_default()),
73+
format!("{}test a <tmp-path> 0000000000000000000000000000000000000000 100644 <tmp-path> 4c469b6c8c4486fdc9ded9d597d8f6816a455707 100755", if !cfg!(windows) { "GIT_DIFF_PATH_COUNTER=3 GIT_DIFF_PATH_TOTAL=3 GIT_DIR=. " } else { Default::default() }),
7474
"in this case, there is no rename-to field as last argument, it's based on the resource paths being different"
7575
);
7676

@@ -117,7 +117,7 @@ fn resources_of_worktree_and_odb_and_check_link() -> crate::Result {
117117
0,
118118
1
119119
)),
120-
format!("{}test a <tmp-path> 0000000000000000000000000000000000000000 100644 <tmp-path> 4c469b6c8c4486fdc9ded9d597d8f6816a455707 120000", (!cfg!(windows)).then_some(r#"GIT_DIFF_PATH_COUNTER=1 GIT_DIFF_PATH_TOTAL=1 GIT_DIR=. "#).unwrap_or_default()),
120+
format!("{}test a <tmp-path> 0000000000000000000000000000000000000000 100644 <tmp-path> 4c469b6c8c4486fdc9ded9d597d8f6816a455707 120000", if !cfg!(windows) { r#"GIT_DIFF_PATH_COUNTER=1 GIT_DIFF_PATH_TOTAL=1 GIT_DIR=. "# } else { Default::default() }),
121121
"Also obvious that symlinks are definitely special, but it's what git does as well"
122122
);
123123

@@ -340,9 +340,11 @@ fn source_and_destination_do_not_exist() -> crate::Result {
340340
),
341341
format!(
342342
r#"{}"test" "missing" "/dev/null" "." "." "/dev/null" "." "." "a""#,
343-
(!cfg!(windows))
344-
.then_some(r#"GIT_DIFF_PATH_COUNTER="1" GIT_DIFF_PATH_TOTAL="1" GIT_DIR="." "#)
345-
.unwrap_or_default()
343+
if !cfg!(windows) {
344+
r#"GIT_DIFF_PATH_COUNTER="1" GIT_DIFF_PATH_TOTAL="1" GIT_DIR="." "#
345+
} else {
346+
Default::default()
347+
}
346348
)
347349
);
348350
Ok(())

gix-odb/src/store_impls/dynamic/load_index.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ impl super::Store {
251251
.collect();
252252

253253
let mut new_slot_map_indices = Vec::new(); // these indices into the slot map still exist there/didn't change
254-
let mut index_paths_to_add = was_uninitialized
255-
.then(|| VecDeque::with_capacity(indices_by_modification_time.len()))
256-
.unwrap_or_default();
254+
let mut index_paths_to_add = if was_uninitialized {
255+
VecDeque::with_capacity(indices_by_modification_time.len())
256+
} else {
257+
Default::default()
258+
};
257259

258260
// Figure out this number based on what we see while handling the existing indices
259261
let mut num_loaded_indices = 0;
@@ -389,9 +391,11 @@ impl super::Store {
389391
generation,
390392
// if there was a prior generation, some indices might already be loaded. But we deal with it by trying to load the next index then,
391393
// until we find one.
392-
next_index_to_load: index_unchanged
393-
.then(|| Arc::clone(&index.next_index_to_load))
394-
.unwrap_or_default(),
394+
next_index_to_load: if index_unchanged {
395+
Arc::clone(&index.next_index_to_load)
396+
} else {
397+
Default::default()
398+
},
395399
loaded_indices: if index_unchanged {
396400
Arc::clone(&index.loaded_indices)
397401
} else {

gix-path/src/env/auxiliary.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ mod tests {
141141
];
142142

143143
#[test]
144-
#[cfg_attr(not(windows), ignore)]
144+
#[cfg_attr(not(windows), ignore = "only meaningful on Windows")]
145145
fn find_git_associated_windows_executable() {
146146
for stem in SHOULD_FIND {
147147
let path = super::find_git_associated_windows_executable(stem);
@@ -150,7 +150,7 @@ mod tests {
150150
}
151151

152152
#[test]
153-
#[cfg_attr(not(windows), ignore)]
153+
#[cfg_attr(not(windows), ignore = "only meaningful on Windows")]
154154
fn find_git_associated_windows_executable_no_extra() {
155155
for stem in SHOULD_NOT_FIND {
156156
let path = super::find_git_associated_windows_executable(stem);
@@ -159,7 +159,7 @@ mod tests {
159159
}
160160

161161
#[test]
162-
#[cfg_attr(not(windows), ignore)]
162+
#[cfg_attr(not(windows), ignore = "only meaningful on Windows")]
163163
fn find_git_associated_windows_executable_with_fallback() {
164164
for stem in SHOULD_FIND {
165165
let path = super::find_git_associated_windows_executable_with_fallback(stem);
@@ -168,7 +168,7 @@ mod tests {
168168
}
169169

170170
#[test]
171-
#[cfg_attr(not(windows), ignore)]
171+
#[cfg_attr(not(windows), ignore = "only meaningful on Windows")]
172172
fn find_git_associated_windows_executable_with_fallback_falls_back() {
173173
for stem in SHOULD_NOT_FIND {
174174
let path = super::find_git_associated_windows_executable_with_fallback(stem)

gix-pathspec/src/pattern.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ impl Pattern {
5454
_ => 0,
5555
})
5656
.sum::<isize>();
57-
(count > 0).then_some(count as usize).unwrap_or_default()
57+
if count > 0 {
58+
count as usize
59+
} else {
60+
Default::default()
61+
}
5862
}
5963

6064
let mut path = gix_path::from_bstr(self.path.as_bstr());

gix-protocol/tests/protocol/fetch/response.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ mod v2 {
220220
for keepalive in [false, true] {
221221
let fixture = format!(
222222
"v2/clone-only{}.response",
223-
keepalive.then_some("-with-keepalive").unwrap_or_default()
223+
if keepalive {
224+
"-with-keepalive"
225+
} else {
226+
Default::default()
227+
}
224228
);
225229
let mut provider = mock_reader(&fixture);
226230
let mut reader = provider.as_read_without_sidebands();

0 commit comments

Comments
 (0)