Skip to content

Commit 67a599e

Browse files
tree: Add a test showing failure to roundtrip
We can see it even in the existing test fixtures: As the types are currently defined, some trees have more than one valid git representation, meaning that with these types, we cannot roundtrip from git representation to gix-object types and back to git representation. The issue comes from storing the `EntryMode` as an integer. In git, the source of truth is the string that represents the mode in octal form, represented as up to 6 characters. For an `EntryMode` representing a Tree, there are two valid ways to represent them in `git`: `"40000"` and `"040000"`. We see both representations in the wild. Because `"40000"` and `"040000"` become identical once parsed as `u16`, there is no possible way to ensure roundtrip without enriching the data representation with at least one more bit of information to indicate whether the mode had leading zeroes. This is not an issue for `Blob`, `BlobExecutable`, `Link` or `Commit` because each of them starts with a 1 when expressed as 6 digits.
1 parent 6d5f774 commit 67a599e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

gix-object/tests/object/tree/from_bytes.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ fn special_trees() -> crate::Result {
101101
expected_entry_count,
102102
"{name}"
103103
);
104+
// Show we can roundtrip
105+
let mut buf: Vec<u8> = Default::default();
106+
actual.write_to(&mut buf).expect("Failed to write bytes to buffer");
107+
assert_eq!(buf, fixture);
104108
}
105109
Ok(())
106110
}

0 commit comments

Comments
 (0)