Skip to content

various improvements #1975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions gitoxide-core/src/hours/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ pub fn estimate_hours(
};

let author = &commits[0].1;
let (files, lines) = (!stats.is_empty())
.then(|| {
let (files, lines) = if !stats.is_empty() {
{
commits
.iter()
.map(|t| &t.0)
Expand All @@ -60,8 +60,10 @@ pub fn estimate_hours(
}
Err(_) => acc,
})
})
.unwrap_or_default();
}
} else {
Default::default()
};
WorkByEmail {
name: author.name,
email: author.email,
Expand Down
22 changes: 13 additions & 9 deletions gitoxide-core/src/hours/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ where
Ok(out)
});

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

(Some((sp, cp, lp)), Some((sc, cc, lc)))
})
.unwrap_or_default();
}
} else {
Default::default()
};

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

let (tx_tree_id, stat_threads) = needs_stats
.then(|| {
let (tx_tree_id, stat_threads) = if needs_stats {
{
let (tx, threads) = spawn_tree_delta_threads(
scope,
threads,
Expand All @@ -144,8 +146,10 @@ where
stats_counters.clone().expect("counters are set"),
);
(Some(tx), threads)
})
.unwrap_or_default();
}
} else {
Default::default()
};

let mut commit_idx = 0_u32;
let mut skipped_merge_commits = 0;
Expand Down Expand Up @@ -296,7 +300,7 @@ where
total_hours,
total_hours / HOURS_PER_WORKDAY,
total_commits,
is_shallow.then_some(" (shallow)").unwrap_or_default(),
if is_shallow { " (shallow)" } else { Default::default() },
num_authors
)?;
if file_stats {
Expand Down
13 changes: 7 additions & 6 deletions gitoxide-core/src/index/checkout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,18 @@ pub fn checkout_exclusive(
progress.done(format!(
"Created {} {} files{} ({})",
files_updated,
no_repo.then_some("empty").unwrap_or_default(),
should_interrupt
.load(Ordering::Relaxed)
.then(|| {
if no_repo { "empty" } else { Default::default() },
if should_interrupt.load(Ordering::Relaxed) {
{
format!(
" of {}",
entries_for_checkout
.saturating_sub(errors.len() + collisions.len() + delayed_paths_unprocessed.len())
)
})
.unwrap_or_default(),
}
} else {
Default::default()
},
gix::progress::bytes()
.unwrap()
.display(bytes_written as usize, None, None)
Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/src/repository/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ pub(crate) mod function {
out,
"{maybe}{suffix} {}{} {status}",
display_path.display(),
disk_kind.is_dir().then_some("/").unwrap_or_default(),
if disk_kind.is_dir() { "/" } else { Default::default() },
status = match entry.status {
Status::Ignored(kind) => {
Cow::Owned(format!(
Expand Down
16 changes: 10 additions & 6 deletions gitoxide-core/src/repository/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ fn write_meta(meta: &gix::config::file::Metadata, out: &mut impl std::io::Write)
.as_deref()
.map_or_else(|| "memory".into(), |p| p.display().to_string()),
meta.source,
(meta.level != 0)
.then(|| format!(", include level {}", meta.level))
.unwrap_or_default(),
(meta.trust != gix::sec::Trust::Full)
.then_some(", untrusted")
.unwrap_or_default()
if meta.level != 0 {
format!(", include level {}", meta.level)
} else {
Default::default()
},
if meta.trust != gix::sec::Trust::Full {
", untrusted"
} else {
Default::default()
}
)
}
12 changes: 7 additions & 5 deletions gix-diff/tests/diff/blob/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn resources_of_worktree_and_odb_and_check_link() -> crate::Result {
2,
3
)),
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()),
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() }),
"in this case, there is no rename-to field as last argument, it's based on the resource paths being different"
);

Expand Down Expand Up @@ -117,7 +117,7 @@ fn resources_of_worktree_and_odb_and_check_link() -> crate::Result {
0,
1
)),
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()),
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() }),
"Also obvious that symlinks are definitely special, but it's what git does as well"
);

Expand Down Expand Up @@ -340,9 +340,11 @@ fn source_and_destination_do_not_exist() -> crate::Result {
),
format!(
r#"{}"test" "missing" "/dev/null" "." "." "/dev/null" "." "." "a""#,
(!cfg!(windows))
.then_some(r#"GIT_DIFF_PATH_COUNTER="1" GIT_DIFF_PATH_TOTAL="1" GIT_DIR="." "#)
.unwrap_or_default()
if !cfg!(windows) {
r#"GIT_DIFF_PATH_COUNTER="1" GIT_DIFF_PATH_TOTAL="1" GIT_DIR="." "#
} else {
Default::default()
}
)
);
Ok(())
Expand Down
16 changes: 10 additions & 6 deletions gix-odb/src/store_impls/dynamic/load_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,11 @@ impl super::Store {
.collect();

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

// Figure out this number based on what we see while handling the existing indices
let mut num_loaded_indices = 0;
Expand Down Expand Up @@ -389,9 +391,11 @@ impl super::Store {
generation,
// 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,
// until we find one.
next_index_to_load: index_unchanged
.then(|| Arc::clone(&index.next_index_to_load))
.unwrap_or_default(),
next_index_to_load: if index_unchanged {
Arc::clone(&index.next_index_to_load)
} else {
Default::default()
},
loaded_indices: if index_unchanged {
Arc::clone(&index.loaded_indices)
} else {
Expand Down
8 changes: 4 additions & 4 deletions gix-path/src/env/auxiliary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod tests {
];

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

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

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

#[test]
#[cfg_attr(not(windows), ignore)]
#[cfg_attr(not(windows), ignore = "only meaningful on Windows")]
fn find_git_associated_windows_executable_with_fallback_falls_back() {
for stem in SHOULD_NOT_FIND {
let path = super::find_git_associated_windows_executable_with_fallback(stem)
Expand Down
6 changes: 5 additions & 1 deletion gix-pathspec/src/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ impl Pattern {
_ => 0,
})
.sum::<isize>();
(count > 0).then_some(count as usize).unwrap_or_default()
if count > 0 {
count as usize
} else {
Default::default()
}
}

let mut path = gix_path::from_bstr(self.path.as_bstr());
Expand Down
6 changes: 5 additions & 1 deletion gix-protocol/tests/protocol/fetch/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ mod v2 {
for keepalive in [false, true] {
let fixture = format!(
"v2/clone-only{}.response",
keepalive.then_some("-with-keepalive").unwrap_or_default()
if keepalive {
"-with-keepalive"
} else {
Default::default()
}
);
let mut provider = mock_reader(&fixture);
let mut reader = provider.as_read_without_sidebands();
Expand Down
6 changes: 5 additions & 1 deletion gix-protocol/tests/protocol/fetch/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ async fn clone() -> crate::Result {
let mut dlg = CloneDelegate::default();
let fixture = format!(
"v1/clone{}.response",
with_keepalive.then_some("-with-keepalive").unwrap_or_default()
if with_keepalive {
"-with-keepalive"
} else {
Default::default()
}
);
crate::fetch(
transport(
Expand Down
8 changes: 5 additions & 3 deletions gix-transport/src/client/blocking_io/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ impl SpawnProcessOnDemand {
.expect("valid url"),
path,
ssh_cmd: None,
envs: (version != Protocol::V1)
.then(|| vec![("GIT_PROTOCOL", format!("version={}", version as usize))])
.unwrap_or_default(),
envs: if version != Protocol::V1 {
vec![("GIT_PROTOCOL", format!("version={}", version as usize))]
} else {
Default::default()
},
ssh_disallow_shell: false,
child: None,
connection: None,
Expand Down
106 changes: 106 additions & 0 deletions gix/src/object/tree/entry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
use crate::object::tree::EntryRef;
use crate::{bstr::BStr, ext::ObjectIdExt, object::tree::Entry};

/// Access
impl<'repo> Entry<'repo> {
/// The kind of object to which `oid` is pointing to.
pub fn mode(&self) -> gix_object::tree::EntryMode {
self.inner.mode
}

/// The name of the file in the parent tree.
pub fn filename(&self) -> &BStr {
self.inner.filename.as_ref()
}

/// Return the object id of the entry.
pub fn id(&self) -> crate::Id<'repo> {
self.inner.oid.attach(self.repo)
}

/// Return the object this entry points to.
pub fn object(&self) -> Result<crate::Object<'repo>, crate::object::find::existing::Error> {
self.id().object()
}

/// Return the plain object id of this entry, without access to the repository.
pub fn oid(&self) -> &gix_hash::oid {
&self.inner.oid
}

/// Return the plain object id of this entry, without access to the repository.
pub fn object_id(&self) -> gix_hash::ObjectId {
self.inner.oid
}
}

/// Consuming
impl Entry<'_> {
/// Return the contained object.
pub fn detach(self) -> gix_object::tree::Entry {
self.inner
}
}

impl<'repo, 'a> EntryRef<'repo, 'a> {
/// The kind of object to which [`id()`][Self::id()] is pointing.
pub fn mode(&self) -> gix_object::tree::EntryMode {
self.inner.mode
}

/// The kind of object to which [`id()`][Self::id()] is pointing, as shortcut to [self.mode().kind()](Self::mode()).
pub fn kind(&self) -> gix_object::tree::EntryKind {
self.inner.mode.kind()
}

/// The name of the file in the parent tree.
pub fn filename(&self) -> &gix_object::bstr::BStr {
self.inner.filename
}

/// Return the entries id, connected to the underlying repository.
pub fn id(&self) -> crate::Id<'repo> {
crate::Id::from_id(self.inner.oid, self.repo)
}

/// Return the plain object id of this entry, without access to the repository.
pub fn oid(&self) -> &gix_hash::oid {
self.inner.oid
}

/// Return the object this entry points to.
pub fn object(&self) -> Result<crate::Object<'repo>, crate::object::find::existing::Error> {
self.id().object()
}

/// Return the plain object id of this entry, without access to the repository.
pub fn object_id(&self) -> gix_hash::ObjectId {
self.inner.oid.to_owned()
}

/// Detach the repository from this instance.
pub fn detach(&self) -> gix_object::tree::EntryRef<'a> {
self.inner
}

/// Create an instance that doesn't bind to a buffer anymore (but that still contains a repository reference).
pub fn to_owned(&self) -> Entry<'repo> {
Entry {
inner: self.inner.into(),
repo: self.repo,
}
}
}

impl std::fmt::Display for EntryRef<'_, '_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{:>6o} {:>6} {}\t{}",
self.mode(),
self.mode().as_str(),
self.id().shorten_or_id(),
self.filename()
)
}
}
Loading
Loading