summaryrefslogtreecommitdiffstats
path: root/vendor/gix-odb/src/store_impls/dynamic/write.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gix-odb/src/store_impls/dynamic/write.rs')
-rw-r--r--vendor/gix-odb/src/store_impls/dynamic/write.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/vendor/gix-odb/src/store_impls/dynamic/write.rs b/vendor/gix-odb/src/store_impls/dynamic/write.rs
new file mode 100644
index 000000000..a2e40eec4
--- /dev/null
+++ b/vendor/gix-odb/src/store_impls/dynamic/write.rs
@@ -0,0 +1,47 @@
+use std::{io::Read, ops::Deref};
+
+use gix_hash::ObjectId;
+use gix_object::Kind;
+
+use crate::store;
+
+mod error {
+ use crate::{loose, store};
+
+ /// The error returned by the [dynamic Store's][crate::Store] [`Write`][crate::Write] implementation.
+ #[derive(Debug, thiserror::Error)]
+ #[allow(missing_docs)]
+ pub enum Error {
+ #[error(transparent)]
+ LoadIndex(#[from] store::load_index::Error),
+ #[error(transparent)]
+ LooseWrite(#[from] loose::write::Error),
+ #[error(transparent)]
+ Io(#[from] std::io::Error),
+ }
+}
+pub use error::Error;
+
+use crate::store_impls::dynamic;
+
+impl<S> crate::Write for store::Handle<S>
+where
+ S: Deref<Target = dynamic::Store> + Clone,
+{
+ type Error = Error;
+
+ fn write_stream(&self, kind: Kind, size: u64, from: impl Read) -> Result<ObjectId, Self::Error> {
+ let mut snapshot = self.snapshot.borrow_mut();
+ Ok(match snapshot.loose_dbs.first() {
+ Some(ldb) => ldb.write_stream(kind, size, from)?,
+ None => {
+ let new_snapshot = self
+ .store
+ .load_one_index(self.refresh, snapshot.marker)?
+ .expect("there is always at least one ODB, and this code runs only once for initialization");
+ *snapshot = new_snapshot;
+ snapshot.loose_dbs[0].write_stream(kind, size, from)?
+ }
+ })
+ }
+}