From 43d8096dcdd797fd015c177cefeb8ee1f0ae5881 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Aug 2024 21:43:18 +0200 Subject: [PATCH] fix!: improve naming and change `Target::Peeled` to `Target::Object`. This also renames `TargetRef::Peeled` to `TargetRef::Object` to make clear that it's not necessarily the peeled object that is contained. Previously these terms were confusing due to the incorrect usage of the word `peeled`. --- gix-ref/src/lib.rs | 12 +++--- gix-ref/src/raw.rs | 5 ++- .../src/store/file/loose/reference/decode.rs | 2 +- gix-ref/src/store/file/raw_ext.rs | 11 ++--- gix-ref/src/store/file/transaction/commit.rs | 10 ++--- gix-ref/src/store/file/transaction/prepare.rs | 12 +++--- gix-ref/src/store/packed/transaction.rs | 4 +- gix-ref/src/target.rs | 34 ++++++++-------- gix-ref/tests/file/reference.rs | 27 ++++++++++--- gix-ref/tests/file/store/find.rs | 20 +++++----- gix-ref/tests/file/store/iter.rs | 14 +++---- gix-ref/tests/file/store/mod.rs | 2 +- gix-ref/tests/file/transaction/mod.rs | 2 +- .../create_or_update/collisions.rs | 6 +-- .../create_or_update/mod.rs | 40 +++++++++---------- .../transaction/prepare_and_commit/delete.rs | 10 ++--- gix-ref/tests/file/worktree.rs | 2 +- .../fixtures/generated-archives/.gitignore | 1 + gix-ref/tests/fixtures/make_multi_hop_ref.sh | 13 ++++++ gix-ref/tests/transaction/mod.rs | 16 ++++---- 20 files changed, 138 insertions(+), 105 deletions(-) create mode 100644 gix-ref/tests/fixtures/make_multi_hop_ref.sh diff --git a/gix-ref/src/lib.rs b/gix-ref/src/lib.rs index 8c35ed35c57..b7c503eb2bc 100644 --- a/gix-ref/src/lib.rs +++ b/gix-ref/src/lib.rs @@ -150,8 +150,8 @@ pub struct Namespace(BString); #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Kind { - /// A ref that points to an object id - Peeled, + /// A ref that points to an object id directly. + Object, /// A ref that points to another reference, adding a level of indirection. /// /// It can be resolved to an id using the [`peel_in_place_to_id()`][`crate::file::ReferenceExt::peel_to_id_in_place()`] method. @@ -203,8 +203,8 @@ pub enum Category<'a> { #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Target { - /// A ref that points to an object id - Peeled(ObjectId), + /// A ref that points directly to an object id. + Object(ObjectId), /// A ref that points to another reference by its validated name, adding a level of indirection. /// /// Note that this is an extension of gitoxide which will be helpful in logging all reference changes. @@ -214,8 +214,8 @@ pub enum Target { /// Denotes a ref target, equivalent to [`Kind`], but with immutable data. #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)] pub enum TargetRef<'a> { - /// A ref that points to an object id - Peeled(&'a oid), + /// A ref that points directly to an object id. + Object(&'a oid), /// A ref that points to another reference by its validated name, adding a level of indirection. Symbolic(&'a FullNameRef), } diff --git a/gix-ref/src/raw.rs b/gix-ref/src/raw.rs index 14eb09eecb2..34eb6e814dc 100644 --- a/gix-ref/src/raw.rs +++ b/gix-ref/src/raw.rs @@ -10,7 +10,8 @@ pub struct Reference { pub name: FullName, /// The target of the reference, either a symbolic reference by full name or a possibly intermediate object by its id. pub target: Target, - /// The fully peeled object to which this reference ultimately points to. Only guaranteed to be set after + /// The fully peeled object to which this reference ultimately points to after following all symbolic refs and all annotated + /// tags. Only guaranteed to be set after /// [`Reference::peel_to_id_in_place()`](crate::file::ReferenceExt) was called or if this reference originated /// from a packed ref. pub peeled: Option, @@ -48,7 +49,7 @@ mod convert { fn from(value: packed::Reference<'p>) -> Self { Reference { name: value.name.into(), - target: Target::Peeled(value.target()), + target: Target::Object(value.target()), peeled: value .object .map(|hex| ObjectId::from_hex(hex).expect("parser validation")), diff --git a/gix-ref/src/store/file/loose/reference/decode.rs b/gix-ref/src/store/file/loose/reference/decode.rs index 68fb4f65d70..03590eaec95 100644 --- a/gix-ref/src/store/file/loose/reference/decode.rs +++ b/gix-ref/src/store/file/loose/reference/decode.rs @@ -35,7 +35,7 @@ impl TryFrom for Target { fn try_from(v: MaybeUnsafeState) -> Result { Ok(match v { - MaybeUnsafeState::Id(id) => Target::Peeled(id), + MaybeUnsafeState::Id(id) => Target::Object(id), MaybeUnsafeState::UnvalidatedPath(name) => { Target::Symbolic(match gix_validate::reference::name(name.as_ref()) { Ok(_) => FullName(name), diff --git a/gix-ref/src/store/file/raw_ext.rs b/gix-ref/src/store/file/raw_ext.rs index ede518827fd..eeb44ff8043 100644 --- a/gix-ref/src/store/file/raw_ext.rs +++ b/gix-ref/src/store/file/raw_ext.rs @@ -21,7 +21,8 @@ pub trait ReferenceExt: Sealed { fn log_exists(&self, store: &file::Store) -> bool; /// Follow all symbolic targets this reference might point to and peel the underlying object - /// to the end of the chain, and return it, using `objects` to access them. + /// to the end of the tag-chain, returning the first non-tag object the annotated tag points to, + /// using `objects` to access them. /// /// This is useful to learn where this reference is ultimately pointing to. fn peel_to_id_in_place( @@ -89,7 +90,7 @@ impl ReferenceExt for Reference { ) -> Result { match self.peeled { Some(peeled) => { - self.target = Target::Peeled(peeled.to_owned()); + self.target = Target::Object(peeled.to_owned()); Ok(peeled) } None => { @@ -136,7 +137,7 @@ impl ReferenceExt for Reference { }; }; self.peeled = Some(peeled_id); - self.target = Target::Peeled(peeled_id); + self.target = Target::Object(peeled_id); Ok(peeled_id) } } @@ -161,11 +162,11 @@ impl ReferenceExt for Reference { match self.peeled { Some(peeled) => Some(Ok(Reference { name: self.name.clone(), - target: Target::Peeled(peeled), + target: Target::Object(peeled), peeled: None, })), None => match &self.target { - Target::Peeled(_) => None, + Target::Object(_) => None, Target::Symbolic(full_name) => match store.try_find_packed(full_name.as_ref(), packed) { Ok(Some(next)) => Some(Ok(next)), Ok(None) => Some(Err(file::find::existing::Error::NotFound { diff --git a/gix-ref/src/store/file/transaction/commit.rs b/gix-ref/src/store/file/transaction/commit.rs index 829e45ebb8e..deb34172c15 100644 --- a/gix-ref/src/store/file/transaction/commit.rs +++ b/gix-ref/src/store/file/transaction/commit.rs @@ -54,17 +54,17 @@ impl<'s, 'p> Transaction<'s, 'p> { // Unless, the ref is new and we can obtain a peeled id // identified by the expectation of what could be there, as is the case when cloning. match expected { - PreviousValue::ExistingMustMatch(Target::Peeled(oid)) => { + PreviousValue::ExistingMustMatch(Target::Object(oid)) => { Some((Some(gix_hash::ObjectId::null(oid.kind())), oid)) } _ => None, } } - Target::Peeled(new_oid) => { + Target::Object(new_oid) => { let previous = match expected { // Here, this means that the ref already existed, and that it will receive (even transitively) // the given value - PreviousValue::MustExistAndMatch(Target::Peeled(oid)) => Some(oid.to_owned()), + PreviousValue::MustExistAndMatch(Target::Object(oid)) => Some(oid.to_owned()), _ => None, } .or(change.leaf_referent_previous_oid); @@ -88,7 +88,7 @@ impl<'s, 'p> Transaction<'s, 'p> { // Don't do anything else while keeping the lock after potentially updating the reflog. // We delay deletion of the reference and dropping the lock to after the packed-refs were // safely written. - if delete_loose_refs && matches!(new, Target::Peeled(_)) { + if delete_loose_refs && matches!(new, Target::Object(_)) { change.lock = lock; continue; } @@ -156,7 +156,7 @@ impl<'s, 'p> Transaction<'s, 'p> { log: LogChange { mode, .. }, new, .. - } => delete_loose_refs && *mode == RefLog::AndReference && matches!(new, Target::Peeled(_)), + } => delete_loose_refs && *mode == RefLog::AndReference && matches!(new, Target::Object(_)), Change::Delete { log: mode, .. } => *mode == RefLog::AndReference, }; if take_lock_and_delete { diff --git a/gix-ref/src/store/file/transaction/prepare.rs b/gix-ref/src/store/file/transaction/prepare.rs index 79d86c6cbd5..4b17b71b2b9 100644 --- a/gix-ref/src/store/file/transaction/prepare.rs +++ b/gix-ref/src/store/file/transaction/prepare.rs @@ -124,7 +124,7 @@ impl<'s, 'p> Transaction<'s, 'p> { | (PreviousValue::MustExist, Some(_)) | (PreviousValue::MustNotExist | PreviousValue::ExistingMustMatch(_), None) => {} (PreviousValue::MustExist, None) => { - let expected = Target::Peeled(store.object_hash.null()); + let expected = Target::Object(store.object_hash.null()); let full_name = change.name(); return Err(Error::MustExist { full_name, expected }); } @@ -163,9 +163,9 @@ impl<'s, 'p> Transaction<'s, 'p> { fn new_would_change_existing(new: &Target, existing: &Target) -> (bool, bool) { match (new, existing) { - (Target::Peeled(new), Target::Peeled(old)) => (old != new, false), + (Target::Object(new), Target::Object(old)) => (old != new, false), (Target::Symbolic(new), Target::Symbolic(old)) => (old != new, true), - (Target::Peeled(_), _) => (true, false), + (Target::Object(_), _) => (true, false), (Target::Symbolic(_), _) => (true, true), } } @@ -182,7 +182,7 @@ impl<'s, 'p> Transaction<'s, 'p> { let mut lock = lock.take().map_or_else(obtain_lock, Ok)?; lock.with_mut(|file| match new { - Target::Peeled(oid) => write!(file, "{oid}"), + Target::Object(oid) => write!(file, "{oid}"), Target::Symbolic(name) => writeln!(file, "ref: {}", name.0), })?; Some(lock.close()?) @@ -277,7 +277,7 @@ impl<'s, 'p> Transaction<'s, 'p> { }; if let Some(ref mut num_updates) = maybe_updates_for_packed_refs { if let Change::Update { - new: Target::Peeled(_), .. + new: Target::Object(_), .. } = edit.update.change { edits_for_packed_transaction.push(RefEdit { @@ -390,7 +390,7 @@ impl<'s, 'p> Transaction<'s, 'p> { // traverse parent chain from leaf/peeled ref and set the leaf previous oid accordingly // to help with their reflog entries - if let (Some(crate::TargetRef::Peeled(oid)), Some(parent_idx)) = + if let (Some(crate::TargetRef::Object(oid)), Some(parent_idx)) = (change.update.change.previous_value(), change.parent_index) { let oid = oid.to_owned(); diff --git a/gix-ref/src/store/packed/transaction.rs b/gix-ref/src/store/packed/transaction.rs index 8c615a10d4b..d4e2503d760 100644 --- a/gix-ref/src/store/packed/transaction.rs +++ b/gix-ref/src/store/packed/transaction.rs @@ -102,7 +102,7 @@ impl packed::Transaction { let mut buf = Vec::new(); for edit in &mut edits { if let Change::Update { - new: Target::Peeled(new), + new: Target::Object(new), .. } = edit.inner.change { @@ -235,7 +235,7 @@ fn write_edit(out: &mut dyn std::io::Write, edit: &Edit, lines_written: &mut i32 match edit.inner.change { Change::Delete { .. } => {} Change::Update { - new: Target::Peeled(target_oid), + new: Target::Object(target_oid), .. } => { write!(out, "{target_oid} ")?; diff --git a/gix-ref/src/target.rs b/gix-ref/src/target.rs index 15d1e3fc0e9..46967f969bd 100644 --- a/gix-ref/src/target.rs +++ b/gix-ref/src/target.rs @@ -9,28 +9,28 @@ impl<'a> TargetRef<'a> { pub fn kind(&self) -> Kind { match self { TargetRef::Symbolic(_) => Kind::Symbolic, - TargetRef::Peeled(_) => Kind::Peeled, + TargetRef::Object(_) => Kind::Object, } } /// Interpret this target as object id which maybe `None` if it is symbolic. pub fn try_id(&self) -> Option<&oid> { match self { TargetRef::Symbolic(_) => None, - TargetRef::Peeled(oid) => Some(oid), + TargetRef::Object(oid) => Some(oid), } } /// Interpret this target as object id or **panic** if it is symbolic. pub fn id(&self) -> &oid { match self { TargetRef::Symbolic(_) => panic!("BUG: tries to obtain object id from symbolic target"), - TargetRef::Peeled(oid) => oid, + TargetRef::Object(oid) => oid, } } /// Interpret this target as name of the reference it points to which maybe `None` if it an object id. pub fn try_name(&self) -> Option<&FullNameRef> { match self { TargetRef::Symbolic(name) => Some(name), - TargetRef::Peeled(_) => None, + TargetRef::Object(_) => None, } } /// Convert this instance into an owned version, without consuming it. @@ -44,14 +44,14 @@ impl Target { pub fn kind(&self) -> Kind { match self { Target::Symbolic(_) => Kind::Symbolic, - Target::Peeled(_) => Kind::Peeled, + Target::Object(_) => Kind::Object, } } /// Return true if this is a peeled target with a null hash pub fn is_null(&self) -> bool { match self { - Target::Peeled(oid) => oid.is_null(), + Target::Object(oid) => oid.is_null(), Target::Symbolic(_) => false, } } @@ -59,7 +59,7 @@ impl Target { /// Interpret this owned Target as shared Target pub fn to_ref(&self) -> TargetRef<'_> { match self { - Target::Peeled(oid) => TargetRef::Peeled(oid), + Target::Object(oid) => TargetRef::Object(oid), Target::Symbolic(name) => TargetRef::Symbolic(name.as_ref()), } } @@ -68,21 +68,21 @@ impl Target { pub fn try_id(&self) -> Option<&oid> { match self { Target::Symbolic(_) => None, - Target::Peeled(oid) => Some(oid), + Target::Object(oid) => Some(oid), } } /// Interpret this target as object id or panic if it is symbolic. pub fn id(&self) -> &oid { match self { Target::Symbolic(_) => panic!("BUG: tries to obtain object id from symbolic target"), - Target::Peeled(oid) => oid, + Target::Object(oid) => oid, } } /// Return the contained object id or panic pub fn into_id(self) -> ObjectId { match self { Target::Symbolic(_) => panic!("BUG: expected peeled reference target but found symbolic one"), - Target::Peeled(oid) => oid, + Target::Object(oid) => oid, } } @@ -90,14 +90,14 @@ impl Target { pub fn try_into_id(self) -> Result { match self { Target::Symbolic(_) => Err(self), - Target::Peeled(oid) => Ok(oid), + Target::Object(oid) => Ok(oid), } } /// Interpret this target as name of the reference it points to which maybe `None` if it an object id. pub fn try_name(&self) -> Option<&FullNameRef> { match self { Target::Symbolic(name) => Some(name.as_ref()), - Target::Peeled(_) => None, + Target::Object(_) => None, } } } @@ -105,7 +105,7 @@ impl Target { impl<'a> From> for Target { fn from(src: TargetRef<'a>) -> Self { match src { - TargetRef::Peeled(oid) => Target::Peeled(oid.to_owned()), + TargetRef::Object(oid) => Target::Object(oid.to_owned()), TargetRef::Symbolic(name) => Target::Symbolic(name.to_owned()), } } @@ -114,7 +114,7 @@ impl<'a> From> for Target { impl<'a> PartialEq> for Target { fn eq(&self, other: &TargetRef<'a>) -> bool { match (self, other) { - (Target::Peeled(lhs), TargetRef::Peeled(rhs)) => lhs == rhs, + (Target::Object(lhs), TargetRef::Object(rhs)) => lhs == rhs, (Target::Symbolic(lhs), TargetRef::Symbolic(rhs)) => lhs.as_bstr() == rhs.as_bstr(), _ => false, } @@ -123,7 +123,7 @@ impl<'a> PartialEq> for Target { impl From for Target { fn from(id: ObjectId) -> Self { - Target::Peeled(id) + Target::Object(id) } } @@ -132,7 +132,7 @@ impl TryFrom for ObjectId { fn try_from(value: Target) -> Result { match value { - Target::Peeled(id) => Ok(id), + Target::Object(id) => Ok(id), Target::Symbolic(_) => Err(value), } } @@ -147,7 +147,7 @@ impl From for Target { impl fmt::Display for Target { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Target::Peeled(oid) => oid.fmt(f), + Target::Object(oid) => oid.fmt(f), Target::Symbolic(name) => write!(f, "ref: {}", name.as_bstr()), } } diff --git a/gix-ref/tests/file/reference.rs b/gix-ref/tests/file/reference.rs index d4c071ab3af..bbf08f8ce47 100644 --- a/gix-ref/tests/file/reference.rs +++ b/gix-ref/tests/file/reference.rs @@ -47,6 +47,7 @@ mod reflog { } mod peel { + use gix_object::FindExt; use gix_ref::{file::ReferenceExt, Reference}; use crate::{ @@ -63,13 +64,13 @@ mod peel { let nr = Reference::from(r).follow(&store).expect("exists").expect("no failure"); assert!( - matches!(nr.target.to_ref(), gix_ref::TargetRef::Peeled(_)), + matches!(nr.target.to_ref(), gix_ref::TargetRef::Object(_)), "iteration peels a single level" ); assert!(nr.follow(&store).is_none(), "end of iteration"); assert_eq!( nr.target.to_ref(), - gix_ref::TargetRef::Peeled(&hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03")), + gix_ref::TargetRef::Object(&hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03")), "we still have the peeled target" ); Ok(()) @@ -100,7 +101,7 @@ mod peel { ); assert_eq!( head.kind(), - gix_ref::Kind::Peeled, + gix_ref::Kind::Object, "its peeled, but does have another step to peel to" ); @@ -110,7 +111,7 @@ mod peel { Some(hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03")), "packed refs are always peeled (at least the ones we choose to read)" ); - assert_eq!(peeled.kind(), gix_ref::Kind::Peeled, "it's terminally peeled now"); + assert_eq!(peeled.kind(), gix_ref::Kind::Object, "it's terminally peeled now"); assert!(peeled.follow(&store).is_none()); Ok(()) } @@ -143,6 +144,22 @@ mod peel { Ok(()) } + #[test] + fn to_id_long_jump() -> crate::Result { + let store = file::store_at("make_multi_hop_ref.sh")?; + let odb = gix_odb::at(store.git_dir().join("objects"))?; + let mut r: Reference = store.find("multi-hop")?; + r.peel_to_id_in_place(&store, &odb)?; + + let commit = hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03"); + assert_eq!(r.peeled, Some(commit)); + + let mut buf = Vec::new(); + let obj = odb.find(&commit, &mut buf)?; + assert_eq!(obj.kind, gix_object::Kind::Commit, "always peeled to the first non-tag"); + Ok(()) + } + #[test] fn to_id_cycle() -> crate::Result { let store = file::store()?; @@ -204,7 +221,7 @@ mod parse { mktest!( peeled, b"c5241b835b93af497cda80ce0dceb8f49800df1c\n", - gix_ref::Kind::Peeled, + gix_ref::Kind::Object, Some(hex_to_id("c5241b835b93af497cda80ce0dceb8f49800df1c").as_ref()), None ); diff --git a/gix-ref/tests/file/store/find.rs b/gix-ref/tests/file/store/find.rs index 2343b33fb42..d4eb8dd0e88 100644 --- a/gix-ref/tests/file/store/find.rs +++ b/gix-ref/tests/file/store/find.rs @@ -133,19 +133,19 @@ mod loose { fn success() -> crate::Result { let store = store()?; for (partial_name, expected_path, expected_ref_kind) in &[ - ("dt1", "refs/tags/dt1", gix_ref::Kind::Peeled), // tags before heads - ("FETCH_HEAD", "FETCH_HEAD", gix_ref::Kind::Peeled), // special ref - ("heads/dt1", "refs/heads/dt1", gix_ref::Kind::Peeled), - ("d1", "refs/d1", gix_ref::Kind::Peeled), // direct refs before heads - ("heads/d1", "refs/heads/d1", gix_ref::Kind::Peeled), + ("dt1", "refs/tags/dt1", gix_ref::Kind::Object), // tags before heads + ("FETCH_HEAD", "FETCH_HEAD", gix_ref::Kind::Object), // special ref + ("heads/dt1", "refs/heads/dt1", gix_ref::Kind::Object), + ("d1", "refs/d1", gix_ref::Kind::Object), // direct refs before heads + ("heads/d1", "refs/heads/d1", gix_ref::Kind::Object), ("HEAD", "HEAD", gix_ref::Kind::Symbolic), // it finds shortest paths first ("origin", "refs/remotes/origin/HEAD", gix_ref::Kind::Symbolic), ("origin/HEAD", "refs/remotes/origin/HEAD", gix_ref::Kind::Symbolic), - ("origin/main", "refs/remotes/origin/main", gix_ref::Kind::Peeled), - ("t1", "refs/tags/t1", gix_ref::Kind::Peeled), - ("main", "refs/heads/main", gix_ref::Kind::Peeled), - ("heads/main", "refs/heads/main", gix_ref::Kind::Peeled), - ("refs/heads/main", "refs/heads/main", gix_ref::Kind::Peeled), + ("origin/main", "refs/remotes/origin/main", gix_ref::Kind::Object), + ("t1", "refs/tags/t1", gix_ref::Kind::Object), + ("main", "refs/heads/main", gix_ref::Kind::Object), + ("heads/main", "refs/heads/main", gix_ref::Kind::Object), + ("refs/heads/main", "refs/heads/main", gix_ref::Kind::Object), ] { let reference = store.try_find_loose(*partial_name)?.expect("exists"); assert_eq!(reference.name.as_bstr(), expected_path); diff --git a/gix-ref/tests/file/store/iter.rs b/gix-ref/tests/file/store/iter.rs index 0ed5a971843..900a15d56f0 100644 --- a/gix-ref/tests/file/store/iter.rs +++ b/gix-ref/tests/file/store/iter.rs @@ -394,16 +394,16 @@ fn overlay_iter() -> crate::Result { assert_eq!( ref_names, vec![ - (b"refs/heads/main".as_bstr().to_owned(), Peeled(c1)), - ("refs/heads/newer-as-loose".into(), Peeled(c2)), + (b"refs/heads/main".as_bstr().to_owned(), Object(c1)), + ("refs/heads/newer-as-loose".into(), Object(c2)), ( "refs/remotes/origin/HEAD".into(), Symbolic("refs/remotes/origin/main".try_into()?), ), - ("refs/remotes/origin/main".into(), Peeled(c1)), + ("refs/remotes/origin/main".into(), Object(c1)), ( "refs/tags/tag-object".into(), - Peeled(hex_to_id("b3109a7e51fc593f85b145a76c70ddd1d133fafd")), + Object(hex_to_id("b3109a7e51fc593f85b145a76c70ddd1d133fafd")), ) ] ); @@ -440,8 +440,8 @@ fn overlay_prefixed_iter() -> crate::Result { assert_eq!( ref_names, vec![ - (b"refs/heads/main".as_bstr().to_owned(), Peeled(c1)), - ("refs/heads/newer-as-loose".into(), Peeled(c2)), + (b"refs/heads/main".as_bstr().to_owned(), Object(c1)), + ("refs/heads/newer-as-loose".into(), Object(c2)), ] ); Ok(()) @@ -458,6 +458,6 @@ fn overlay_partial_prefix_iter() -> crate::Result { .map(|r| r.map(|r| (r.name.as_bstr().to_owned(), r.target))) .collect::, _>>()?; let c1 = hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03"); - assert_eq!(ref_names, vec![(b"refs/heads/main".as_bstr().to_owned(), Peeled(c1)),]); + assert_eq!(ref_names, vec![(b"refs/heads/main".as_bstr().to_owned(), Object(c1)),]); Ok(()) } diff --git a/gix-ref/tests/file/store/mod.rs b/gix-ref/tests/file/store/mod.rs index 4cfd6120b03..ceb76e52d9f 100644 --- a/gix-ref/tests/file/store/mod.rs +++ b/gix-ref/tests/file/store/mod.rs @@ -105,7 +105,7 @@ fn precompose_unicode_journey() -> crate::Result { // Intentionally use the decomposed versions of their names store_decomposed .loose_iter()? - .filter_map(|r| r.ok().filter(|r| r.kind() == gix_ref::Kind::Peeled)) + .filter_map(|r| r.ok().filter(|r| r.kind() == gix_ref::Kind::Object)) .map(|r| RefEdit { change: Change::Update { log: LogChange::default(), diff --git a/gix-ref/tests/file/transaction/mod.rs b/gix-ref/tests/file/transaction/mod.rs index 348f76df6e7..926b4d597bf 100644 --- a/gix-ref/tests/file/transaction/mod.rs +++ b/gix-ref/tests/file/transaction/mod.rs @@ -56,7 +56,7 @@ pub(crate) mod prepare_and_commit { message: "log peeled".into(), }, expected: PreviousValue::MustNotExist, - new: Target::Peeled(hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")), + new: Target::Object(hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")), }, name: name.try_into().expect("valid"), deref: false, diff --git a/gix-ref/tests/file/transaction/prepare_and_commit/create_or_update/collisions.rs b/gix-ref/tests/file/transaction/prepare_and_commit/create_or_update/collisions.rs index 5ef7a0ad1eb..622a589bfb4 100644 --- a/gix-ref/tests/file/transaction/prepare_and_commit/create_or_update/collisions.rs +++ b/gix-ref/tests/file/transaction/prepare_and_commit/create_or_update/collisions.rs @@ -127,7 +127,7 @@ fn conflicting_creation_into_packed_refs() -> crate::Result { change: Change::Update { log: LogChange::default(), expected: PreviousValue::Any, - new: Target::Peeled(gix_hash::Kind::Sha1.null()), + new: Target::Object(gix_hash::Kind::Sha1.null()), }, name: "refs/a".try_into().expect("valid"), deref: false, @@ -135,10 +135,10 @@ fn conflicting_creation_into_packed_refs() -> crate::Result { RefEdit { change: Change::Update { log: LogChange::default(), - expected: PreviousValue::MustExistAndMatch(Target::Peeled(hex_to_id( + expected: PreviousValue::MustExistAndMatch(Target::Object(hex_to_id( "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", ))), - new: Target::Peeled(gix_hash::Kind::Sha1.null()), + new: Target::Object(gix_hash::Kind::Sha1.null()), }, name: "refs/A".try_into().expect("valid"), deref: false, diff --git a/gix-ref/tests/file/transaction/prepare_and_commit/create_or_update/mod.rs b/gix-ref/tests/file/transaction/prepare_and_commit/create_or_update/mod.rs index 6c71b98ca76..2741a5fda2f 100644 --- a/gix-ref/tests/file/transaction/prepare_and_commit/create_or_update/mod.rs +++ b/gix-ref/tests/file/transaction/prepare_and_commit/create_or_update/mod.rs @@ -106,7 +106,7 @@ fn reference_with_equally_named_empty_or_non_empty_directory_already_in_place_ca fn reference_with_old_value_must_exist_when_creating_it() -> crate::Result { let (_keep, store) = empty_store()?; - let new_target = Target::Peeled(gix_hash::Kind::Sha1.null()); + let new_target = Target::Object(gix_hash::Kind::Sha1.null()); let res = store.transaction().prepare( Some(RefEdit { change: Change::Update { @@ -141,8 +141,8 @@ fn reference_with_explicit_value_must_match_the_value_on_update() -> crate::Resu Some(RefEdit { change: Change::Update { log: LogChange::default(), - new: Target::Peeled(gix_hash::Kind::Sha1.null()), - expected: PreviousValue::MustExistAndMatch(Target::Peeled(hex_to_id( + new: Target::Object(gix_hash::Kind::Sha1.null()), + expected: PreviousValue::MustExistAndMatch(Target::Object(hex_to_id( "28ce6a8b26aa170e1de65536fe8abe1832bd3242", ))), }, @@ -165,14 +165,14 @@ fn reference_with_explicit_value_must_match_the_value_on_update() -> crate::Resu #[test] fn the_existing_must_match_constraint_allow_non_existing_references_to_be_created() -> crate::Result { let (_keep, store) = store_writable("make_repo_for_reflog.sh")?; - let expected = PreviousValue::ExistingMustMatch(Target::Peeled(ObjectId::empty_tree(gix_hash::Kind::Sha1))); + let expected = PreviousValue::ExistingMustMatch(Target::Object(ObjectId::empty_tree(gix_hash::Kind::Sha1))); let edits = store .transaction() .prepare( Some(RefEdit { change: Change::Update { log: LogChange::default(), - new: Target::Peeled(gix_hash::Kind::Sha1.null()), + new: Target::Object(gix_hash::Kind::Sha1.null()), expected: expected.clone(), }, name: "refs/heads/new".try_into()?, @@ -188,7 +188,7 @@ fn the_existing_must_match_constraint_allow_non_existing_references_to_be_create vec![RefEdit { change: Change::Update { log: LogChange::default(), - new: Target::Peeled(gix_hash::Kind::Sha1.null()), + new: Target::Object(gix_hash::Kind::Sha1.null()), expected, }, name: "refs/heads/new".try_into()?, @@ -209,8 +209,8 @@ fn the_existing_must_match_constraint_requires_existing_references_to_have_the_g Some(RefEdit { change: Change::Update { log: LogChange::default(), - new: Target::Peeled(gix_hash::Kind::Sha1.null()), - expected: PreviousValue::ExistingMustMatch(Target::Peeled(hex_to_id( + new: Target::Object(gix_hash::Kind::Sha1.null()), + expected: PreviousValue::ExistingMustMatch(Target::Object(hex_to_id( "28ce6a8b26aa170e1de65536fe8abe1832bd3242", ))), }, @@ -273,7 +273,7 @@ fn reference_with_must_exist_constraint_must_exist_already_with_any_value() -> c let target = head.target; let previous_reflog_count = reflog_lines(&store, "HEAD")?.len(); - let new_target = Target::Peeled(ObjectId::empty_tree(gix_hash::Kind::Sha1)); + let new_target = Target::Object(ObjectId::empty_tree(gix_hash::Kind::Sha1)); let edits = store .transaction() .prepare( @@ -404,7 +404,7 @@ fn symbolic_reference_writes_reflog_if_previous_value_is_set() -> crate::Result change: Change::Update { log, new: new_head_value, - expected: PreviousValue::ExistingMustMatch(Target::Peeled(new_oid)), + expected: PreviousValue::ExistingMustMatch(Target::Object(new_oid)), }, name: "refs/heads/symbolic".try_into()?, deref: false, @@ -441,7 +441,7 @@ fn windows_device_name_is_illegal_with_enabled_windows_protections() -> crate::R message: "ignored".into(), }; - let new = Target::Peeled(hex_to_id("28ce6a8b26aa170e1de65536fe8abe1832bd3242")); + let new = Target::Object(hex_to_id("28ce6a8b26aa170e1de65536fe8abe1832bd3242")); for invalid_name in ["refs/heads/CON", "refs/CON/still-invalid"] { let err = store .transaction() @@ -550,7 +550,7 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { assert!(store.try_find_loose(referent)?.is_none(), "referent wasn't created"); let new_oid = hex_to_id("28ce6a8b26aa170e1de65536fe8abe1832bd3242"); - let new = Target::Peeled(new_oid); + let new = Target::Object(new_oid); let log = LogChange { message: "an actual change".into(), mode: RefLog::AndReference, @@ -614,7 +614,7 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result { ); let referent_ref = store.find_loose(referent)?; - assert_eq!(referent_ref.kind(), gix_ref::Kind::Peeled, "referent is a peeled ref"); + assert_eq!(referent_ref.kind(), gix_ref::Kind::Object, "referent is a peeled ref"); assert_eq!( referent_ref.target.to_ref().try_id(), Some(new_oid.as_ref()), @@ -661,7 +661,7 @@ fn write_reference_to_which_head_points_to_does_not_update_heads_reflog_even_tho message: "".into(), }, expected: PreviousValue::MustExist, - new: Target::Peeled(new_id), + new: Target::Object(new_id), }, name: referent.as_bstr().try_into()?, deref: false, @@ -681,10 +681,10 @@ fn write_reference_to_which_head_points_to_does_not_update_heads_reflog_even_tho force_create_reflog: false, message: "".into(), }, - expected: PreviousValue::MustExistAndMatch(Target::Peeled(hex_to_id( + expected: PreviousValue::MustExistAndMatch(Target::Object(hex_to_id( "02a7a22d90d7c02fb494ed25551850b868e634f0" )),), - new: Target::Peeled(new_id), + new: Target::Object(new_id), }, name: referent.as_bstr().try_into()?, deref: false, @@ -726,8 +726,8 @@ fn packed_refs_are_looked_up_when_checking_existing_values() -> crate::Result { force_create_reflog: false, message: "for pack".into(), }, - expected: PreviousValue::MustExistAndMatch(Target::Peeled(old_id)), - new: Target::Peeled(new_id), + expected: PreviousValue::MustExistAndMatch(Target::Object(old_id)), + new: Target::Object(new_id), }, name: "refs/heads/main".try_into()?, deref: false, @@ -774,7 +774,7 @@ fn packed_refs_creation_with_packed_refs_mode_prune_removes_original_loose_refs( .prepare( store .loose_iter()? - .filter_map(|r| r.ok().filter(|r| r.kind() == gix_ref::Kind::Peeled)) + .filter_map(|r| r.ok().filter(|r| r.kind() == gix_ref::Kind::Object)) .map(|r| RefEdit { change: Change::Update { log: LogChange::default(), @@ -887,7 +887,7 @@ fn packed_refs_deletion_in_deletions_and_updates_mode() -> crate::Result { .prepare( Some(RefEdit { change: Change::Delete { - expected: PreviousValue::MustExistAndMatch(Target::Peeled(old_id)), + expected: PreviousValue::MustExistAndMatch(Target::Object(old_id)), log: RefLog::AndReference, }, name: "refs/heads/d1".try_into()?, diff --git a/gix-ref/tests/file/transaction/prepare_and_commit/delete.rs b/gix-ref/tests/file/transaction/prepare_and_commit/delete.rs index c4a8c94c4fd..6b422e1e113 100644 --- a/gix-ref/tests/file/transaction/prepare_and_commit/delete.rs +++ b/gix-ref/tests/file/transaction/prepare_and_commit/delete.rs @@ -242,7 +242,7 @@ fn delete_broken_ref_that_must_exist_fails_as_it_is_no_valid_ref() -> crate::Res fn non_existing_can_be_deleted_with_the_may_exist_match_constraint() -> crate::Result { let (_keep, store) = empty_store()?; let previous_value = - PreviousValue::ExistingMustMatch(Target::Peeled(hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03"))); + PreviousValue::ExistingMustMatch(Target::Object(hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03"))); let edits = store .transaction() .prepare( @@ -363,7 +363,7 @@ fn packed_refs_are_consulted_when_determining_previous_value_of_ref_to_be_delete .prepare( Some(RefEdit { change: Change::Delete { - expected: PreviousValue::MustExistAndMatch(Target::Peeled(old_id)), + expected: PreviousValue::MustExistAndMatch(Target::Object(old_id)), log: RefLog::AndReference, }, name: "refs/heads/main".try_into()?, @@ -397,7 +397,7 @@ fn a_loose_ref_with_old_value_check_and_outdated_packed_refs_value_deletes_both_ .prepare( Some(RefEdit { change: Change::Delete { - expected: PreviousValue::MustExistAndMatch(Target::Peeled(branch_id)), + expected: PreviousValue::MustExistAndMatch(Target::Object(branch_id)), log: RefLog::AndReference, }, name: branch.name, @@ -432,8 +432,8 @@ fn all_contained_references_deletes_the_packed_ref_file_too() -> crate::Result { RefEdit { change: Change::Delete { expected: match mode { - "must-exist" => PreviousValue::MustExistAndMatch(Target::Peeled(r.target())), - "may-exist" => PreviousValue::ExistingMustMatch(Target::Peeled(r.target())), + "must-exist" => PreviousValue::MustExistAndMatch(Target::Object(r.target())), + "may-exist" => PreviousValue::ExistingMustMatch(Target::Object(r.target())), _ => unimplemented!("unknown mode: {}", mode), }, log: RefLog::AndReference, diff --git a/gix-ref/tests/file/worktree.rs b/gix-ref/tests/file/worktree.rs index 7b723eca107..321b7d17159 100644 --- a/gix-ref/tests/file/worktree.rs +++ b/gix-ref/tests/file/worktree.rs @@ -209,7 +209,7 @@ mod writable { Change::Update { log: LogChange::default(), expected: PreviousValue::MustNotExist, - new: Target::Peeled(id), + new: Target::Object(id), } } diff --git a/gix-ref/tests/fixtures/generated-archives/.gitignore b/gix-ref/tests/fixtures/generated-archives/.gitignore index 59d684d6015..08883d5f401 100644 --- a/gix-ref/tests/fixtures/generated-archives/.gitignore +++ b/gix-ref/tests/fixtures/generated-archives/.gitignore @@ -1,2 +1,3 @@ make_worktree_repo.tar make_worktree_repo_packed.tar +make_multi_hop_ref.tar diff --git a/gix-ref/tests/fixtures/make_multi_hop_ref.sh b/gix-ref/tests/fixtures/make_multi_hop_ref.sh new file mode 100644 index 00000000000..4a4f6e7d80b --- /dev/null +++ b/gix-ref/tests/fixtures/make_multi_hop_ref.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -eu -o pipefail + +git init -q + +git checkout -q -b main +git commit -q --allow-empty -m c1 + +git tag t1 +git tag -m "tag object" dt1 +git tag -m "tag object indirect" dt2 dt1 + +echo "ref: refs/tags/dt2" > .git/refs/multi-hop diff --git a/gix-ref/tests/transaction/mod.rs b/gix-ref/tests/transaction/mod.rs index 64d7627c0dd..bac6a7bd0bb 100644 --- a/gix-ref/tests/transaction/mod.rs +++ b/gix-ref/tests/transaction/mod.rs @@ -117,7 +117,7 @@ mod refedit_ext { fn non_symbolic_refs_are_ignored_or_if_the_deref_flag_is_not_set() -> crate::Result { let store = MockStore::with(Some(( "refs/heads/anything-but-not-symbolic", - Target::Peeled(gix_hash::Kind::Sha1.null()), + Target::Object(gix_hash::Kind::Sha1.null()), ))); let mut edits = vec![ RefEdit { @@ -204,7 +204,7 @@ mod refedit_ext { force_create_reflog: true, message: "the log message".into(), }, - new: Target::Peeled(gix_hash::Kind::Sha1.null()), + new: Target::Object(gix_hash::Kind::Sha1.null()), }, name: "refs/heads/update-symbolic-1".try_into()?, deref: true, @@ -236,7 +236,7 @@ mod refedit_ext { ), ( "refs/heads/delete-symbolic-3", - Target::Peeled(hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")), + Target::Object(hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")), ), ( "refs/heads/update-symbolic-1", @@ -248,7 +248,7 @@ mod refedit_ext { ), ( "refs/heads/update-symbolic-3", - Target::Peeled(hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")), + Target::Object(hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")), ), ]); let log = LogChange { @@ -274,7 +274,7 @@ mod refedit_ext { change: Change::Update { expected: PreviousValue::MustNotExist, log: log.clone(), - new: Target::Peeled(gix_hash::Kind::Sha1.null()), + new: Target::Object(gix_hash::Kind::Sha1.null()), }, name: "refs/heads/update-symbolic-1".try_into()?, deref: true, @@ -307,7 +307,7 @@ mod refedit_ext { change: Change::Update { expected: PreviousValue::Any, log: log_only.clone(), - new: Target::Peeled(gix_hash::Kind::Sha1.null()), + new: Target::Object(gix_hash::Kind::Sha1.null()), }, name: "refs/heads/update-symbolic-1".try_into()?, deref: false, @@ -324,7 +324,7 @@ mod refedit_ext { change: Change::Update { expected: PreviousValue::Any, log: log_only, - new: Target::Peeled(gix_hash::Kind::Sha1.null()), + new: Target::Object(gix_hash::Kind::Sha1.null()), }, name: "refs/heads/update-symbolic-2".try_into()?, deref: false, @@ -341,7 +341,7 @@ mod refedit_ext { change: Change::Update { expected: PreviousValue::MustNotExist, log, - new: Target::Peeled(gix_hash::Kind::Sha1.null()), + new: Target::Object(gix_hash::Kind::Sha1.null()), }, name: "refs/heads/update-symbolic-3".try_into()?, deref: false,