Skip to content

various improvements #2075

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 4 additions & 4 deletions gitoxide-core/src/repository/submodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn print_sm(sm: Submodule<'_>, dirty_suffix: Option<&str>, out: &mut impl std::i
}
writeln!(
out,
" {is_active} {path} {config} head:{head_id} index:{index_id} ({worktree}) [{url}]",
" {is_active} {path:?} {config} head:{head_id} index:{index_id} ({worktree}) [{url}]",
is_active = if !sm.is_active()? || !state.repository_exists {
"ⅹ"
} else {
Expand All @@ -48,8 +48,8 @@ fn print_sm(sm: Submodule<'_>, dirty_suffix: Option<&str>, out: &mut impl std::i
worktree = match sm_repo {
Some(repo) => {
// TODO(name-revision): this is the simple version, `git` gives it
// multiple tries https://github.com/git/git/blob/fac96dfbb1c24369ba7d37a5affd8adfe6c650fd/builtin/submodule--helper.c#L161
// and even uses `git name-rev`/`git describe --contains` which we can't do yet.
// multiple tries https://github.com/git/git/blob/fac96dfbb1c24369ba7d37a5affd8adfe6c650fd/builtin/submodule--helper.c#L161
// and even uses `git name-rev`/`git describe --contains` which we can't do yet.
repo.head_commit()?
.describe()
.names(SelectRef::AllRefs)
Expand All @@ -60,7 +60,7 @@ fn print_sm(sm: Submodule<'_>, dirty_suffix: Option<&str>, out: &mut impl std::i
.to_string()
}
None => {
"no worktree".to_string()
"no worktree".into()
}
},
url = sm.url()?.to_bstring()
Expand Down
13 changes: 10 additions & 3 deletions gix-odb/src/store_impls/dynamic/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,24 @@ impl Store {
let mut db_paths = crate::alternate::resolve(objects_dir.clone(), &current_dir)
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?;
db_paths.insert(0, objects_dir.clone());
let num_slots = super::Store::collect_indices_and_mtime_sorted_by_size(db_paths, None, None)
let num_slots = Store::collect_indices_and_mtime_sorted_by_size(db_paths, None, None)
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))?
.len();

((num_slots as f32 * multiplier) as usize).max(minimum)
let candidate = ((num_slots as f32 * multiplier) as usize).max(minimum);
if candidate > crate::store::types::PackId::max_indices() {
// A chance for this to work without 10% extra allocation - this already
// is an insane amount of packs.
num_slots
} else {
candidate
}
}
};
if slot_count > crate::store::types::PackId::max_indices() {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Cannot use more than 1^15 slots",
format!("Cannot use more than 2^15-1 slots, got {slot_count}"),
));
}
let mut replacements: Vec<_> = replacements.collect();
Expand Down
2 changes: 1 addition & 1 deletion gix-path/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include = ["src/**/*", "LICENSE-*"]
rust-version = "1.70"

[lib]
doctest = false
doctest = true

[dependencies]
gix-trace = { version = "^0.1.12", path = "../gix-trace" }
Expand Down
28 changes: 23 additions & 5 deletions gix-path/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,34 @@ pub fn to_windows_separators<'a>(path: impl Into<Cow<'a, BStr>>) -> Cow<'a, BStr
///
/// For example, this turns `a/./b/c/.././..` into `a`, and turns `/a/../b/..` into `/`.
///
/// If the input path was relative and ends up being the `current_dir`, `.` is returned instead of
/// the full path to `current_dir`.
/// ```
/// # fn main() {
/// # use std::path::Path;
/// # use gix_path::normalize;
/// for (input, expected) in [
/// ("a/./b/c/.././..", "a"),
/// ("/a/../b/..", "/"),
/// ("/base/a/..", "/base"),
/// ("./a/..", "."),
/// ("./a/../..", "/"),
/// (".///", ".///"),
/// ("a//b", "a//b"),
/// ("/base/../base", "/base"),
/// ] {
/// let input = Path::new(input);
/// let expected = Path::new(expected);
/// assert_eq!(normalize(input.into(), Path::new("/cwd")), Some(expected.into()));
/// }
/// # }
/// ```
///
/// Single `.` components as well as duplicate separators are left untouched.
/// Leading `.` components as well as duplicate separators are left untouched.
///
/// This is particularly useful when manipulating paths that are based on user input, and not
/// resolving intermediate symlinks keeps the path similar to what the user provided. If that's not
/// desirable, use `[realpath()][crate::realpath()` instead.
/// desirable, use [`realpath()`](crate::realpath()) instead.
///
/// Note that we might access the `current_dir` if we run out of path components to pop off, which
/// Note that we will use the `current_dir` if we run out of path components to pop off, which
/// is expected to be absolute as typical return value of `std::env::current_dir()` or
/// `gix_fs::current_dir(…)` when `core.precomposeUnicode` is known. As a `current_dir` like `/c`
/// can be exhausted by paths like `../../r`, `None` will be returned to indicate the inability to
Expand Down
Loading