diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/gix-object/src/tree | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-object/src/tree')
-rw-r--r-- | vendor/gix-object/src/tree/mod.rs | 31 | ||||
-rw-r--r-- | vendor/gix-object/src/tree/write.rs | 16 |
2 files changed, 26 insertions, 21 deletions
diff --git a/vendor/gix-object/src/tree/mod.rs b/vendor/gix-object/src/tree/mod.rs index be723e1b8..147213d70 100644 --- a/vendor/gix-object/src/tree/mod.rs +++ b/vendor/gix-object/src/tree/mod.rs @@ -11,7 +11,7 @@ pub mod write; /// The mode of items storable in a tree, similar to the file mode on a unix file system. /// -/// Used in [mutable::Entry][crate::tree::Entry] and [EntryRef]. +/// Used in [`mutable::Entry`][crate::tree::Entry] and [`EntryRef`]. #[derive(Clone, Copy, PartialEq, Eq, Debug, Ord, PartialOrd, Hash)] #[repr(u16)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -72,7 +72,7 @@ pub struct EntryRef<'a> { pub filename: &'a BStr, /// The id of the object representing the entry. // TODO: figure out how these should be called. id or oid? It's inconsistent around the codebase. - // Answer: make it 'id', as in `git2` + // Answer: make it 'id', as in `git2` #[cfg_attr(feature = "serde", serde(borrow))] pub oid: &'a gix_hash::oid, } @@ -84,11 +84,14 @@ impl<'a> PartialOrd for EntryRef<'a> { } impl<'a> Ord for EntryRef<'a> { - /// Entries compare by the common portion of the filename. This is critical for proper functioning of algorithms working on trees. - /// Doing it like this is needed for compatibility with older, potentially broken(?) trees. - fn cmp(&self, other: &Self) -> Ordering { - let len = self.filename.len().min(other.filename.len()); - self.filename[..len].cmp(&other.filename[..len]) + fn cmp(&self, b: &Self) -> Ordering { + let a = self; + let common = a.filename.len().min(b.filename.len()); + a.filename[..common].cmp(&b.filename[..common]).then_with(|| { + let a = a.filename.get(common).or_else(|| a.mode.is_tree().then_some(&b'/')); + let b = b.filename.get(common).or_else(|| b.mode.is_tree().then_some(&b'/')); + a.cmp(&b) + }) } } @@ -111,12 +114,14 @@ impl PartialOrd for Entry { } impl Ord for Entry { - /// Entries compare by the common portion of the filename. This is critical for proper functioning of algorithms working on trees. - fn cmp(&self, other: &Self) -> Ordering { - let common_len = self.filename.len().min(other.filename.len()); - self.filename[..common_len] - .cmp(&other.filename[..common_len]) - .then_with(|| self.filename.len().cmp(&other.filename.len())) + fn cmp(&self, b: &Self) -> Ordering { + let a = self; + let common = a.filename.len().min(b.filename.len()); + a.filename[..common].cmp(&b.filename[..common]).then_with(|| { + let a = a.filename.get(common).or_else(|| a.mode.is_tree().then_some(&b'/')); + let b = b.filename.get(common).or_else(|| b.mode.is_tree().then_some(&b'/')); + a.cmp(&b) + }) } } diff --git a/vendor/gix-object/src/tree/write.rs b/vendor/gix-object/src/tree/write.rs index 1e8edc024..f826e6749 100644 --- a/vendor/gix-object/src/tree/write.rs +++ b/vendor/gix-object/src/tree/write.rs @@ -53,16 +53,16 @@ impl crate::WriteTo for Tree { Ok(()) } + fn kind(&self) -> Kind { + Kind::Tree + } + fn size(&self) -> usize { self.entries .iter() .map(|Entry { mode, filename, oid }| mode.as_bytes().len() + 1 + filename.len() + 1 + oid.as_bytes().len()) .sum() } - - fn kind(&self) -> Kind { - Kind::Tree - } } /// Serialization @@ -96,6 +96,10 @@ impl<'a> crate::WriteTo for TreeRef<'a> { Ok(()) } + fn kind(&self) -> Kind { + Kind::Tree + } + fn size(&self) -> usize { self.entries .iter() @@ -104,8 +108,4 @@ impl<'a> crate::WriteTo for TreeRef<'a> { }) .sum() } - - fn kind(&self) -> Kind { - Kind::Tree - } } |