Fix for Rust 1.26

This commit is contained in:
sharkdp 2018-08-31 23:42:08 +02:00 committed by David Peter
parent 194155f062
commit 8903b64830
1 changed files with 7 additions and 6 deletions

View File

@ -15,13 +15,14 @@ pub type LineChanges = HashMap<u32, LineChange>;
pub fn get_git_diff(filename: &str) -> Option<LineChanges> {
let repo = Repository::discover(&filename).ok()?;
let path_absolute = fs::canonicalize(&filename).ok()?;
let path_relative_to_repo = path_absolute
.strip_prefix(fs::canonicalize(repo.workdir()?).ok()?)
.ok()?;
let repo_path_absolute = fs::canonicalize(repo.workdir()?).ok()?;
let filepath_absolute = fs::canonicalize(&filename).ok()?;
let filepath_relative_to_repo = filepath_absolute.strip_prefix(&repo_path_absolute).ok()?;
let mut diff_options = DiffOptions::new();
let pathspec = path_relative_to_repo.into_c_string().ok()?;
let pathspec = filepath_relative_to_repo.into_c_string().ok()?;
diff_options.pathspec(pathspec);
diff_options.context_lines(0);
@ -44,7 +45,7 @@ pub fn get_git_diff(filename: &str) -> Option<LineChanges> {
Some(&mut |delta, hunk| {
let path = delta.new_file().path().unwrap_or_else(|| Path::new(""));
if path_relative_to_repo != path {
if filepath_relative_to_repo != path {
return false;
}