History

More explicit expectations towards entries in mutable Trees

They must remain sorted or else the world will stop spinning.

Sebastian Thiel committed 5 years ago

Commit d94f84c1 parent f19ea333 files · +14 −1Browse files

Showing the changes to git-object/src/mutable (1 of 3 files). Show all

Unified · Split

git-object/src/mutable/tree.rs+10−1
@@ -24,7 +24,7 @@ impl From<Error> for io::Error { · 23 unmodified lines
2424 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
2525 #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
2626 pub struct Tree {
27− /// The directories and files contained in this tree.
27+ /// The directories and files contained in this tree. They must be and remain sorted by [`filename`][Entry::filename].
2828 pub entries: Vec<Entry>,
2929 }
3030
@@ -59,6 +59,15 @@ impl Mode { · 28 unmodified lines
5959 impl Tree {
6060 /// Serialize this tree to `out` in the git internal format.
6161 pub fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {
62+ debug_assert_eq!(
63+ &{
64+ let mut entries_sorted = self.entries.clone();
65+ entries_sorted.sort_by(|lhs, rhs| lhs.filename.cmp(&rhs.filename));
66+ entries_sorted
67+ },
68+ &self.entries,
69+ "entries for serialization must be sorted by filename"
70+ );
6271 for Entry { mode, filename, oid } in &self.entries {
6372 out.write_all(mode.as_bytes())?;
6473 out.write_all(SPACE)?;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t