chore: refactor hunks_by_filepath function to simplify code and improve readability

This commit is contained in:
Nikita Galaiko 2023-09-29 11:02:34 +02:00 committed by GitButler
parent 1cccaa6d69
commit 644a4ae3f3

View File

@ -1,4 +1,4 @@
use std::{collections::HashMap, path};
use std::{collections::HashMap, path, str};
use anyhow::{Context, Result};
use serde::Serialize;
@ -135,12 +135,11 @@ fn hunks_by_filepath(
}
match line.origin() {
'+' | '-' | ' ' => current_diff.push_str(&format!("{}", line.origin())),
_ => {}
}
// is this a binary patch or a hunk?
match line.origin() {
'+' | '-' | ' ' => {
current_diff.push_str(&format!("{}", line.origin()));
current_diff.push_str(str::from_utf8(line.content()).unwrap());
current_binary = false;
}
'B' => {
let full_path = repository.workdir().unwrap().join(file_path);
// save the file_path to the odb
@ -153,7 +152,6 @@ fn hunks_by_filepath(
}
_ => {
current_diff.push_str(std::str::from_utf8(line.content()).unwrap());
current_binary = false;
}
}