From ef24de24a82fe681581cc130f342363c47c0969a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 07:48:48 +0200 Subject: Merging upstream version 1.75.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/gix/src/repository/cache.rs | 2 +- vendor/gix/src/repository/index.rs | 10 +++++++ vendor/gix/src/repository/location.rs | 1 + vendor/gix/src/repository/object.rs | 49 +++++++++++++++++++++++++++------- vendor/gix/src/repository/reference.rs | 9 +++++++ 5 files changed, 61 insertions(+), 10 deletions(-) (limited to 'vendor/gix/src/repository') diff --git a/vendor/gix/src/repository/cache.rs b/vendor/gix/src/repository/cache.rs index 7dcd844e6..03c2ff019 100644 --- a/vendor/gix/src/repository/cache.rs +++ b/vendor/gix/src/repository/cache.rs @@ -11,7 +11,7 @@ impl crate::Repository { pub fn object_cache_size(&mut self, bytes: impl Into>) { let bytes = bytes.into(); match bytes { - Some(bytes) if bytes == 0 => self.objects.unset_object_cache(), + Some(0) => self.objects.unset_object_cache(), Some(bytes) => self .objects .set_object_cache(move || Box::new(crate::object::cache::MemoryCappedHashmap::new(bytes))), diff --git a/vendor/gix/src/repository/index.rs b/vendor/gix/src/repository/index.rs index a21b138a5..59666fc5f 100644 --- a/vendor/gix/src/repository/index.rs +++ b/vendor/gix/src/repository/index.rs @@ -55,6 +55,16 @@ impl crate::Repository { }) } + /// Return the shared worktree index if present, or return a new empty one which has an association to the place where the index would be. + pub fn index_or_empty(&self) -> Result { + Ok(self.try_index()?.unwrap_or_else(|| { + worktree::Index::new(gix_fs::FileSnapshot::new(gix_index::File::from_state( + gix_index::State::new(self.object_hash()), + self.index_path(), + ))) + })) + } + /// Return a shared worktree index which is updated automatically if the in-memory snapshot has become stale as the underlying file /// on disk has changed, or `None` if no such file exists. /// diff --git a/vendor/gix/src/repository/location.rs b/vendor/gix/src/repository/location.rs index 5811e7bf9..8ee907ca9 100644 --- a/vendor/gix/src/repository/location.rs +++ b/vendor/gix/src/repository/location.rs @@ -37,6 +37,7 @@ impl crate::Repository { } /// Return the work tree containing all checked out files, if there is one. + #[doc(alias = "workdir", alias = "git2")] pub fn work_dir(&self) -> Option<&std::path::Path> { self.work_tree.as_deref() } diff --git a/vendor/gix/src/repository/object.rs b/vendor/gix/src/repository/object.rs index c156971d0..0b894939f 100644 --- a/vendor/gix/src/repository/object.rs +++ b/vendor/gix/src/repository/object.rs @@ -10,7 +10,7 @@ use gix_ref::{ }; use smallvec::SmallVec; -use crate::{commit, ext::ObjectIdExt, object, tag, Id, Object, Reference, Tree}; +use crate::{commit, ext::ObjectIdExt, object, tag, Blob, Id, Object, Reference, Tree}; /// Methods related to object creation. impl crate::Repository { @@ -26,7 +26,7 @@ impl crate::Repository { #[momo] pub fn find_object(&self, id: impl Into) -> Result, object::find::existing::Error> { let id = id.into(); - if id == gix_hash::ObjectId::empty_tree(self.object_hash()) { + if id == ObjectId::empty_tree(self.object_hash()) { return Ok(Object { id, kind: gix_object::Kind::Tree, @@ -46,7 +46,7 @@ impl crate::Repository { #[momo] pub fn find_header(&self, id: impl Into) -> Result { let id = id.into(); - if id == gix_hash::ObjectId::empty_tree(self.object_hash()) { + if id == ObjectId::empty_tree(self.object_hash()) { return Ok(gix_odb::find::Header::Loose { kind: gix_object::Kind::Tree, size: 0, @@ -55,6 +55,25 @@ impl crate::Repository { self.objects.header(id) } + /// Return `true` if `id` exists in the object database. + /// + /// # Performance + /// + /// This method can be slow if the underlying [object database](crate::Repository::objects) has + /// an unsuitable [RefreshMode](gix_odb::store::RefreshMode) and `id` is not likely to exist. + /// Use [`repo.objects.refresh_never()`](gix_odb::store::Handle::refresh_never) to avoid expensive + /// IO-bound refreshes if an object wasn't found. + #[doc(alias = "exists", alias = "git2")] + #[momo] + pub fn has_object(&self, id: impl AsRef) -> bool { + let id = id.as_ref(); + if id == ObjectId::empty_tree(self.object_hash()) { + true + } else { + self.objects.contains(id) + } + } + /// Obtain information about an object without fully decoding it, or `None` if the object doesn't exist. /// /// Note that despite being cheaper than [`Self::try_find_object()`], there is still some effort traversing delta-chains. @@ -64,7 +83,7 @@ impl crate::Repository { id: impl Into, ) -> Result, object::find::Error> { let id = id.into(); - if id == gix_hash::ObjectId::empty_tree(self.object_hash()) { + if id == ObjectId::empty_tree(self.object_hash()) { return Ok(Some(gix_odb::find::Header::Loose { kind: gix_object::Kind::Tree, size: 0, @@ -77,7 +96,7 @@ impl crate::Repository { #[momo] pub fn try_find_object(&self, id: impl Into) -> Result>, object::find::Error> { let id = id.into(); - if id == gix_hash::ObjectId::empty_tree(self.object_hash()) { + if id == ObjectId::empty_tree(self.object_hash()) { return Ok(Some(Object { id, kind: gix_object::Kind::Tree, @@ -236,7 +255,7 @@ impl crate::Repository { reference: FullName, message: &str, tree: ObjectId, - parents: SmallVec<[gix_hash::ObjectId; 1]>, + parents: SmallVec<[ObjectId; 1]>, ) -> Result, commit::Error> { use gix_ref::{ transaction::{Change, RefEdit}, @@ -310,13 +329,25 @@ impl crate::Repository { self.commit_as(committer, author, reference, message, tree, parents) } - /// Return an empty tree object, suitable for [getting changes](crate::Tree::changes()). + /// Return an empty tree object, suitable for [getting changes](Tree::changes()). /// - /// Note that it is special and doesn't physically exist in the object database even though it can be returned. + /// Note that the returned object is special and doesn't necessarily physically exist in the object database. /// This means that this object can be used in an uninitialized, empty repository which would report to have no objects at all. pub fn empty_tree(&self) -> Tree<'_> { - self.find_object(gix_hash::ObjectId::empty_tree(self.object_hash())) + self.find_object(ObjectId::empty_tree(self.object_hash())) .expect("always present") .into_tree() } + + /// Return an empty blob object. + /// + /// Note that the returned object is special and doesn't necessarily physically exist in the object database. + /// This means that this object can be used in an uninitialized, empty repository which would report to have no objects at all. + pub fn empty_blob(&self) -> Blob<'_> { + Blob { + id: gix_hash::ObjectId::empty_blob(self.object_hash()), + data: Vec::new(), + repo: self, + } + } } diff --git a/vendor/gix/src/repository/reference.rs b/vendor/gix/src/repository/reference.rs index 5a14c60b5..e57ca63c0 100644 --- a/vendor/gix/src/repository/reference.rs +++ b/vendor/gix/src/repository/reference.rs @@ -212,6 +212,15 @@ impl crate::Repository { Ok(self.head()?.peel_to_commit_in_place()?) } + /// Return the tree id the `HEAD` reference currently points to after peeling it fully. + /// + /// Note that this may fail for various reasons, most notably because the repository + /// is freshly initialized and doesn't have any commits yet. It could also fail if the + /// head does not point to a commit. + pub fn head_tree_id(&self) -> Result, reference::head_tree_id::Error> { + Ok(self.head()?.peel_to_commit_in_place()?.tree_id()?) + } + /// Find the reference with the given partial or full `name`, like `main`, `HEAD`, `heads/branch` or `origin/other`, /// or return an error if it wasn't found. /// -- cgit v1.2.3