diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
commit | 10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch) | |
tree | bdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/gix-ref/src/store/general | |
parent | Releasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff) | |
download | rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip |
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-ref/src/store/general')
-rw-r--r-- | vendor/gix-ref/src/store/general/handle/find.rs | 82 | ||||
-rw-r--r-- | vendor/gix-ref/src/store/general/handle/mod.rs | 43 | ||||
-rw-r--r-- | vendor/gix-ref/src/store/general/init.rs | 38 | ||||
-rw-r--r-- | vendor/gix-ref/src/store/general/mod.rs | 1 |
4 files changed, 164 insertions, 0 deletions
diff --git a/vendor/gix-ref/src/store/general/handle/find.rs b/vendor/gix-ref/src/store/general/handle/find.rs new file mode 100644 index 000000000..9792b9b7d --- /dev/null +++ b/vendor/gix-ref/src/store/general/handle/find.rs @@ -0,0 +1,82 @@ +use std::convert::TryInto; + +use crate::{store, PartialNameRef, Reference}; + +mod error { + use std::convert::Infallible; + + /// The error returned by [crate::file::Store::find_loose()]. + #[derive(Debug, thiserror::Error)] + #[allow(missing_docs)] + pub enum Error { + #[error("An error occurred while finding a reference in the loose file database")] + Loose(#[from] crate::file::find::Error), + #[error("The ref name or path is not a valid ref name")] + RefnameValidation(#[from] crate::name::Error), + } + + impl From<Infallible> for Error { + fn from(_: Infallible) -> Self { + unreachable!("this impl is needed to allow passing a known valid partial path as parameter") + } + } +} + +pub use error::Error; + +use crate::store::handle; + +impl store::Handle { + /// TODO: actually implement this with handling of the packed buffer. + pub fn try_find<'a, Name, E>(&self, partial: Name) -> Result<Option<Reference>, Error> + where + Name: TryInto<&'a PartialNameRef, Error = E>, + Error: From<E>, + { + let _name = partial.try_into()?; + match &self.state { + handle::State::Loose { store: _, .. } => { + todo!() + } + } + } +} + +mod existing { + mod error { + use std::path::PathBuf; + + /// The error returned by [file::Store::find_existing()][crate::file::Store::find_existing()]. + #[derive(Debug, thiserror::Error)] + #[allow(missing_docs)] + pub enum Error { + #[error("An error occurred while finding a reference in the database")] + Find(#[from] crate::store::find::Error), + #[error("The ref partially named {name:?} could not be found")] + NotFound { name: PathBuf }, + } + } + + use std::convert::TryInto; + + pub use error::Error; + + use crate::{store, PartialNameRef, Reference}; + + impl store::Handle { + /// Similar to [`crate::file::Store::find()`] but a non-existing ref is treated as error. + pub fn find<'a, Name, E>(&self, _partial: Name) -> Result<Reference, Error> + where + Name: TryInto<&'a PartialNameRef, Error = E>, + crate::name::Error: From<E>, + { + todo!() + // match self.try_find(partial) {} + // match self.find_one_with_verified_input(path.to_partial_path().as_ref(), packed) { + // Ok(Some(r)) => Ok(r), + // Ok(None) => Err(Error::NotFound(path.to_partial_path().into_owned())), + // Err(err) => Err(err.into()), + // } + } + } +} diff --git a/vendor/gix-ref/src/store/general/handle/mod.rs b/vendor/gix-ref/src/store/general/handle/mod.rs new file mode 100644 index 000000000..44d9e060d --- /dev/null +++ b/vendor/gix-ref/src/store/general/handle/mod.rs @@ -0,0 +1,43 @@ +#![allow(dead_code)] +use crate::{store, Namespace}; + +#[derive(Clone)] +pub(crate) enum State { + Loose { store: crate::file::Store }, +} + +impl crate::Store { + /// Return a new handle which sees all references if `namespace` is `None` or all read and write operations are limited + /// to the given `namespace` if `Some`. + pub fn to_handle(&self) -> store::Handle { + Self::new_handle_inner(&self.inner, None) + } + + /// As above, but supports a namespace to be set + pub fn to_handle_namespaced(&self, namespace: Option<Namespace>) -> store::Handle { + Self::new_handle_inner(&self.inner, namespace) + } + + fn new_handle_inner(state: &store::State, namespace: Option<Namespace>) -> store::Handle { + store::Handle { + state: match state { + store::State::Loose { store } => store::handle::State::Loose { + store: { + let mut store = store.clone(); + store.namespace = namespace; + store + }, + }, + }, + } + } +} + +/// +pub mod find; + +mod iter { + // impl store::Handle { + // pub fn iter<'p, 's>(&'s self, packed: Option<&'p packed::Buffer>) -> std::io::Result<LooseThenPacked<'p, 's>> { + // } +} diff --git a/vendor/gix-ref/src/store/general/init.rs b/vendor/gix-ref/src/store/general/init.rs new file mode 100644 index 000000000..a9112c0a6 --- /dev/null +++ b/vendor/gix-ref/src/store/general/init.rs @@ -0,0 +1,38 @@ +use std::path::PathBuf; + +use crate::store::WriteReflog; + +mod error { + /// The error returned by [crate::Store::at()]. + #[derive(Debug, thiserror::Error)] + #[allow(missing_docs)] + pub enum Error { + #[error("There was an error accessing the store's directory")] + Io(#[from] std::io::Error), + } +} + +pub use error::Error; + +use crate::file; + +#[allow(dead_code)] +impl crate::Store { + /// Create a new store at the given location, typically the `.git/` directory. + /// + /// `object_hash` defines the kind of hash to assume when dealing with refs. + pub fn at( + git_dir: impl Into<PathBuf>, + reflog_mode: WriteReflog, + object_hash: gix_hash::Kind, + ) -> Result<Self, Error> { + // for now, just try to read the directory - later we will do that naturally as we have to figure out if it's a ref-table or not. + let git_dir = git_dir.into(); + std::fs::read_dir(&git_dir)?; + Ok(crate::Store { + inner: crate::store::State::Loose { + store: file::Store::at(git_dir, reflog_mode, object_hash), + }, + }) + } +} diff --git a/vendor/gix-ref/src/store/general/mod.rs b/vendor/gix-ref/src/store/general/mod.rs new file mode 100644 index 000000000..6adc4f6e6 --- /dev/null +++ b/vendor/gix-ref/src/store/general/mod.rs @@ -0,0 +1 @@ +mod init; |