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

+6-4
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

+13-9
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

+7-6
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

+1-1
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

+10-6
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

+7-5
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

+10-6
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

+4-4
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

+5-1
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

+5-1
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();

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ async fn clone() -> crate::Result {
1212
let mut dlg = CloneDelegate::default();
1313
let fixture = format!(
1414
"v1/clone{}.response",
15-
with_keepalive.then_some("-with-keepalive").unwrap_or_default()
15+
if with_keepalive {
16+
"-with-keepalive"
17+
} else {
18+
Default::default()
19+
}
1620
);
1721
crate::fetch(
1822
transport(

gix-transport/src/client/blocking_io/file.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ impl SpawnProcessOnDemand {
7878
.expect("valid url"),
7979
path,
8080
ssh_cmd: None,
81-
envs: (version != Protocol::V1)
82-
.then(|| vec![("GIT_PROTOCOL", format!("version={}", version as usize))])
83-
.unwrap_or_default(),
81+
envs: if version != Protocol::V1 {
82+
vec![("GIT_PROTOCOL", format!("version={}", version as usize))]
83+
} else {
84+
Default::default()
85+
},
8486
ssh_disallow_shell: false,
8587
child: None,
8688
connection: None,

gix/src/object/tree/entry.rs

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
use crate::object::tree::EntryRef;
2+
use crate::{bstr::BStr, ext::ObjectIdExt, object::tree::Entry};
3+
4+
/// Access
5+
impl<'repo> Entry<'repo> {
6+
/// The kind of object to which `oid` is pointing to.
7+
pub fn mode(&self) -> gix_object::tree::EntryMode {
8+
self.inner.mode
9+
}
10+
11+
/// The name of the file in the parent tree.
12+
pub fn filename(&self) -> &BStr {
13+
self.inner.filename.as_ref()
14+
}
15+
16+
/// Return the object id of the entry.
17+
pub fn id(&self) -> crate::Id<'repo> {
18+
self.inner.oid.attach(self.repo)
19+
}
20+
21+
/// Return the object this entry points to.
22+
pub fn object(&self) -> Result<crate::Object<'repo>, crate::object::find::existing::Error> {
23+
self.id().object()
24+
}
25+
26+
/// Return the plain object id of this entry, without access to the repository.
27+
pub fn oid(&self) -> &gix_hash::oid {
28+
&self.inner.oid
29+
}
30+
31+
/// Return the plain object id of this entry, without access to the repository.
32+
pub fn object_id(&self) -> gix_hash::ObjectId {
33+
self.inner.oid
34+
}
35+
}
36+
37+
/// Consuming
38+
impl Entry<'_> {
39+
/// Return the contained object.
40+
pub fn detach(self) -> gix_object::tree::Entry {
41+
self.inner
42+
}
43+
}
44+
45+
impl<'repo, 'a> EntryRef<'repo, 'a> {
46+
/// The kind of object to which [`id()`][Self::id()] is pointing.
47+
pub fn mode(&self) -> gix_object::tree::EntryMode {
48+
self.inner.mode
49+
}
50+
51+
/// The kind of object to which [`id()`][Self::id()] is pointing, as shortcut to [self.mode().kind()](Self::mode()).
52+
pub fn kind(&self) -> gix_object::tree::EntryKind {
53+
self.inner.mode.kind()
54+
}
55+
56+
/// The name of the file in the parent tree.
57+
pub fn filename(&self) -> &gix_object::bstr::BStr {
58+
self.inner.filename
59+
}
60+
61+
/// Return the entries id, connected to the underlying repository.
62+
pub fn id(&self) -> crate::Id<'repo> {
63+
crate::Id::from_id(self.inner.oid, self.repo)
64+
}
65+
66+
/// Return the plain object id of this entry, without access to the repository.
67+
pub fn oid(&self) -> &gix_hash::oid {
68+
self.inner.oid
69+
}
70+
71+
/// Return the object this entry points to.
72+
pub fn object(&self) -> Result<crate::Object<'repo>, crate::object::find::existing::Error> {
73+
self.id().object()
74+
}
75+
76+
/// Return the plain object id of this entry, without access to the repository.
77+
pub fn object_id(&self) -> gix_hash::ObjectId {
78+
self.inner.oid.to_owned()
79+
}
80+
81+
/// Detach the repository from this instance.
82+
pub fn detach(&self) -> gix_object::tree::EntryRef<'a> {
83+
self.inner
84+
}
85+
86+
/// Create an instance that doesn't bind to a buffer anymore (but that still contains a repository reference).
87+
pub fn to_owned(&self) -> Entry<'repo> {
88+
Entry {
89+
inner: self.inner.into(),
90+
repo: self.repo,
91+
}
92+
}
93+
}
94+
95+
impl std::fmt::Display for EntryRef<'_, '_> {
96+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
97+
write!(
98+
f,
99+
"{:>6o} {:>6} {}\t{}",
100+
self.mode(),
101+
self.mode().as_str(),
102+
self.id().shorten_or_id(),
103+
self.filename()
104+
)
105+
}
106+
}

0 commit comments

Comments
 (0)