summaryrefslogtreecommitdiffstats
path: root/vendor/gix-odb/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/gix-odb/src
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-odb/src')
-rw-r--r--vendor/gix-odb/src/lib.rs3
-rw-r--r--vendor/gix-odb/src/sink.rs36
-rw-r--r--vendor/gix-odb/src/store_impls/dynamic/iter.rs9
-rw-r--r--vendor/gix-odb/src/store_impls/dynamic/mod.rs13
-rw-r--r--vendor/gix-odb/src/store_impls/dynamic/types.rs2
-rw-r--r--vendor/gix-odb/src/store_impls/dynamic/verify.rs8
-rw-r--r--vendor/gix-odb/src/store_impls/loose/verify.rs2
-rw-r--r--vendor/gix-odb/src/store_impls/loose/write.rs41
8 files changed, 69 insertions, 45 deletions
diff --git a/vendor/gix-odb/src/lib.rs b/vendor/gix-odb/src/lib.rs
index a63ea544f..08b14238c 100644
--- a/vendor/gix-odb/src/lib.rs
+++ b/vendor/gix-odb/src/lib.rs
@@ -65,8 +65,7 @@ pub fn sink(object_hash: gix_hash::Kind) -> Sink {
}
}
-///
-pub mod sink;
+mod sink;
///
pub mod find;
diff --git a/vendor/gix-odb/src/sink.rs b/vendor/gix-odb/src/sink.rs
index 1befd6fdf..44a406151 100644
--- a/vendor/gix-odb/src/sink.rs
+++ b/vendor/gix-odb/src/sink.rs
@@ -30,7 +30,6 @@ impl crate::traits::Write for Sink {
mut from: impl io::Read,
) -> Result<gix_hash::ObjectId, Self::Error> {
let mut size = size.try_into().expect("object size to fit into usize");
- use gix_features::hash::Sha1;
let mut buf = [0u8; 8096];
let header = gix_object::encode::loose_header(kind, size);
@@ -40,27 +39,24 @@ impl crate::traits::Write for Sink {
}
Ok(())
};
- match self.object_hash {
- gix_hash::Kind::Sha1 => {
- let mut hasher = Sha1::default();
- hasher.update(&header);
- possibly_compress(&header)?;
- while size != 0 {
- let bytes = size.min(buf.len());
- from.read_exact(&mut buf[..bytes])?;
- hasher.update(&buf[..bytes]);
- possibly_compress(&buf[..bytes])?;
- size -= bytes;
- }
- if let Some(compressor) = self.compressor.as_ref() {
- let mut c = compressor.borrow_mut();
- c.flush()?;
- c.reset();
- }
+ let mut hasher = gix_features::hash::hasher(self.object_hash);
+ hasher.update(&header);
+ possibly_compress(&header)?;
- Ok(hasher.digest().into())
- }
+ while size != 0 {
+ let bytes = size.min(buf.len());
+ from.read_exact(&mut buf[..bytes])?;
+ hasher.update(&buf[..bytes]);
+ possibly_compress(&buf[..bytes])?;
+ size -= bytes;
+ }
+ if let Some(compressor) = self.compressor.as_ref() {
+ let mut c = compressor.borrow_mut();
+ c.flush()?;
+ c.reset();
}
+
+ Ok(hasher.digest().into())
}
}
diff --git a/vendor/gix-odb/src/store_impls/dynamic/iter.rs b/vendor/gix-odb/src/store_impls/dynamic/iter.rs
index bbe859e7c..2152dff71 100644
--- a/vendor/gix-odb/src/store_impls/dynamic/iter.rs
+++ b/vendor/gix-odb/src/store_impls/dynamic/iter.rs
@@ -30,7 +30,7 @@ enum State {
}
/// Define the order in which objects are returned.
-#[derive(Debug, Copy, Clone)]
+#[derive(Default, Debug, Copy, Clone)]
pub enum Ordering {
/// Traverse packs first as sorted by their index files in lexicographical order (sorted by object id), then traverse loose objects
/// as sorted by their names as well.
@@ -38,6 +38,7 @@ pub enum Ordering {
/// This mode uses no memory as it's the natural ordering of objects, and is best to obtain all object ids as quickly as possible,
/// while noting that these may contain duplicates. However, it's very costly to obtain object information or decode them with this
/// scheme as cache-hits are unlikely with it and memory maps are less efficient when loading them in random order.
+ #[default]
PackLexicographicalThenLooseLexicographical,
/// Traverse packs first yielding object ids sorted by their position in the pack, with those at the beginning of the pack file coming first.
/// Then follow loose objects sorted by their names.
@@ -48,12 +49,6 @@ pub enum Ordering {
PackAscendingOffsetThenLooseLexicographical,
}
-impl Default for Ordering {
- fn default() -> Self {
- Ordering::PackLexicographicalThenLooseLexicographical
- }
-}
-
/// An iterator over all, _possibly duplicate_, objects of an object store, which by default uses no extra memory but yields an
/// order that is costly to traverse when querying object information or decoding them.
///
diff --git a/vendor/gix-odb/src/store_impls/dynamic/mod.rs b/vendor/gix-odb/src/store_impls/dynamic/mod.rs
index 5cf2a26ee..774bb61dc 100644
--- a/vendor/gix-odb/src/store_impls/dynamic/mod.rs
+++ b/vendor/gix-odb/src/store_impls/dynamic/mod.rs
@@ -28,23 +28,18 @@ where
}
/// Decide what happens when all indices are loaded.
-#[derive(Clone, Copy)]
+#[derive(Default, Clone, Copy)]
pub enum RefreshMode {
/// Check for new or changed pack indices (and pack data files) when the last known index is loaded.
/// During runtime we will keep pack indices stable by never reusing them, however, there is the option for
/// clearing internal caches which is likely to change pack ids and it will trigger unloading of packs as they are missing on disk.
+ #[default]
AfterAllIndicesLoaded,
/// Use this if you expect a lot of missing objects that shouldn't trigger refreshes even after all packs are loaded.
/// This comes at the risk of not learning that the packs have changed in the mean time.
Never,
}
-impl Default for RefreshMode {
- fn default() -> Self {
- RefreshMode::AfterAllIndicesLoaded
- }
-}
-
impl RefreshMode {
/// Set this refresh mode to never refresh.
pub fn never(&mut self) {
@@ -94,7 +89,7 @@ pub mod structure {
/// A record of a structural element of an object database.
#[derive(Debug, Clone, PartialEq, Eq)]
- #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+ #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Record {
/// A loose object database.
LooseObjectDatabase {
@@ -123,7 +118,7 @@ pub mod structure {
}
#[derive(Debug, Clone, PartialEq, Eq)]
- #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+ #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Possible stats of pack indices.
pub enum IndexState {
/// The index is active in memory because a mapping exists.
diff --git a/vendor/gix-odb/src/store_impls/dynamic/types.rs b/vendor/gix-odb/src/store_impls/dynamic/types.rs
index 2bda0d7d3..df2365433 100644
--- a/vendor/gix-odb/src/store_impls/dynamic/types.rs
+++ b/vendor/gix-odb/src/store_impls/dynamic/types.rs
@@ -394,7 +394,7 @@ pub(crate) struct MutableIndexAndPack {
/// A snapshot about resource usage.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
-#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Metrics {
/// The total amount of handles which can be used to access object information.
pub num_handles: usize,
diff --git a/vendor/gix-odb/src/store_impls/dynamic/verify.rs b/vendor/gix-odb/src/store_impls/dynamic/verify.rs
index 9a35cb5d7..d6291e834 100644
--- a/vendor/gix-odb/src/store_impls/dynamic/verify.rs
+++ b/vendor/gix-odb/src/store_impls/dynamic/verify.rs
@@ -44,7 +44,7 @@ pub mod integrity {
}
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
- #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+ #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Integrity information about loose object databases
pub struct LooseObjectStatistics {
/// The path to the root directory of the loose objects database
@@ -54,7 +54,7 @@ pub mod integrity {
}
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
- #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+ #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
/// Traversal statistics of packs governed by single indices or multi-pack indices.
#[allow(missing_docs)]
pub enum SingleOrMultiStatistics {
@@ -64,7 +64,7 @@ pub mod integrity {
/// Statistics gathered when traversing packs of various kinds of indices.
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
- #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+ #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IndexStatistics {
/// The path to the index or multi-pack index for which statics were gathered.
pub path: PathBuf,
@@ -109,7 +109,7 @@ pub mod integrity {
impl super::Store {
/// Check the integrity of all objects as per the given `options`.
///
- /// Note that this will not not force loading all indices or packs permanently, as we will only use the momentarily loaded disk state.
+ /// Note that this will not force loading all indices or packs permanently, as we will only use the momentarily loaded disk state.
/// This does, however, include all alternates.
pub fn verify_integrity<C, P, F>(
&self,
diff --git a/vendor/gix-odb/src/store_impls/loose/verify.rs b/vendor/gix-odb/src/store_impls/loose/verify.rs
index 648e5764c..8ffbb7105 100644
--- a/vendor/gix-odb/src/store_impls/loose/verify.rs
+++ b/vendor/gix-odb/src/store_impls/loose/verify.rs
@@ -33,7 +33,7 @@ pub mod integrity {
/// The outcome returned by [`verify_integrity()`][super::Store::verify_integrity()].
#[derive(Debug, PartialEq, Eq, Hash, Ord, PartialOrd, Clone)]
- #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
+ #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Statistics {
/// The amount of loose objects we checked.
pub num_objects: usize,
diff --git a/vendor/gix-odb/src/store_impls/loose/write.rs b/vendor/gix-odb/src/store_impls/loose/write.rs
index e87462e4c..912426bba 100644
--- a/vendor/gix-odb/src/store_impls/loose/write.rs
+++ b/vendor/gix-odb/src/store_impls/loose/write.rs
@@ -98,6 +98,16 @@ impl crate::traits::Write for Store {
type CompressedTempfile = deflate::Write<NamedTempFile>;
+/// Access
+impl Store {
+ /// Return the path to the object with `id`.
+ ///
+ /// Note that is may not exist yet.
+ pub fn object_path(&self, id: &gix_hash::oid) -> PathBuf {
+ loose::hash_path(id, self.path.clone())
+ }
+}
+
impl Store {
fn dest(&self) -> Result<hash::Write<CompressedTempfile>, Error> {
Ok(hash::Write::new(
@@ -126,7 +136,36 @@ impl Store {
}
}
let file = file.into_inner();
- file.persist(&object_path).map_err(|err| Error::Persist {
+ let res = file.persist(&object_path);
+ // On windows, we assume that such errors are due to its special filesystem semantics,
+ // on any other platform that would be a legitimate error though.
+ #[cfg(windows)]
+ if let Err(err) = &res {
+ if err.error.kind() == std::io::ErrorKind::PermissionDenied
+ || err.error.kind() == std::io::ErrorKind::AlreadyExists
+ {
+ return Ok(id);
+ }
+ }
+ #[cfg(unix)]
+ if let Ok(mut perm) = object_path.metadata().map(|m| m.permissions()) {
+ use std::os::unix::fs::PermissionsExt;
+ /// For now we assume the default with standard umask. This can be more sophisticated,
+ /// but we have the bare minimum.
+ fn comp_mode(_mode: u32) -> u32 {
+ 0o444
+ }
+ let new_mode = comp_mode(perm.mode());
+ if (perm.mode() ^ new_mode) & !0o170000 != 0 {
+ perm.set_mode(new_mode);
+ std::fs::set_permissions(&object_path, perm).map_err(|err| Error::Io {
+ source: err,
+ message: "Failed to set permission bits",
+ path: object_path.clone(),
+ })?;
+ }
+ }
+ res.map_err(|err| Error::Persist {
source: err,
target: object_path,
})?;