Skip to content

Commit 4a11ee8

Browse files
committed
ostree: Set parent of merge commit to base commit if present
Motivated by ostreedev/ostree#3523 This is an obvious and trivially easy thing to do here, and makes dereferencing from "merge -> base" client side also trivial which is especially important in the initramfs. Signed-off-by: Colin Walters <[email protected]>
1 parent 39b0a32 commit 4a11ee8

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

crates/ostree-ext/src/container/store.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,9 +1167,12 @@ impl ImageImporter {
11671167
.write_mtree(&mt, cancellable)
11681168
.context("Writing mtree")?;
11691169
let merged_root = merged_root.downcast::<ostree::RepoFile>().unwrap();
1170+
// The merge has the base commit as a parent, if it exists. See
1171+
// https://github.com/ostreedev/ostree/pull/3523
1172+
let parent = base_commit.as_deref();
11701173
let merged_commit = repo
11711174
.write_commit_with_time(
1172-
None,
1175+
parent,
11731176
None,
11741177
None,
11751178
Some(&metadata),

crates/ostree-ext/tests/it/main.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use oci_spec::image as oci_image;
1212
use ocidir::oci_spec::distribution::Reference;
1313
use ocidir::oci_spec::image::{Arch, DigestAlgorithm};
1414
use ostree_ext::chunking::ObjectMetaSized;
15-
use ostree_ext::container::{store, ManifestDiff};
15+
use ostree_ext::container::{store, ManifestDiff, OSTREE_COMMIT_LABEL};
1616
use ostree_ext::container::{
1717
Config, ExportOpts, ImageReference, OstreeImageReference, SignatureSource, Transport,
1818
};
@@ -968,6 +968,7 @@ async fn test_container_chunked() -> Result<()> {
968968
let mut fixture = Fixture::new_v1()?;
969969

970970
let (imgref, expected_digest) = fixture.export_container().await.unwrap();
971+
let exported_commit = fixture.srcrepo().require_rev(fixture.testref())?;
971972
let imgref = OstreeImageReference {
972973
sigverify: SignatureSource::ContainerPolicyAllowInsecure,
973974
imgref,
@@ -990,7 +991,12 @@ async fn test_container_chunked() -> Result<()> {
990991
store::PrepareResult::AlreadyPresent(_) => panic!("should not be already imported"),
991992
store::PrepareResult::Ready(r) => r,
992993
};
994+
let labels = prep.config.labels_of_config().unwrap();
993995
assert!(prep.deprecated_warning().is_none());
996+
assert_eq!(
997+
labels.get(OSTREE_COMMIT_LABEL).unwrap(),
998+
exported_commit.as_str()
999+
);
9941000
assert_eq!(prep.version(), Some("42.0"));
9951001
let digest = prep.manifest_digest.clone();
9961002
assert!(prep.ostree_commit_layer.as_ref().unwrap().commit.is_none());
@@ -1023,6 +1029,14 @@ async fn test_container_chunked() -> Result<()> {
10231029
}
10241030
let import = imp.import(prep).await.context("Init pull derived").unwrap();
10251031
assert_eq!(import.manifest_digest, digest);
1032+
// For now we never expect that these are the same
1033+
assert_ne!(import.get_commit(), exported_commit.as_str());
1034+
// But the parent should match
1035+
let commit_obj = fixture.destrepo().load_commit(import.get_commit())?.0;
1036+
assert_eq!(
1037+
ostree::commit_get_parent(&commit_obj).unwrap(),
1038+
exported_commit.as_str()
1039+
);
10261040

10271041
assert_eq!(store::list_images(fixture.destrepo()).unwrap().len(), 1);
10281042

0 commit comments

Comments
 (0)