|
1 | 1 | use ansi_to_tui::IntoText; |
2 | | -use git2::{DiffLineType, Oid, Repository}; |
| 2 | +use git2::{DiffLineType, DiffOptions, Oid, Repository}; |
3 | 3 | use std::{ |
4 | 4 | error, |
5 | 5 | path::{Path, PathBuf}, |
@@ -92,12 +92,12 @@ fn format_line_num_and_code(line_num: i32, line: &str) -> Vec<Span<'static>> { |
92 | 92 | ] |
93 | 93 | } |
94 | 94 |
|
95 | | -pub fn show(repo: &Repository, commit_id: Oid) -> Text<'static> { |
| 95 | +pub fn show(repo: &Repository, commit_id: Oid, path: PathBuf) -> Text<'static> { |
96 | 96 | let commit = match repo.find_commit(commit_id) { |
97 | 97 | Ok(commit) => commit, |
98 | 98 | Err(e) => return Text::raw(e.to_string()), |
99 | 99 | }; |
100 | | - let diff = match diff_for_commit(repo, &commit) { |
| 100 | + let diff = match diff_for_commit(repo, &commit, path) { |
101 | 101 | Ok(diff) => diff, |
102 | 102 | Err(e) => return Text::raw(e.to_string()), |
103 | 103 | }; |
@@ -148,9 +148,18 @@ pub fn show(repo: &Repository, commit_id: Oid) -> Text<'static> { |
148 | 148 | Text::from(lines) |
149 | 149 | } |
150 | 150 |
|
151 | | -fn diff_for_commit<'a>(repo: &'a Repository, commit: &git2::Commit<'a>) -> Result<git2::Diff<'a>, git2::Error> { |
| 151 | +fn diff_for_commit<'a>( |
| 152 | + repo: &'a Repository, |
| 153 | + commit: &git2::Commit<'a>, |
| 154 | + path: PathBuf, |
| 155 | +) -> Result<git2::Diff<'a>, git2::Error> { |
152 | 156 | let parent_tree = commit.parent(0).and_then(|parent| parent.tree()).ok(); |
153 | | - return repo.diff_tree_to_tree(parent_tree.as_ref(), Some(&commit.tree()?), None); |
| 157 | + let mut options = DiffOptions::new(); |
| 158 | + return repo.diff_tree_to_tree( |
| 159 | + parent_tree.as_ref(), |
| 160 | + Some(&commit.tree()?), |
| 161 | + Some(options.pathspec(path)), |
| 162 | + ); |
154 | 163 | } |
155 | 164 |
|
156 | 165 | fn push_lines(lines: &mut Vec<Line>, s: &str, color: Color) { |
|
0 commit comments