Skip to content

Commit

Permalink
reproduce issue with 'too many packs' for slotmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 13, 2025
1 parent af8f201 commit 167f49f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gix/src/commit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//!
#![allow(clippy::empty_docs)]

use std::convert::Infallible;

/// An empty array of a type usable with the `gix::easy` API to help declaring no parents should be used
pub const NO_PARENT_IDS: [gix_hash::ObjectId; 0] = [];

Expand All @@ -22,6 +24,12 @@ pub enum Error {
ReferenceEdit(#[from] crate::reference::edit::Error),
}

impl From<std::convert::Infallible> for Error {
fn from(_value: Infallible) -> Self {
unreachable!("cannot be invoked")
}
}

///
#[cfg(feature = "revision")]
pub mod describe {
Expand Down
62 changes: 62 additions & 0 deletions gix/tests/gix/remote/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ mod shallow {
mod blocking_and_async_io {
use std::sync::atomic::AtomicBool;

use gix::interrupt::IS_INTERRUPTED;
use gix::{
config::tree::Protocol,
remote::{fetch, fetch::Status, Direction::Fetch},
};
use gix_features::progress;
use gix_odb::store::init::Slots;
use gix_protocol::maybe_async;
use gix_testtools::tempfile;
use gix_testtools::tempfile::TempDir;

use crate::{
Expand Down Expand Up @@ -85,6 +88,65 @@ mod blocking_and_async_io {
try_repo_rw(name).unwrap()
}

#[test]
fn fetch_more_packs_than_can_be_handled() -> gix_testtools::Result {
fn create_empty_commit(repo: &gix::Repository) -> anyhow::Result<()> {
let name = repo.head_name()?.expect("no detached head");
repo.commit(
name.as_bstr(),
"empty",
gix::hash::ObjectId::empty_tree(repo.object_hash()),
repo.try_find_reference(name.as_ref())?.map(|r| r.id()),
)?;
Ok(())
}
let remote_dir = tempfile::tempdir()?;
let remote_repo = gix::init_bare(remote_dir.path())?;
create_empty_commit(&remote_repo)?;

for max_packs in 1..=2 {
let local_dir = tempfile::tempdir()?;
let (local_repo, _) = gix::clone::PrepareFetch::new(
remote_repo.path(),
local_dir.path(),
gix::create::Kind::Bare,
Default::default(),
gix::open::Options::isolated().object_store_slots(Slots::Given(max_packs)),
)?
.fetch_only(gix::progress::Discard, &IS_INTERRUPTED)?;

let remote = local_repo
.branch_remote(
local_repo.head_ref()?.expect("branch available").name().shorten(),
Fetch,
)
.expect("remote is configured after clone")?;
for round in 1.. {
eprintln!("Fetch number {round}…");
create_empty_commit(&remote_repo)?;
match remote
.connect(Fetch)?
.prepare_fetch(gix::progress::Discard, Default::default())?
.receive(gix::progress::Discard, &IS_INTERRUPTED)
{
Ok(out) => {
for local_tracking_branch_name in out.ref_map.mappings.into_iter().filter_map(|m| m.local) {
let r = local_repo.find_reference(&local_tracking_branch_name)?;
r.id()
.object()
.expect("object should be present after fetching, triggering pack refreshes works");
}
}
Err(err) => assert_eq!(
err.to_string(),
"It should indicate that the ODB is exhausted for now - we can't grow"
),
}
}
}
Ok(())
}

#[test]
#[cfg(feature = "blocking-network-client")]
#[allow(clippy::result_large_err)]
Expand Down

0 comments on commit 167f49f

Please sign in to comment.