|
3 | 3 | use super::utils; |
4 | 4 | use crate::hash; |
5 | 5 | use git2::{ |
6 | | - Delta, Diff, DiffDelta, DiffFlags, DiffFormat, DiffHunk, |
7 | | - DiffOptions, Patch, Repository, |
| 6 | + Delta, Diff, DiffDelta, DiffFormat, DiffHunk, DiffOptions, Patch, |
| 7 | + Repository, |
8 | 8 | }; |
9 | | -use log::debug; |
10 | 9 | use scopetime::scope_time; |
11 | 10 | use std::{fs, path::Path}; |
12 | 11 |
|
@@ -173,13 +172,8 @@ pub fn get_diff(repo_path: &str, p: String, stage: bool) -> FileDiff { |
173 | 172 | let newfile_path = |
174 | 173 | repo_path.join(delta.new_file().path().unwrap()); |
175 | 174 |
|
176 | | - let newfile_content = |
177 | | - if delta.flags().contains(DiffFlags::NOT_BINARY) { |
178 | | - new_file_content(&newfile_path) |
179 | | - .unwrap_or(String::from("file not found")) |
180 | | - } else { |
181 | | - String::from("binary file") |
182 | | - }; |
| 175 | + let newfile_content = new_file_content(&newfile_path) |
| 176 | + .unwrap_or(String::from("file not found")); |
183 | 177 |
|
184 | 178 | let mut patch = Patch::from_buffers( |
185 | 179 | &[], |
@@ -232,12 +226,12 @@ fn new_file_content(path: &Path) -> Option<String> { |
232 | 226 | } else if meta.file_type().is_file() { |
233 | 227 | if let Ok(content) = fs::read_to_string(path) { |
234 | 228 | return Some(content); |
| 229 | + } else { |
| 230 | + return Some(String::from("no text file")); |
235 | 231 | } |
236 | 232 | } |
237 | 233 | } |
238 | 234 |
|
239 | | - debug!("could not read: {:?}", path); |
240 | | - |
241 | 235 | None |
242 | 236 | } |
243 | 237 |
|
|
0 commit comments