diff: Handle missing and abbreviated blobs
09732af90d0f2f82ce59de5a3445a5322a9c85cb
Treat missing blob metadata as optional when rendering a Git diff so unstaged worktree object ids do not abort the pager. Accept abbreviated all-hex index object ids from piped diff input as unavailable blob metadata while still rejecting malformed ids. Assisted-by: Codex:gpt-5.5
1 parent
0e4a04d9
crates/diff/src/bin/rustik-diff.rs
+1 -1
| 109 | 109 | options.file_tree_root = root; |
|
| 110 | 110 | } |
|
| 111 | 111 | let mut viewer = DiffViewer::new(document, options); |
|
| 112 | 112 | match &repo { |
|
| 113 | 113 | RenderRepo::Git(repository) => { |
|
| 114 | - | viewer.load_file_locs(|oid| repository.cat_blob(oid))?; |
|
| 114 | + | let _ = viewer.load_file_locs(|oid| repository.cat_blob(oid)); |
|
| 115 | 115 | } |
|
| 116 | 116 | RenderRepo::Stdin => { |
|
| 117 | 117 | if let Ok(repository) = git::Repository::discover(cwd.to_path_buf()) { |
|
| 118 | 118 | let _ = viewer.load_file_locs(|oid| repository.cat_blob(oid)); |
|
| 119 | 119 | } |
crates/diff/src/decode.rs
+3 -0
| 17 | 17 | use crate::document::{ |
|
| 18 | 18 | DecodeError, DiffDocument, DiffLine, DiffLineKind, FileDiff, FileHeader, FileId, FileKind, |
|
| 19 | 19 | FileMode, Hunk, HunkHeader, HunkId, Oid, RowId, |
|
| 20 | 20 | }; |
|
| 21 | 21 | ||
| 22 | + | /// Maximum number of hexadecimal characters in a Git object id. |
|
| 23 | + | const FULL_OBJECT_ID_HEX_LEN: usize = 64; |
|
| 24 | + | ||
| 22 | 25 | /// Decodes a value from unified diff text. |
|
| 23 | 26 | /// |
|
| 24 | 27 | /// The default `decode_str`/`decode_bytes` adapters route through `decode` |
|
| 25 | 28 | /// so a single [`BufRead`]-based implementation covers all input shapes. |
|
| 26 | 29 | pub trait Decode: Sized { |
{
+0 -0
+0 -0
=> break,
+0 -0
a.rs
+0 -0
new.rs
+0 -0
old.rs
+0 -0
to.rs
+0 -0
copy2.rs
+0 -0
mode.sh
+0 -0
image.png
+0 -0
a
+0 -0
a
+0 -0
a
+0 -0
a
+0 -0
a.rs
+0 -0
b.rs
+0 -0
a.rs\x1b[m
+0 -0