diff: Skip null source blob IDs

173b9efb9f45ac580d6f52557ea753d265842015
Added and deleted files use a null object ID for their missing side, which Git
cannot read as a blob.

Assisted-by: Codex:gpt-5.6-sol
Alexis Sellier committed ago 1 parent 8de202df
crates/diff/src/viewer.rs +1 -0
748 748
                continue;
749 749
            }
750 750
            for oid in [file.header.old_oid, file.header.new_oid]
751 751
                .into_iter()
752 752
                .flatten()
753 +
                .filter(|oid| !oid.is_zero())
753 754
            {
754 755
                if let Entry::Vacant(entry) = blobs.entry(oid) {
755 756
                    let blob = LoadedBlob::read(read_blob(oid)?);
756 757
                    entry.insert(blob.loc);
757 758
                    if let Some(source) = blob.source.filter(|source| {
a.rs +0 -0
image.png +0 -0
a.rs +0 -0
b.rs +0 -0
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
b.rs +0 -0
crates/diff/tests/golden/sticky_header_before_next_file_64x5.txt +0 -0
src/a.rs +0 -0
src/b.rs +0 -0
README.md +0 -0
src/app/a.rs +0 -0
src/lib/b.rs +0 -0
README.md +0 -0
a.rs +0 -0
b.rs +0 -0
assets/css/style.css +0 -0
assets/css/style.css +0 -0
first.rs +0 -0
second.rs +0 -0
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
a.rs +0 -0
b.rs +0 -0
a.rs\n", +0 -0
new.rs\n", +0 -0
a\n\ +0 -0
crates/repo/src/oid.rs +8 -0
25 25
impl Oid {
26 26
    /// Returns the abbreviated object id used in compact displays.
27 27
    pub fn short(&self) -> String {
28 28
        self.to_string()[..SHORT_LEN].to_owned()
29 29
    }
30 +
31 +
    /// Returns whether every byte in the object identifier is zero.
32 +
    pub fn is_zero(&self) -> bool {
33 +
        match self {
34 +
            Self::Sha1(bytes) => bytes.iter().all(|byte| *byte == 0),
35 +
            Self::Sha256(bytes) => bytes.iter().all(|byte| *byte == 0),
36 +
        }
37 +
    }
30 38
}
31 39
32 40
impl FromStr for Oid {
33 41
    type Err = OidError;
34 42