Skip to content

Commit da5bd29

Browse files
committed
Handle binary files
1 parent 62744a0 commit da5bd29

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

asyncgit/src/sync/diff.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,35 @@ impl ConsumeHunk for FileDiff {
319319
}
320320
}
321321

322+
fn file_diff_for_binary_files(
323+
old_data: gix::diff::blob::platform::resource::Data,
324+
new_data: gix::diff::blob::platform::resource::Data,
325+
) -> FileDiff {
326+
use gix::diff::blob::platform::resource::Data;
327+
328+
let mut file_diff = FileDiff::default();
329+
330+
let old_size = match old_data {
331+
Data::Missing => 0,
332+
Data::Buffer { buf, .. } => u64::conv(buf.len()),
333+
Data::Binary { size } => size,
334+
};
335+
let new_size = match new_data {
336+
Data::Missing => 0,
337+
Data::Buffer { buf, .. } => u64::conv(buf.len()),
338+
Data::Binary { size } => size,
339+
};
340+
341+
let sizes = (old_size, new_size);
342+
let size_delta =
343+
(i64::conv(new_size)).saturating_sub(i64::conv(old_size));
344+
345+
file_diff.sizes = sizes;
346+
file_diff.size_delta = size_delta;
347+
348+
file_diff
349+
}
350+
322351
/// returns diff of a specific file either in `stage` or workdir
323352
pub fn get_diff(
324353
repo_path: &RepoPath,
@@ -342,9 +371,6 @@ pub fn get_diff(
342371
gix_repo
343372
.head_tree()?
344373
.lookup_entry_by_path(p)
345-
.expect("TODO")
346-
.expect("TODO")
347-
.object_id(),
348374
None,
349375
)
350376
} else {
@@ -406,7 +432,10 @@ pub fn get_diff(
406432
unreachable!("We disabled that")
407433
}
408434
Operation::SourceOrDestinationIsBinary => {
409-
todo!();
435+
return Ok(file_diff_for_binary_files(
436+
outcome.old.data,
437+
outcome.new.data,
438+
));
410439
}
411440
}
412441
};

0 commit comments

Comments
 (0)