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
24#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]24#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
25#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]25#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
26pub struct Tree {26pub 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].
28 pub entries: Vec<Entry>,28 pub entries: Vec<Entry>,
29}29}
30 30
@@ -59,6 +59,15 @@ impl Mode { · 28 unmodified lines
59impl Tree {59impl Tree {
60 /// Serialize this tree to `out` in the git internal format.60 /// Serialize this tree to `out` in the git internal format.
61 pub fn write_to(&self, mut out: impl io::Write) -> io::Result<()> {61 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 );
62 for Entry { mode, filename, oid } in &self.entries {71 for Entry { mode, filename, oid } in &self.entries {
63 out.write_all(mode.as_bytes())?;72 out.write_all(mode.as_bytes())?;
64 out.write_all(SPACE)?;73 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