on master help sign in
Fix for Rust 1.26
commit8903b64830a09db249d011d35e0a5537ff4ee0ba authorsharkdp <davidpeter@web.de> dateFri 31 Aug 2018, 23:42 (8 years ago) parent194155f
1 file changed+7−6
src/diff.rs+7−6
src/diff.rs+7−6
@@ -15,13 +15,14 @@ pub type LineChanges = HashMap<u32, LineChange>;
1515
1616pub fn get_git_diff(filename: &str) -> Option<LineChanges> {
1717 let repo = Repository::discover(&filename).ok()?;
18− let path_absolute = fs::canonicalize(&filename).ok()?;
19− let path_relative_to_repo = path_absolute
20− .strip_prefix(fs::canonicalize(repo.workdir()?).ok()?)
21− .ok()?;
18+
19+ let repo_path_absolute = fs::canonicalize(repo.workdir()?).ok()?;
20+
21+ let filepath_absolute = fs::canonicalize(&filename).ok()?;
22+ let filepath_relative_to_repo = filepath_absolute.strip_prefix(&repo_path_absolute).ok()?;
2223
2324 let mut diff_options = DiffOptions::new();
24− let pathspec = path_relative_to_repo.into_c_string().ok()?;
25+ let pathspec = filepath_relative_to_repo.into_c_string().ok()?;
2526 diff_options.pathspec(pathspec);
2627 diff_options.context_lines(0);
2728
@@ -44,7 +45,7 @@ pub fn get_git_diff(filename: &str) -> Option<LineChanges> {
4445 Some(&mut |delta, hunk| {
4546 let path = delta.new_file().path().unwrap_or_else(|| Path::new(""));
4647
47− if path_relative_to_repo != path {
48+ if filepath_relative_to_repo != path {
4849 return false;
4950 }
5051